=0 &&" />
//1.成绩判断#include <stdio.h>int main(){//成绩int score;printf("请输入你的成绩:\n");scanf("%d", &score);//判断if(score >=0 && score < 60){printf("不及格\n");}else if(60 <= score && score < 80){printf("中等\n");}else if(80 <= score && score < 100){printf("优秀\n");}else{printf("输入错误!\n");}}//2.计算1到100的和#include <stdio.h>int main(){int sum = 0;//存结果变量int i;for(i=1;i <= 100;i++){sum = sum + i;}printf("sum=%d\n", sum);}//3.最大公约数#include <stdio.h>//求m,n的最大公约数int main(){int m, n;int i, k;printf("请输入两个数:");scanf("%d %d", &m, &n);//三元运算符找较小的那个k = m < n ? m : n;//从较小的那个数倒着往前找for(i=k; i>=1; i--){//这是公约数if((m % i == 0) && (n % i ==0)){printf("最大公约数是%d\n", i);break;//跳出for循环}}}//4.最小公倍数#include <stdio.h>//求m,n的最小公倍数int main(){int m, n;int max, min;//m,n中较大,较小的那个int k;//max, 2*max, 3*max, .....printf("请输入两个数:");scanf("%d %d", &m, &n);//也可以交换m,n,保证m小n大max = m > n ? m : n;min = m < n ? m : n;k = max;//从max开始while(k % min != 0){k += max;//每次倍增}printf("最小公倍数是%d\n", k); }//5.金字塔#include <stdio.h>//金字塔int main(){int i;//外层int j;//内层for(i=1;i<=10;i++){//当前是在第i行//先补空格10-i个for(j=1;j<=10-i;j++){printf(" ");}//再打2i-1个*for(j=1;j<=2*i-1;j++){printf("*");}printf("\n");}}//6.九九乘法表#include <stdio.h>//打印九九乘法表int main(){int i,j;for(i=1;i<=9;i++)//外层一定是9行{for(j=1; j<=i; j++)//内层第几行走几遍{printf("%d*%d=%d ", i, j, i*j);}printf("\n");}}//7.百钱买百鸡#include <stdio.h>/**百钱买百鸡,类似1,2,5凑100银币问题*/int main2(){int i,j;//公鸡,母鸡个数for(i=0; i<=20; i++)//公鸡{for(j=0; j<=33; j++)//母鸡{if( (15*i + 9*j + (100-i-j)) == 300){printf("公鸡%d,母鸡%d,小鸡%d\n", i, j, 100-i-j);}}}}//1,2,5凑100银币问题int main3(){int count = 0;//情况数int i,j;//5分个数,2分个数for(i=0; i<=20; i++)//5分个数{for(j=0; j<=50; j++)//2分个数{if( ( 5*i + 2*j ) <= 100 ){count++;printf("%d: 5分%d个,2分%d 个,1分%d个\n", count, i, j, 100-5*i-2*j);}}}}//8.一维数组的最大值、最小值、平均值#include <stdio.h>#define N 10//宏定义常量int main(){int i;//下标索引int max, min;double sum = 0;//累加和int a[N] = {58, 58, 96, 100, 25, 55, 66, 88, 99, 77};max = a[0];//假设第一个最大min = a[0];//假设第一个最小for(i=1; i<N; i++){if(a[i] > max)//比最大值还大max = a[i];//你才是最大if(a[i] < min)//比最小值还小min = a[i];//你才是最小sum += a[i];}printf("max=%d, min=%d\n", max, min);printf("average = %.2lf\n", sum/N);}//9.二维数组的最大值、最小值、平均值#include <stdio.h>int main(){int i; //第几行int j; //第几列int a[3][4] = { {1,2,3,4}, {5,-6,7,8}, {9,19,39,0}};int max = a[0][0];//假设你最大int min = a[0][0];//假设你最小double average;//平均值double sum = 0; //总和for(i=0; i<3; i++)//必定3行{for(j=0; j<4; j++)//必定4列{printf("%5d ", a[i][j]);sum += a[i][j];if(a[i][j] > max)max = a[i][j];if(a[i][j] < min)min = a[i][j];}printf("\n");}average = sum / (3*4);printf("max=%d, min=%d, avg=%.2lf\n", max, min, average);}//10.二维数组转置#include <stdio.h>//二维数组转置:行变列,列变行int main(){int i; //第几行int j; //第几列int a[3][4] = { {1,2,3,4}, {5,-6,7,8}, {9,19,39,0}};int b[4][3];for(i=0; i<3; i++){for(j=0; j<4; j++){printf("%5d", a[i][j]);}printf("\n");}//矩阵转置for(i=0; i<3; i++){for(j=0; j<4; j++){b[j][i] = a[i][j];}}for(i=0; i<4; i++){for(j=0; j<3; j++){printf("%5d", b[i][j]);}printf("\n");}}//11.冒泡排序#include <stdio.h>#define N 10//宏定义常量int main(){int i;//下标索引int j;int tmp;//临时交换用int a[N] = {58, 58, 96, 100, 25, 55, 66, 88, 99, 77};//外层循环一定是N-1for(i=0; i<N-1; i++){//两两交换,大的往后走for(j=0; j<N-i-1; j++){//交换if(a[j] > a[j+1]){tmp = a[j];a[j] = a[j+1];a[j+1] = tmp;}}}for(i=0; i<N; i++){printf("%d ", a[i]);;}printf("\n");}//12.结构冒泡排序#include <stdio.h>//结构定义,用户自定义类型typedef struct student{char sno[20];//学号char name[20];//姓名int age;//年龄char gender;//性别char tel[20];//电话};int main(){int i;int j;double sum = 0;struct student tmp;//两两交换临时用;//结构数组struct student team[5];for(i=0; i<5; i++){printf("请输入第%d个队员的信息:\n", i+1);scanf("%s %s %d %c %s", team[i].sno, team[i].name, &team[i].age, &team[i].gender, team[i].tel);}//按年龄冒泡排序for(i=0; i<5; i++){for(j=0; j<5-i-1; j++){//两两交换if(team[j].age > team[j+1].age){tmp = team[j];team[j] = team[j+1];team[j+1] = tmp;}}}//取值printf("%-12s %-10s %-5s %-5s %-15s\n", "学号", "姓名", "年龄", "性别", "电话");for(i=0; i<5; i++){printf("%-12s %-10s %-5d %-5c %-15s\n", team[i].sno, team[i].name, team[i].age, team[i].gender, team[i].tel);}}//13.结构数组找年龄最大值#include <stdio.h>//结构定义,用户自定义类型typedef struct student{char sno[20];//学号char name[20];//姓名int age;//年龄char gender;//性别char tel[20];//电话};int main(){int i;struct student tmp;//找最大临时用//结构数组struct student team[5];for(i=0; i<5; i++){printf("请输入第%d个队员的信息:\n", i+1);scanf("%s %s %d %c %s", team[i].sno, team[i].name, &team[i].age, &team[i].gender, team[i].tel);}//取值printf("%-12s %-10s %-5s %-5s %-15s\n ", "学号", "姓名", "年龄", "性别", "电话");for(i=0; i<5; i++){printf("%-12s %-10s %-5d %-5c %-15s\ n", team[i].sno, team[i].name, team[i].age, team[i].gender, team[i].tel);}//找学号最大的那一个tmp = team[0];for(i=1; i<5; i++){if(strcmp(team[i].sno,tmp.sno) >0 ){tmp = team[i];}}printf("学号最大的队员如下:\n");printf("%-12s %-10s %-5d %-5c %-15s\ n", tmp.sno, , tmp.age, tmp.gender, tmp.tel);}//14.文件读写#include <stdio.h>#include <stdlib.h>//结构定义,用户自定义类型typedef struct student{char sno[20];//学号char name[20];//姓名int age;//年龄char gender;//性别char tel[20];//电话};//文件读写int main(){struct student * s, * p1;//个数未知FILE * fp;int i, n = 0;char buf[1024];//fgets缓冲区//打开文件fp = fopen("e:\\test.txt", "r");while(fgets(buf, 1024, fp) != NULL)n++;fclose(fp);//指向一个可以存储n个student结构的内存空间s = (struct student *)malloc(sizeof(struct student) * n);p1 = s;//不要动头位置s的值//打开文件fp = fopen("e:\\test.txt", "r");for(i=0; i<n; i++){//从文件中读入一行fscanf(fp, "%s %s %d %c %s", p1->sno, p1->name, &p1->age, &p1->gender, p1->tel);p1++;}fclose(fp);p1 = s;for(i=0; i<3; i++){printf("%s %s %d %c %s\n", p1->sno, p1->name, p1->age, p1->gender, p1->tel);}free(s);}//15.输入三角形三边长计算周长和面积#include<stdio.h>#include<math.h>int main(){double area,perimeter,s,a,b,c;printf("请输入三边长a b c:");scanf("%lf%lf%lf",&a,&b,&c);if((a+b>c) && (a+c>b) && (b+c>a)){s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c));perimeter=a+b+c;printf("area=%.2f,perimeter=%.2f\ n",area,perimeter);}else{printf("三边长无法构成三角形。