//1. 1£¡+2£¡+3£¡+...20!
/*
#include <stdio.h>
int main()
{int i;long sum=0,k=1;for(i=1;i<=20;i++){k*=i;sum+=k;}printf("%d",sum);
}
*///方法2
/*
#include <stdio.h>
int main()
{int i,j;long sum=0,k;for(i=1;i<=20;i++){k=1;for(j=1;j<=i;j++){k*=j;}sum+=k;}printf("%d",sum);
}
*///2. 利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来
/*
#include<stdio.h>
void reverse(int n)
{int next;if(n<=1){next=getchar();putchar(next);}else{next=getchar();reverse(n-1);putchar(next);}
}int main()
{int n=5; //这里n是字母的个数,也可以通过键盘输入reverse(n);return 0;
}
*///3. 输入一个小于5位的正整数,分别输出它的位数及其逆序打印出各位数字
/*
#include<stdio.h>int main()
{int a,b,c,d,e,x;printf("请输入一个小于5位的正整数;");scanf("%d",&x);a=x/10000;b=x%10000/1000;c=x%1000/100;d=x%100/10;e=x%10;if(a!=0){printf("为5位数字,逆序为:%d%d%d%d%d\n",e,d,c,b,a);}else if(b!=0){printf("为4位数字,逆序为:%d%d%d%d",e,d,c,b);}else if(c!=0){printf("位3位数字,逆序为:%d%d%d",e,d,c);}else if(d!=0){printf("为2位数字,逆序为:%d%d",e,d);}else if(e!=0){printf("位1位数字,逆序为:%d",e);}return 0;
}
*///编写一个程序输出 HelloWord//4. 输入3个数abc 输出他们其中最大的数
/*
#include<stdio.h>
int main()
{int a,b,c,max;printf("请输出a,b,c\n");scanf("%d%d%d",&a,&b,&c);if(a>b){if(c>a)max=c;elsemax=a;}else{if(c>b)max=c;elsemax=b;}printf("max=%d",max);return 0;
}
*///5. 请输入星期几的第一个字母来判断是星期几,
//如果第一个字母一样,则继续判断第二个字母
/*
#include <stdio.h>int main()
{char i, j;printf("请输入第一个字母:");scanf("%c", &i);getchar();//处理‘\n’switch (i){case 'm':printf("monday\n");break;case 'w':printf("wednesday\n");break;case 'f':printf("friday\n");break;case 't':printf("请输入下一个字母\n");scanf("%c", &j);if ('u' == j) {printf("tuesday\n");break;}if ('h' == j) {printf("thursday\n");break;}case 's':printf("请输入下一个字母\n");scanf("%c", &j);if ('a' == j) {printf("saturday\n");break;}if ('u' == j) {printf("sunday\n");break;}default:printf("error\n");break;}return 0;
}
*/// 6. 函数调用的用法实例
/*
#include<stdio.h>
int main()
{int n;printf("打印多少次:");scanf("%d",&n);hello(n);return 0;
}
void hello(n)
{if(n){printf("hello C!\n");hello(n-1);}}*///7. 求2/1,3/2, 5/3,8/5,13/8,21/13...这个数列的前20项之和/*#include<stdio.h>
int main()
{int i,t;float sum=0;float a=2,b=1;for(i=1;i<=20;i++){sum=sum+a/b;t=a;a=a+b;b=t;}printf("%f\n",sum);return 0;
}
*/
//8. 打印出所有的水仙花数(一个三位数,其各位数字立方和等于该数本身)
/*
int main()
{int i,x,y,z;for(i=100;i<1000;i++){x=i%10;y=i/10%10;z=i/100%10;if(i==(x*x*x+y*y*y+z*z*z))printf("%d\n",i);}return 0;
}
*///9. 输出101-200 之间的素数
/*
#include<stdio.h>
int main()
{int i,j;int count=0;for(i=101;i<=200;i++){for(j=2;j<i;j++){if(i%j==0)break;}if(j>=i){count++;printf("%d ",i);if(count%5==0)printf("\n");}}return 0;
}
*///10 . 输出9*9乘法表口诀
/*
#include<stdio.h>
int main()
{int i,j,result;for(i=1;i<10;i++){for(j=1;j<=i;j++){result=i*j;printf("%d*%d=%-3d",i,j,result); //-3d表示左对齐,占3位}printf("\n");}return 0;}
*///11 .输入三个整数xyz,请把这三个数由小到大输出。
/*
#include<stdio.h>
int main()
{int x,y,z,t;printf("请输入三个数字:\n");scanf("%d %d %d",&x,&y,&z);//return 0;if(x>y){t=x;x=y;y=t;}if(x>z){t=x;x=z;z=t;}if(y>z){t=y;y=z;z=t;}printf("从小到大的顺序:%d %d %d\n",x,y,z);return 0;
}
*/
// 12.判断2000-2500年中的每一年是否为闰年,并将结果输出
/*
#include<stdio.h>
int main()
{int i;for(i=2000;i<=2500;i++){if(i%400==0||i%4==0&&i%100!=0){printf("闰年的年份:%d\n",i);continue;}else{continue;//printf("不是闰年的年份:%d\n",i);}}
}
*///13 . 输入一个数是否能被3和5整除
/*
#include<stdio.h>
int main()
{int a;printf("请输入一个数:");scanf("%d",&a);if(a%3==0&&a%5==0){printf("这是能被3和5整除的数:%d",a);}else{printf("不能:%d",a);}
}
*///14 . 求1+2+3+...+100的和
/*
#include<stdio.h>
int main()
{int i,a=0;for(i=1;i<=100;i++){a+=i;}printf("%d",a);
}
*/
//15. 求两个数m和n的最大公约数
/*
#include<stdio.h>
//#include<stdlib.h>
int main(){
#include<stdio.h>
int a,b,r,t;
printf("请输入两个数");
scanf("%d,%d",&a,&b);
if(b==0){t=a;a=b;b=t;
}
while(a%b!=0){r=a%b;a=b;b=r;
}
printf("最大公约数为:%d",r);
return 0;
}
*///16 依次输入10个数,求出之中的最大数
/*
#include<stdio.h>
int main()
{int b[10]={0};int a;int i,max;for(i=0;i<10;i++){printf("please input your ten number%d:",i);scanf("%d",&b[i]);}max=b[0];for(i=0;i<10;i++){if(max<b[i]){max=b[i];a=i+1;}}printf("max:max=%d\n",max);printf("max index:%d\n",a);
}
*/// 17迭代法
//1-1/2+1/3-1/4+.....+1/99-1/100
/*
#include<stdio.h>
int main()
{int i;double sum = 0.0;for (i = 1; i <= 100; i++){if (i % 2 == 0){sum -= 1.0/i;}else{sum += 1.0/i;}}printf("The result is: %lf\n", sum);return 0;
}
*///18 给出一个大于或等于3的正整数,判断它是不是一个素数
// 所谓素数prime是指除了1和该本身之外,不能被其他任何整数整除的数
//输出1-100之间的素数
/*
#include<stdio.h>
int main()
{int i,j;for(i=2;i<100;i++){int isprime=1;for(j=2;j<i;j++){if(i%j==0){isprime=0;break;}}if(isprime==1){printf("%d ",i);}}return 0;
}
*///19 求5!
/*
#include<stdio.h>
int main()
{int i,n=5,fact=1;for(i=1;i<=n;i++){fact*=i;}printf("%d!=%d\n",n,fact);
}
*/
//20 有50个同学,要求将成绩在80分以上的学生的学号和成绩输出 c语言
/*
#include <stdio.h>int main()
{int i, score[50], id[50];for (i = 0; i < 50; i++){printf("请输入第%d个学生的学号和成绩:", i + 1);scanf("%d%d", &id[i], &score[i]);}printf("成绩在80分以上的学生有:\n");for (i = 0; i < 50; i++){if (score[i] >= 80){printf("学号:%d,成绩:%d\n", id[i], score[i]);}}return 0;
}
*//*
#include<stdio.h>
int main()
{int i,j;for(i=1;i<=4;i++){for(j=1;j<=i;j++){printf("&");}printf("\n");}return 0;
}
*/
// 21 输入一个字符串,统计出其中字母、数字和其他字符的个数
/*
#include<stdio.h>
int main()
{char s[50];int i,alpha=0,digit=0,other=0;gets(s);for(i=0;s[i]!='\0';i++){if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z'){alpha++;}else if(s[i]>='0'&&s[i]<='9'){digit++;}else {other++;}}printf("alpha:%d,digit:%d,other:%d",alpha,digit,other);return 0;
}*///22 编写一个函数,输入一个整数数组和数组长度,输出该数组中的最大值、最小值和平均值。
/*
#include<stdio.h>
void operator(int a[], int n, int *max, int *min, float *avg) {int sum=0, i;*max=*min=a[0]; // 假设a列表中第一个数为最大数,最小数。for (i=0; i<n; i++) {sum += a[i];if (a[i]>*max) {*max=a[i];}if (a[i]<*min) {*min=a[i];}}*avg=(float)sum/n; // 注意强制类型转换为float类型
}
int main() {int i, n, a[50], max, min;float avg;scanf("%d", &n);for (i=0; i<n; i++) {scanf("%d", &a[i]); // 读入数组}operator(a, n, &max, &min, &avg); // 调用函数printf("最大值:%d,最小值:%d,平均值:%0.2f", max, min, avg);return 0;
}*/
//23 设计一个计算器程序,可以进行加、减、乘、除和求幂运算/*
#include<stdio.h>
#include<math.h>
int main() {int a, b, oper;printf("请输入两个整数:");scanf("%d%d", &a, &b);printf("请输入运算符号:1. 加 2. 减 3. 乘 4. 除 5. 求幂 ");scanf("%d", &oper);switch (oper) {case 1: printf("结果为:%d", a+b); break;case 2: printf("结果为:%d", a-b); break;case 3: printf("结果为:%d", a*b); break;case 4: printf("结果为:%d", a/b); break;case 5: printf("结果为:%f", pow(a, b)); break;default: printf("输入有误,请重新输入!");}return 0;
}
*///24 编写一个程序,输入任意一个整数n,输出n的阶乘,要求使用递归实现。
/*
#include<stdio.h>
int factorial(int n) {if (n==0) { // base casereturn 1;} else {return n * factorial(n-1); // 递归调用}
}
int main() {int n, result;scanf("%d", &n);result=factorial(n);printf("%d的阶乘为%d", n, result);return 0;
}
*/
// TEST
/*
#include <stdio.h>
void main()
{//printf("123456789\n");// printf("h\ti\n");// printf("h\ti\bj_k\n");// printf("h\ti\rj_k\n");// printf("\a");
}
*//*
#include<stdio.h>
int main()
{int a,b;// b=(a=3*5,a*4);b=((a=3*5,a*4),a+5);printf("%d",a);printf("\n");printf("%d",b);return 0;
}
*/
//test
/*
#include<stdio.h>
int main()
{int a,b,c,d;// scanf("%d%d%d%d",&a,&b);//printf("%d,%d,%d,%d\n",a,b);//printf("\n");scanf("%c%c",&c,&d);printf("%c,%c\n",c,d);
}*/
// 查询成绩
/*
#include<stdio.h>
int main()
{int x,mark;printf("请输入您的成绩:");scanf("%d",&mark);if(mark>=90)printf("优秀");else if(mark>=80)printf("良好");else if(mark>=70)printf("中等");else if(mark>=60)printf("及格");elseprintf("不及格");
}
*/
//判断是否为闰年
/*
#include<stdio.h>
int main()
{int year,leap;printf("please input");scanf("%d",&year);if((year%4==0&&year%100!=0)||(year%400==0))printf("闰年");elseprintf("非闰年");
}
*/
/*
#include<stdio.h>
int main()
{int i,sum=0;while(i<=100){sum=sum+i;i++;}printf("sum=%d",sum);
}
*/
/*
#include<stdio.h>
int main()
{int i,sum=0;do{sum=sum+i;i++;}while(i<=100);printf("sum=%d",sum);}
*/
// 菱形
/*
#include<stdio.h>
int main()
{int i,j;for(i=1;i<=4;i++){for(j=1;j<=4-i;j++)printf(" ");for(j=1;j<=i*2-1;j++)printf("*");printf("\n");}for(i=3;i>=1;i--){for(j=1;j<=4-i;j++)printf(" ");for(j=1;j<=i*2-1;j++)printf("*");printf("\n");}
}
*///小小矩阵
/*
#include<stdio.h>
void main()
{int i,j,n=0;for(i=1;i<=4;i++)for(j=1;j<=5;j++,n++){if(n%5==0&&n!=0)printf("\n");printf("%d\t",i*j);}printf("\n");}
*/
//1!+2!+3!+4!+5!
/*
#include<stdio.h>
void main()
{int i,j=1;int sum=0;for(i=1;i<=5;i++){j*=i;sum+=j;}printf("%d",sum);
}
*/
//2
/*
#include<stdio.h>
void main()
{int i,j;int sum=0,jec=1;for(i=1;i<=5;i++){jec=1;for(j=1;j<=i;j++){jec*=j;}sum+=jec;}printf("%d",sum);
}
*///迭代法
/*
#include<stdio.h>
#include<math.h>
void main()
{int sign=1;double n=1,pi=0,term=1;while(fabs(term)>=1e-6){pi+=term;n+=2;sign=-sign;term=sign/n;}pi=pi*4;printf("pi=%10.8lf\n",pi);
}
*//*
//打印1000以内的水仙花数
#include<stdio.h>
int main()
{int i,a,b,c;for(i=100;i<=999;i++){a=i%10;b=i/10%10;c=i/100%10;if(i==(a*a*a+b*b*b+c*c*c))printf("%d ",i);}
}
*/
/*
// 求素数#include <stdio.h>
#include <math.h>
int prime(int x);
int main()
{int i;for(i=100;i<=200;i++){if(prime(i)) printf("%d ",i);}return 0;
}
int prime(int x)
{int i;if(x==1) return 0;for(i=2;i<=sqrt(x);i++)if(x%i==0) return 0;return 1;
}
*/
/*
// fib 兔子
#include<stdio.h>int fib(int x)
{if(x==0)return 0;else if (x==1||x==2)return 1;elsereturn fib(x-1)+fib(x-2);
}int main() {int month;printf("请输入月份:");zscanf("%d", &month);int result = fib(month);printf("第%d个月共有%d对兔子\n", month, result);return 0;
}
*//*
#include <stdio.h>int main()
{int i,t,s=0,sign=1;for(i=1;i<=101;i+=2){t=sign*i;s+=t;sign=-sign;//printf("%d\n",s);}printf("%d",s);return 0;
}
*/
/*
#include<stdio.h>
int main()
{int m=5;if(m++>5)printf("%d\n",m);elseprintf("%d\n",m--);return 0;
}
*/
/*
#include<stdio.h>
int main()
{printf("abc123\rdef");
}
*/
//实现一个小型计算器
/*
#include<stdio.h>
int main()
{printf("hello");
}
*/// 函数调用n的阶乘
/*
#include<stdio.h>
int main()
{int fac(int n);int n,y;printf("please input:");scanf("%d",&n);y=fac(n);printf("%d!=%d\n",n,y);return 0;}
int fac(int n){int f;if(n<0) printf("error");else if(n==0||n==1) f=1;else f=fac(n-1)*n;return (f);
}
*/
// 函数调用五个同学问年龄的问题
/*
#include<stdio.h>
int main()
{int age(int n);printf("%d\n",age(5));return 0;
}
int age(int n)
{int c;if(n==1)c=10;elsec=age(n-1)+2;return (c);
}
*/
/*
问题利用数组实现寻找最大值
*/
/*
#include<stdio.h>
int main()
{int max(int x, int y);//定义实参int a[10],m,n,i;//这里需要用到的数组 和三个变量m用于最大值,n用于下标 i用于循环printf("enter 10 integer numbers;");//for (i=0;i<10;i++)//外层循环为了给数组赋初值scanf("%d",&a[i]);printf("\n");for(i=1,m=a[0],n=0;i<10;i++)//内层for循环,在这个吧a[0]给到了m{if(max(m,a[i])>m)//把m和下一个数作为实参传递到形参去运算判断最大值返回的数和上个最大值的m比较{m=max(m,a[i]);//如果条件满足把m的值替换掉n=i;//当前下标}}printf("the largest number is%d\nit is the %dth number.\n",m,n+1);}
int max(int x,int y)
{return (x>y? x:y);
}
*/
/*
#include<stdio.h>
int main()
{float x,y;//x表示服务类型 y表示汽油类型float n,m;//n表示汽油的数量
}
*/
/*
#include<stdio.h>
#include <stdlib.h>
int main(){int a[5]={1,4,5,8,9};int b[5]={2,6,8,10,11};int c[10];int i=0,j=0,k=0;while(i<5&&j<5){if (a[i]<b[i]){c[k++]=a[i++];}else{c[k++]=b[j++];}}while(i<5){c[k++]=a[i++];}while(j<5){c[k++]=b[i++];}for(k=0;k<10;k++){printf("%d\t",c[k]);}return 0;
}
*/
/*
#include <stdio.h>int main()
{printf("Prime numbers between 1 and 100 are:\n");for (int i = 2; i <= 100; i++) {int j;for (j = 2; j <= i; j++)if (i % j == 0) {break;}if (j >= i) {printf("%d ", i);}}return 0;
}
*/
/*
#include <stdio.h>int main()
{printf("Prime numbers between 1 and 100 are:\n");for (int i = 2; i <= 100; i++){int j;for (j = 2; j <= i; j++)if (i % j == 0){break;}if (j>=i){printf("%d ", i);}}return 0;
}
*///指针/*
#include<stdio.h>
int main()
{int *p1,*p2,*p,a,b;printf("please enter two integer numbers:");scanf("%d,%d",&a,&b);p1=&a;p2=&b;if(a<b){p1=&b,p2=&a;}printf("a=%d,b=%d\n",a,b);printf("max=%d,min=%d\n",*p1,*p2);return 0;
}
*/
/*
#include<stdio.h>
int main()
{void exchange(int *q1,int *q2,int *q3);int a,b,c,*p1,*p2,*p3;printf("please enter three numbers:");scanf("%d,%d,%d",&a,&b,&c);p1=&a;p2=&b,p3=&c;exchange(p1,p2,p3);printf("the order is:%d,%d,%d\n",a,b,c);return 0;
}
void exchange(int *q1,int*q2,int*q3)
{void swap(int *pt1,int*pt2);if(*q1<*q2)swap(q1,q2);if(*q1<*q3)swap(q1,q3);if(*q2<*q3)swap(q2,q3);}
void swap(int * pt1,int * pt2)
{int temp;temp=*pt1;*pt1=*pt2;*pt2=temp;}
*/
//数组交换
/*
#include<stdio.h>
#define N 10
int main()
{int a[N]={0,1,2,3,4,5,6,7,8,9};int i,t;printf("Original array:\n");for(i=0;i<N;i++)printf("%d ",a[i]);for(i=0;i<N/2;i++){t=a[i];a[i ]=a[N-1-i];a[N-1-i]=t;}printf("\nSorted array:\n");for(i=0;i<N;i++)printf("%d ",a[i]);printf("\n");return 0;
}
*//*
#include <stdio.h>void reverse(char* s)
{// 获取字符串长度int len = 0;char* p = s;while (*p != 0){len++;p++;}// 交换 ...int i = 0;char c;while (i <= len / 2 - 1){c = *(s + i);*(s + i) = *(s + len - 1 - i);*(s + len - 1 - i) = c;i++;}
}int main()
{char s[] = "www.runoob.com";printf("'%s' =>\n", s);reverse(s); // 反转字符串printf("'%s'\n", s);return 0;
}*//*
#include<stdio.h>
int main(){char a[100];char *p;p=a;do{*p++=getchar();}while(*(p-1)!='\n');for(*p='\0';p>=a;p--)printf("%c",*p);return 0;
}*///100 随机产生若干个10以内的自然数存储在数组中,删除其中重复的元素,输出原数组和新数组/*
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 10
void main()
{int a[N];int i,j;srand(time(NULL));for(i=0;i<N;i++){a[i]=rand()%11;printf("%3d",a[i]);}printf("\n");for(i=0;i<N-1;i++)for(j=i+1;j<N;j++)if(a[j]==a[i])a[j]=-1;for(i=0;i<N;i++)if(a[i]!=-1)printf("%3d",a[i]);}
*/// 99 假设有13位评委参与评分工作,计算每位歌手最终得分的方法是;
//去掉一个最高分和一个最低分,然后计算剩余11哥分数的平均值,所得结果就是最终得分/*
#include<stdio.h>
#define N 13
void main()
{int score[N],i,sum=0,max,min;for(i=0;i<N;i++){scanf("%d,",&score[i]);sum+=score[i];}max=score[0];
min=score[0];
for(i=0;i<N;i++)
{if(max<score[i]) max=score[i];if(min>score[i]) min=score[i];printf("%3d",(int)(sum-max-min)/(N-2));}
}
*///98模拟投筛子游戏100次,编程统计并输出色子的6个面各自出现的次数/*
#include<stdio.h>
#define N 100
#include<stdlib.h>
#include<time.h>
void main()
{int s[N];int a,b,c,d,e,f,i;srand(time(0));for(i=0;i<N;i++)s[i]=rand()%6+1;a=b=c=d=e=f=0;for(i=1;i<=N;i++){if (s[i]==1)a++;else if (s[i]==2)b++;else if (s[i]==3)c++;else if (s[i]==4)d++;else if (s[i]==5)e++;else if (s[i]==6)f++;}printf("1,%2d\n",a);printf("2,%2d\n",b);printf("3,%2d\n",c);printf("4,%2d\n",d);printf("5,%2d\n",e);printf("6,%2d\n",f);}*/
// 方法2
/*
#include<stdio.h>
#include<time.h>
#include<stdlib.h>int main()
{int num[100], times[6] = {0}, i;srand(time(0));for(i = 0; i < 100; i++) {num[i] = rand() % 6 + 1;times[num[i] - 1]++;printf("%3d", num[i]);}printf("\n");for(i = 0; i < 6; i++) {printf("%d,%3d\n", i + 1, times[i]);}return 0;
}
*///有一个3*4的矩阵,要求编程求出其中值最大的那个元素的值,以及其所在的行号和列号/*
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define M 3
#define N 4
int main()
{int i,j,max,a[M][N],m,n;srand(time(NULL));for(i=0; i<M; i++){for(j=0; j<N; j++){a[i][j]=rand()%90+10;printf("%d\t",a[i][j]);}printf("\n");}max=a[0][0];m=0;n=0;for(i=0; i<M; i++)for(j=0; j<N; j++)if(max<a[i][j]){max=a[i][j];m=i;n=j;}printf("%d,%d,%d",max,m,n);return 0;
}*//*
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{char a[20]={0};char b[]="1234567";strncpy(a,b,3);puts(a);puts(b);return 0;
}
*/
/*
#include<stdio.h>
#include<math.h>
double f(double x)
{if (x<=-2) return -1*exp(2*x+1)+3;else if(x>-2&&x<=3) return 2*x-1;else return 2*log10(3*x+5)-11;}int main()
{double x;scanf("%lf",&x);printf("%.2lf",f(x));
}
*/
/*
#include<stdio.h>
int main()
{int i,t=0,n,sum=0;scanf("%d",&n);for(i=1;i<=n;i++){t=t*10+i;sum+=t;}printf("%d",sum);
}*//*结构体类型数组编写一个程序用来输入学生的基本情况信息学生的基本情况信息包括;学号,姓名,c语言成绩,数学成绩,英语成绩,
要求统计每名同学的平均成绩和总成绩,对c语言成绩进行排序,统计c语言不及格的学生信息及不及格人数
*/
/*
#include<stdio.h>
#define M 5
struct student
{int xh;char sm[8];float ccj;float sx;float yycj;float pjcj;float sumcj;float xx;
};
void main()
{struct student xs[M],a;int i,j,count=0;for(i=0;i<M;i++)scanf("%d,%s,%f,%f,%f",&xs[i].xh,xs[i].sm,xs[i].ccj,&xs[i].sx,&xs[i].yycj);for(i=0;i<M;i++)xs[i].pjcj=(xs[i].ccj+xs[i].sx+xs[i].yycj)/3;xs[i].sumcj=(xs[i].ccj+xs[i].sx+xs[i].yycj);for(i=0;i<M;i++)for(j=0;j<M-i-1;j++){if(xs[j].ccj<xs[j+1].ccj)a=xs[j];xs[j]=xs[j+1];xs[j+1]=a;}for (i = 0; i < M; i++) {if (xs[i].ccj < 60) {xs[i].xx = xs[i].ccj;count++;}}printf("%d%s%f%f%f%f%f%f%d",xs[i].xh,xs[i].sm,xs[i].ccj,xs[i].sx,xs[i].yycj,xs[i].pjcj,xs[i].sumcj,xs[i].xx,count);}
*///以下是根据您提供的代码进行了修复的正确版本:/*
#include <stdio.h>
#define M 5struct student
{int xh;char sm[8];float ccj;float sx;float yycj;float pjcj;float sumcj;float xx;
};int main()
{struct student xs[M], a;int i, j, count = 0;for (i = 0; i < M; i++)scanf("%d, %s, %f, %f, %f", &xs[i].xh, xs[i].sm, &xs[i].ccj, &xs[i].sx, &xs[i].yycj);for (i = 0; i < M; i++){xs[i].pjcj = (xs[i].ccj + xs[i].sx + xs[i].yycj) / 3;xs[i].sumcj = xs[i].ccj + xs[i].sx + xs[i].yycj;}for (i = 0; i < M; i++){for (j = 0; j < M - i - 1; j++){if (xs[j].ccj < xs[j + 1].ccj){a = xs[j];xs[j] = xs[j + 1];xs[j + 1] = a;}}}for (i = 0; i < M; i++){if (xs[i].ccj < 60){xs[i].xx = xs[i].ccj;count++;}}for (i = 0; i < M; i++){printf("%d, %s, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d\n", xs[i].xh, xs[i].sm, xs[i].ccj, xs[i].sx, xs[i].yycj, xs[i].pjcj, xs[i].sumcj, xs[i].xx, count);}return 0;
}
*//*
#include <stdio.h>#define MAX_STUDENTS 100 // 最大学生数量
#define PASS_GRADE 60 // 及格分数线typedef struct {int studentID; // 学号char name[50]; // 姓名int cGrade; // C语言成绩int mathGrade; // 数学成绩int englishGrade; // 英语成绩float averageGrade; // 平均成绩int totalGrade; // 总成绩
} Student; // 学生结构体类型void inputStudentInfo(Student *student, int n) {for (int i = 0; i < n; i++) {printf("Enter student %d's ID: ", i+1); // 输入学号scanf("%d", &student[i].studentID);printf("Enter student %d's name: ", i+1); // 输入姓名scanf("%s", student[i].name);printf("Enter student %d's C grade: ", i+1); // 输入C语言成绩scanf("%d", &student[i].cGrade);printf("Enter student %d's Math grade: ", i+1); // 输入数学成绩scanf("%d", &student[i].mathGrade);printf("Enter student %d's English grade: ", i+1); // 输入英语成绩scanf("%d", &student[i].englishGrade);student[i].totalGrade = student[i].cGrade + student[i].mathGrade + student[i].englishGrade; // 计算总成绩student[i].averageGrade = (float)student[i].totalGrade / 3; // 计算平均成绩}
}void sortCGrades(Student *student, int n) {Student temp;for (int i = 0; i < n-1; i++) {for (int j = 0; j < n-i-1; j++) {if (student[j].cGrade > student[j+1].cGrade) { // 使用冒泡排序对C语言成绩进行排序temp = student[j];student[j] = student[j+1];student[j+1] = temp;}}}
}void printStudentInfo(Student *student, int n) {printf("Student Information:\n");for (int i = 0; i < n; i++) {printf("Student %d\n", i+1);printf("ID: %d\n", student[i].studentID);printf("Name: %s\n", student[i].name);printf("C Grade: %d\n", student[i].cGrade);printf("Math Grade: %d\n", student[i].mathGrade);printf("English Grade: %d\n", student[i].englishGrade);printf("Total Grade: %d\n", student[i].totalGrade);printf("Average Grade: %.2f\n", student[i].averageGrade);printf("--------------------------\n");}
}void printFailingCGrades(Student *student, int n) {int count = 0;printf("Students with failing C grades:\n");for (int i = 0; i < n; i++) {if (student[i].cGrade < PASS_GRADE) { // 判断C语言成绩是否不及格printf("Student ID: %d\n", student[i].studentID);printf("Name: %s\n", student[i].name);printf("C Grade: %d\n", student[i].cGrade);printf("--------------------------\n");count++; // 统计不及格人数}}printf("Total number of students with failing C grades: %d\n", count);
}int main() {Student students[MAX_STUDENTS]; // 学生数组int numStudents; // 学生数量printf("Enter the number of students: ");scanf("%d", &numStudents); // 输入学生数量inputStudentInfo(students, numStudents); // 输入学生信息sortCGrades(students, numStudents); // 对C语言成绩排序printStudentInfo(students, numStudents); // 打印学生信息printFailingCGrades(students, numStudents); // 打印不及格学生信息return 0;
}*///1. 1£¡+2£¡+3£¡+...20!
/*
#include <stdio.h>
int main()
{int i;long sum=0,k=1;for(i=1;i<=20;i++){k*=i;sum+=k;}printf("%d",sum);
}
*///方法2
/*
#include <stdio.h>
int main()
{int i,j;long sum=0,k;for(i=1;i<=20;i++){k=1;for(j=1;j<=i;j++){k*=j;}sum+=k;}printf("%d",sum);
}
*///2. 利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来
/*
#include<stdio.h>
void reverse(int n)
{int next;if(n<=1){next=getchar();putchar(next);}else{next=getchar();reverse(n-1);putchar(next);}
}int main()
{int n=5; //这里n是字母的个数,也可以通过键盘输入reverse(n);return 0;
}
*///3. 输入一个小于5位的正整数,分别输出它的位数及其逆序打印出各位数字
/*
#include<stdio.h>int main()
{int a,b,c,d,e,x;printf("请输入一个小于5位的正整数;");scanf("%d",&x);a=x/10000;b=x%10000/1000;c=x%1000/100;d=x%100/10;e=x%10;if(a!=0){printf("为5位数字,逆序为:%d%d%d%d%d\n",e,d,c,b,a);}else if(b!=0){printf("为4位数字,逆序为:%d%d%d%d",e,d,c,b);}else if(c!=0){printf("位3位数字,逆序为:%d%d%d",e,d,c);}else if(d!=0){printf("为2位数字,逆序为:%d%d",e,d);}else if(e!=0){printf("位1位数字,逆序为:%d",e);}return 0;
}
*///编写一个程序输出 HelloWord//4. 输入3个数abc 输出他们其中最大的数
/*
#include<stdio.h>
int main()
{int a,b,c,max;printf("请输出a,b,c\n");scanf("%d%d%d",&a,&b,&c);if(a>b){if(c>a)max=c;elsemax=a;}else{if(c>b)max=c;elsemax=b;}printf("max=%d",max);return 0;
}
*///5. 请输入星期几的第一个字母来判断是星期几,
//如果第一个字母一样,则继续判断第二个字母
/*
#include <stdio.h>int main()
{char i, j;printf("请输入第一个字母:");scanf("%c", &i);getchar();//处理‘\n’switch (i){case 'm':printf("monday\n");break;case 'w':printf("wednesday\n");break;case 'f':printf("friday\n");break;case 't':printf("请输入下一个字母\n");scanf("%c", &j);if ('u' == j) {printf("tuesday\n");break;}if ('h' == j) {printf("thursday\n");break;}case 's':printf("请输入下一个字母\n");scanf("%c", &j);if ('a' == j) {printf("saturday\n");break;}if ('u' == j) {printf("sunday\n");break;}default:printf("error\n");break;}return 0;
}
*/// 6. 函数调用的用法实例
/*
#include<stdio.h>
int main()
{int n;printf("打印多少次:");scanf("%d",&n);hello(n);return 0;
}
void hello(n)
{if(n){printf("hello C!\n");hello(n-1);}}*///7. 求2/1,3/2, 5/3,8/5,13/8,21/13...这个数列的前20项之和/*#include<stdio.h>
int main()
{int i,t;float sum=0;float a=2,b=1;for(i=1;i<=20;i++){sum=sum+a/b;t=a;a=a+b;b=t;}printf("%f\n",sum);return 0;
}
*/
//8. 打印出所有的水仙花数(一个三位数,其各位数字立方和等于该数本身)
/*
int main()
{int i,x,y,z;for(i=100;i<1000;i++){x=i%10;y=i/10%10;z=i/100%10;if(i==(x*x*x+y*y*y+z*z*z))printf("%d\n",i);}return 0;
}
*///9. 输出101-200 之间的素数
/*
#include<stdio.h>
int main()
{int i,j;int count=0;for(i=101;i<=200;i++){for(j=2;j<i;j++){if(i%j==0)break;}if(j>=i){count++;printf("%d ",i);if(count%5==0)printf("\n");}}return 0;
}
*///10 . 输出9*9乘法表口诀
/*
#include<stdio.h>
int main()
{int i,j,result;for(i=1;i<10;i++){for(j=1;j<=i;j++){result=i*j;printf("%d*%d=%-3d",i,j,result); //-3d表示左对齐,占3位}printf("\n");}return 0;}
*///11 .输入三个整数xyz,请把这三个数由小到大输出。
/*
#include<stdio.h>
int main()
{int x,y,z,t;printf("请输入三个数字:\n");scanf("%d %d %d",&x,&y,&z);//return 0;if(x>y){t=x;x=y;y=t;}if(x>z){t=x;x=z;z=t;}if(y>z){t=y;y=z;z=t;}printf("从小到大的顺序:%d %d %d\n",x,y,z);return 0;
}
*/
// 12.判断2000-2500年中的每一年是否为闰年,并将结果输出
/*
#include<stdio.h>
int main()
{int i;for(i=2000;i<=2500;i++){if(i%400==0||i%4==0&&i%100!=0){printf("闰年的年份:%d\n",i);continue;}else{continue;//printf("不是闰年的年份:%d\n",i);}}
}
*///13 . 输入一个数是否能被3和5整除
/*
#include<stdio.h>
int main()
{int a;printf("请输入一个数:");scanf("%d",&a);if(a%3==0&&a%5==0){printf("这是能被3和5整除的数:%d",a);}else{printf("不能:%d",a);}
}
*///14 . 求1+2+3+...+100的和
/*
#include<stdio.h>
int main()
{int i,a=0;for(i=1;i<=100;i++){a+=i;}printf("%d",a);
}
*/
//15. 求两个数m和n的最大公约数
/*
#include<stdio.h>
//#include<stdlib.h>
int main(){
#include<stdio.h>
int a,b,r,t;
printf(