- 博客(44)
- 收藏
- 关注
原创 30.输入三个字符串,按由小到大的顺序输出(指针)
#include"stdio.h"#include"string.h"void swap(char *p1,char *p2){char p[20];strcpy(p.p1);strcpy(p1,p2);strcpy(p2,p);}int main(){char str1[20],str2[20],str3[20];printf(“input three line:\n”);gets(str1);gets(str2);gets(str3);if(strcmp(str1,str2)&
2021-07-28 19:05:41
351
原创 29.输入三个整数,按由小到大的顺序输出。(指针)
#include"stdio.h"int main(){void swap(int *p1,int *p2);int n1,n2,n3;int *p1,*p2,*p3;printf(“input three integer n1,n2,n3:”);scanf("%d%d%d",&n1,&n2,&n3);p1=&n1;p2=&n2;p3=&n3;if(n1>n2)swap(p1,p2);if(n1>n3)swap(p1.p3);
2021-07-28 19:04:52
451
原创 28.编写程序,求出n1至n2自然数之和。要求使用递归方法。
#include"stdio.h"{int sum=0;int f(int n1,int n2)if(n1>n2) return sum;sum+=n1;n1++;f(n1,n2);}main(){int n1,n2;scanf("%d%d",&n1,&n2);printf("%d", f(n1,n2));}
2021-07-28 19:03:37
474
原创 27.两个乒乓球队进行比赛,各出三人。甲队为A、B·C三人,乙队为X、Y、Z三.已抽签决定比赛名单。有人向队员打的比赛的名单,A说他不和X比,C说他不和X、Z比。请编程序找出三对比赛选手名单。
#include"stdio.h"void main(){char ij.k;for(i=‘X’;i<=‘Z’;i++)for(j=‘X’;j<=‘Z’;j++)if(i!=j)for(k=‘X’;k<=‘Z’;k++)if(i!=k&&j!=k)if(i!=‘X’&&k!=‘X’&&k=‘Z’)printf(“A-%cInB-%cInC–%c\n”,i.j.k);}...
2021-07-28 19:02:58
245
原创 26.梅森素数
26.梅森素数#include"stdio.h"#include"math.h"{int prime(int n)long k;int i;k=sqrt(n)+1;for(i=2;i<=k;i++)if(n%i==0)return 0;return 1;}void main()/找出n<=20的所有梅森素数*/{int i;long ms;for(i=2;i<=20;i++)ms=pow(2,i)-1;if(prime(ms))printf(“M(%d)=
2021-07-28 19:02:16
337
原创 25.买卖提将养的一缸金鱼分五次出售系统上一次卖出全部的一半加二分之一条:第二次卖出余下的三分之一加三分之一条;第三次卖出余下的四分之一加四分之一条;第四次卖出余下的五分之一加五分之一条;最后卖出余下
25.买卖提将养的一缸金鱼分五次出售系统上一次卖出全部的一半加二分之一条:第二次卖出余下的三分之一加三分之一条;第三次卖出余下的四分之一加四分之一条;第四次卖出余下的五分之一加五分之一条;最后卖出余下的11条。问原来的鱼缸中共有几条金鱼?#include"stdio.h"float fish(float n)elsereturn ((n+1)/n)*(fish(n+1)+1/(n+1));void main()18float n;n=fish(1);printf("%f",n);}.
2021-07-21 22:20:46
807
原创 24.孪生素数
24.孪生素数#include"stdio.h"#include"math.h"int prime(int n)int j;long k;k=sqrt(n)+1;for(j=2;j<=k;j++)if(n%j0)return 0;retun 1;void main()int i,n,count=0;printf(“please enter the n:”);scanf("%d",&n);printf(“The twin prime pairs between 3
2021-07-21 22:19:51
136
原创 23.定义一个结构体变量(包括年月日)。计算该日在本年中是第几天,注意闰年问题。用函数实现
23.定义一个结构体变量(包括年月日)。计算该日在本年中是第几天,注意闰年问题。用函数实现#include"stdio.h"struct y_m_dint year;int month;int day;]date;int result_days(struct y_m_d datel)int days;switch(datel.month)case 1:days=datel.day; break;case 2:days=datel.day+31;break;case 3:days=da
2021-07-21 22:19:21
560
原创 22.编写一个print函数,打印一个学生的成绩数组,该数组中有5个学生的记录,每个记录包括num,name,score[3],用主函数输入这些记录,用print函数输出这些记录。
22.编写一个print函数,打印一个学生的成绩数组,该数组中有5个学生的记录,每个记录包括num,name,score[3],用主函数输入这些记录,用print函数输出这些记录。#include"stdio.h"#define N 5struct studentchar num[6];char name[8];int score[4];jstu[N];void print(struct student stu(l)int i.j;printf("\nNO.name scorel scor
2021-07-21 22:17:59
1064
原创 21.有10个学生,每个学数据包括学号、姓名、3门课的成绩。从键盘输入10学生的数据,要求打印出3门课的平均成绩,以及最高分的学生数据。
21.有10个学生,每个学数据包括学号、姓名、3门课的成绩。从键盘输入10学生的数据,要求打印出3门课的平均成绩,以及最高分的学生数据。#include"stdio.h"#define N 10struct studentchar num[6];char name[8];int score[4];float ave;)stu[N];void print(struct student stu[])int i,j,maxi;float max:printf("\nNO. name sco
2021-07-21 22:16:43
755
原创 20.编程统计候选人的得票数。设有3个候选人zhang、li、wang(候选人姓名不区分大小写),10个选民,选民每次输入一个得票的候选人的名字,若选民输错候选人姓名,则按废票处理。选民投票结束后程序
20.编程统计候选人的得票数。设有3个候选人zhang、li、wang(候选人姓名不区分大小写),10个选民,选民每次输入一个得票的候选人的名字,若选民输错候选人姓名,则按废票处理。选民投票结束后程序自动显示各候选人的得票结果和废票信息。要求用结构体数组candidate表示3个候选人的姓名和得票结果。#include"stdio.h"#include"string.h"char* toLower(char *p)int i;for(i=0; i < strlen§; i+ +)if (p[
2021-07-21 22:13:20
1750
原创 19.通过键盘输入下面表格中学生的信息,编程计算并输出4门课程平均成绩最高的学生记录。其中,m表示男,f表示女。*/
19.通过键盘输入下面表格中学生的信息,编程计算并输出4门课程平均成绩最高的学生记录。其中,m表示男,f表示女。*/#include <stdio.h>#define N 4struct studentchar stu_no[20];char stu_name[20];char stu_sex;int year;int month;int day;float score[4];float ave;)stu[N];int main()int i,j,maxi;floa
2021-07-21 22:12:50
421
原创 18.编写一个函数,建立一个有三名学生数据的单向动态链表。
18.编写一个函数,建立一个有三名学生数据的单向动态链表。#include"stdio.h"#include"stdlib.h"#define LEN sizeof(struct student)struct student(long num;float score;struct student *next;];int n;//n是全局变量struct student *creat(void)struct student *p1,*p2,*head;n=0;p1=p2=(stru
2021-07-21 22:12:24
457
原创 17.建立简单的静态链表。
17.建立简单的静态链表。#include"stdio.h"struct studentint num;float score;struct student *next;];int main()struct student a,b,c,*head,*p;a.num=10101;a.score=89.5;b.num=10102;b.score=90.5;c.num=10103;c.score=78.5;head=&a;a.next=&b;b.next=&c;
2021-07-21 22:11:24
127
原创 C语言15
#include<stdio.h>int main(){int a=1,b=1,i;for(i=9;i>0;i–){a=2*(a+1);b+=a;}printf(“第一天一共摘了%d\n”,a);return 0;
2021-07-14 19:45:53
202
原创 c语言14
#include <stdio.h>#include <stdlib.h>char *news(int n);int main(){int num;char *n;scanf("%d",&num);n=news(num);printf("%d\n",*n);return 0;}char *news(int n){char *p;p=(char )malloc(nsizeof(char));return p;}————————————————
2021-07-14 19:45:22
115
原创 C语言13
#include<stdio.h>#include<stdlib.h>void bubble(int a[], int n){int i,j,temp;for(i=0;i<n-1;i++){for(j=0;j<n-1-i;j++){if(a[j]>a[j+1]){temp=a[j];a[j]=a[j+1];a[j+1]=temp;}}}}int main(){int N,num,i;scanf("%d", &N);
2021-07-14 19:44:52
188
原创 C语言12
#include<stdio.h>void splitfloat(float x,int *intpart,float *fracpart);int main(void){float x,fracpart;int intpart;scanf("%f",&x);splitfloat(x,&intpart,&fracpart);printf(“intpart=%d\n”,intpart);printf(“fracpart=%f\n”,fracpart);}
2021-07-14 19:44:22
185
原创 C语言11
#include <stdio.h>#include <stdlib.h>#define N 13struct per{int number;int next;}link[N+1];int main(int argc, char *argv[]){int i;for(i=1;i<=N;++i){if(iN)link[i].next=1;elselink[i].next=i+1;link[i].number=i;}int j=N;i=0;
2021-07-14 19:43:45
103
原创 55555
long ctod( char *s ){ long d=0;while(*s)if(isdigit( s)) {/found/d=d10+*s-‘0’;/found/s++;}return d;}long fun( char *a, char *b ){/found/return ctod(a)+ctod(b);}#include <stdio.h>/found/void fun ( char *s, int *a, int *b ){while ( *
2021-07-14 19:43:16
144
原创 44444
double fun(double *x){ int i, j; double av, y[N];av=0;for(i=0; i<N; i++)/found/av+=x[i]/N;for(i=j=0; i<N; i++)if( x[i]<av ){y[j]=x[i]; x[i]=-1;/found/j++;}i=0;while(i<N){ if( x[i]!= -1 ) y[j++]=x[i];/found/i++;}for(i=0; i<N
2021-07-14 19:42:44
5017
原创 二级333
double fun(double *x){ int i, j; double s, av, y[N];s=0;for(i=0; i<N; i++) s=s+x[i];/found/av=s/N;for(i=j=0; i<N; i++)if( x[i]>av ){/found/y[j++]=x[i];x[i]=-1;}for(i=0; i<N; i++)/found/if( x[i]!= -1) y[j++]=x[i];for(i=0; i<N; i
2021-07-14 19:42:13
100
原创 二级222
double fun(double x[],double *av){ int i,j; double d,s;s=0;for(i=0; i<N; i++) s = s +x[i];/found/*av=s/N;d=32767;for(i=0; i<N; i++)if(x[i]<*av && *av - x[i]<=d){/found/d=*av-x[i];j=i;}/found/return x[j];}/found/float fu
2021-07-14 19:41:42
133
原创 二级111
double fun(double x[],double *y){ int i,j; double av;/found/av=0.0;/found/for(i=0; i<N; i++)av=av+x[i]/N;for(i=j=0; i<N; i++)/found/if(x[i]>av) y[j++]= x[i];y[j]=-1;return av;}/found/double fun (int m){ double y=0, d;int i;/found/
2021-07-14 19:41:10
98
原创 编写程序,求出n1至n2自然数之和。要求使用递归方法
9.编写程序,求出n1至n2自然数之和。要求使用递归方法。 #include<stdio.h> he(int n,int m) { int sum=0; if(n==m) return(n); else return(n+he(n+1,m)); } main() { int n,m; scanf("%d%d",&n,&m); printf("%d",he(n,m)); }————————————————版权声明:本文为优快云博主「Nice 2s you.」的原创文章,遵循C
2021-07-08 11:13:21
528
原创 编程统计候选人的得票数
8.编程统计候选人的得票数。设有3个候选人zhang、li、wang(候选人姓名不区分大小写),10个选民,选民每次输入一个得票的候选人的名字,若选民输错候选人姓名,则按废票处理。选民投票结束后程序自动显示各候选人的得票结果和废票信息。要求用结构体数组candidate表示3个候选人的姓名和得票结果。 #include<stdio.h> #include<string.h> struct man { char name[10]; int shu; }m[3]={“zhang”,0,“
2021-07-08 11:12:51
2431
原创 通过键盘输入下面表格中学生的信息
7.通过键盘输入下面表格中学生的信息,编程计算并输出4门课程平均成绩最高的学生记录。其中,m表示男,f表示女。 #include<stdio.h> struct student { int num; char name[10]; char xing; struct birthday { int year; int mouth; int day; }a; int cheng[4]; }; main() { struct student stu[4]={{1,“wanggang”,‘m’,.a={1
2021-07-08 11:12:19
229
原创 任意输入两个字符串,逐个比较两个字符串对应位置上的字符
6.任意输入两个字符串,逐个比较两个字符串对应位置上的字符,并把ASCII值大或相等的字符依次存放到新的数组c中,形成一个新的字符串并输出,要求用函数编程实现。 #include<stdio.h> char bi(char a,char b) { return(a>b?a:b); } main() { char a[10],b[10],c[10]; int i; scanf("%s",&a); scanf("%s",&b); for(i=0;i<10;i++) { c
2021-07-08 11:11:49
1792
原创 输入一个正整数n(1<n<10)
5.输入一个正整数n(1<n<10),再输入n个整数,存入第1个数组中;然后输入一个正整数m(1<m<10),再输入m个整数,存入第2 个数组中,试编写程序找出并输出所有不是这两个数组共有的元素。 #include"stdio.h" main() { int a[10],b[10],m,n,i,j,flag; scanf("%d",&m); for(i=0;i<=m;i++) scanf("%d",&a[10]); scanf("%d",&n); for
2021-07-08 11:11:18
1721
原创 编写一个函数IsLeap(n),
4.编写一个函数IsLeap(n),其功能是:检验一个输入的四位数字是否是闰年,如果是闰年则返回1,否则返回0。在主函数中从键盘输入一个四位数m,调用该函数进行判断,如果是则输出” yes”,否则输出”no”(提示:如果该四位数能被4整除但不能被100整除,则是闰年;如果该四位数能被400整除,则是闰年) #include<stdio.h> lsleap(int n) { if(n%40&&n%100!=0||n%4000) return(1); else return(0);
2021-07-08 11:10:47
2007
原创 使用函数判断完全平方数
3.使用函数判断完全平方数:输入一个正整数n,判断其是否为完全平方数,如果是,则输出”YES”,如果不是,则输出”NO”。要求定义并调用函数IsSquare(n),判断n是否为完全平方数。 #include<stdio.h> lsleap(int n) { int i,a=0; for(i=0;i<=n;i++) if(i*i==n) a=1; return(a); } main() { int n; scanf("%d",&n); if(lsleap(n)) printf(“ye
2021-07-08 11:10:17
2518
原创 用函数计算两点间的距离
2.使用函数计算两点间的距离:给定平面任意两点坐标(x1,y1)和(x2,y2),求这两点之间的距离(保留两位小数)。要求定义和调用函数dist(x1,y1,x2,y2)计算两点间的距离。 #include<stdio.h> #include<math.h> double dist(double x1,double y1,double x2,double y2) { return(sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2))); } main() { int
2021-07-08 11:09:48
2841
原创 2021-07-08
1.使用函数求奇数和:输入一批正整数(以零或负数为结束标志),求其中所有奇数的和。要求定义和调用函数even(n),判断整数的奇偶性,当n为偶数时返回1,否则返回0。#include<stdio.h>even(int n){ if(n%2)return(1);else return(0);}main() { int n,sum=0; scanf("%d",&n); while(n) { if(even(n)) sum+=n; scanf("%d",&n); } pr
2021-07-08 11:09:16
127
原创 二级作业1
void fun(char *filename, STU n){ FILE *fp;/found/fp = fopen(filename, “rb+”);/found/fseek(fp, -(long)sizeof(STU), SEEK_END);/found/fwrite(&n, sizeof(STU), 1, fp);fclose(fp);}{ NODE *h=NULL, *p, s;int i;/found/p=(NODE *)malloc(sizeof(NODE))
2021-07-08 11:08:30
182
原创 2021-02-25
#include"stdio.h"void main(){int i,j,k,n;printf(“The Narcissistic number:\n”);printf("\n");for(n=100;n<1000;n++){i=n/100;j=(n-100i)/10;k=n%10;if(iii+jjj+kk*k==n)printf("%d\t",n);}printf("\n");}
2021-02-25 03:05:17
89
原创 2021-02-25
第九题:判断一个数是否为"水仙花数",所谓"水仙花数"是指一个三位数其各位数字的立方和等于该数本身。例如:371是一个"水仙花数",371=33+73+1^3.#include"stdio.h"void main(){int i,j,k,n;printf(“please input the n:\n”);scanf("%d",&n);printf("\n");i=n/100;j=(n-100*i)/10;k=n%10;if(i*i*i+j*j*j+k*k*k==n)
2021-02-25 03:04:41
90
原创 2021-02-25
#include"stdio.h"void main(){int i,j,n;int count=0;printf(“请输入n:\n”);scanf("%d",&n);for(i=2;i<=n;i++){for(j=2;j<i;j++)if(i%j0)break;if(ji){printf("%d\t",i);count++;}}printf("\n1~%d之间有%d个素数!!!\n",n,count);}...
2021-02-25 03:04:08
92
原创 2021-02-25
第七题:计算下面的分段函数,#include"stdio.h"void main(){int x;printf(“please input the x:\n”);scanf(“x=%d”,&x);if(x==0)printf(“y=0\n”);elseprintf(“y=%f\n”,1.0/x);}
2021-02-25 03:03:32
87
原创 2021-02-25
第四题:从键盘输入一个n,计算1到n的和。#include"stdio.h"void main(){int i=1,n;int sum=0;printf(“please input the n:\n”);scanf("%d",&n);while(i<=n){sum+=i;i++;}printf(“the result is :%d\n”,sum);}
2021-02-25 03:02:39
96
原创 2021-02-25
第六题:#include"stdio.h"void main(){int x,y;printf(“please input the x:\n”);scanf(“x=%d”,&x);if(x<1)y=x;else if(x<10)y=2x-1;elsey=3x-1;printf(“y=%d\n”,y);}
2021-02-25 03:01:53
72
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅