首页 > 代码库 > 第四次作业

第四次作业

1.1

#include <stdio.h>int main(){    int i,sum=0;    i = 1;    while(i <= 100)    {        sum += i;        i++;    }    printf("sum = %d\n",sum);    return 0;}

1.2

#include <stdio.h>int main(){    int i,sum = 0;    i = 1;    sum = 0;    do{        sum+=i;        i++;    }while(i <= 100);    printf("sum = %d\n",sum);    return 0;

1.3

#include <stdio.h>int main(){    int i,sum=0;    sum=0;    for(i = 1;i <= 100;i++)        sum += i;    printf("sum = %d\n",sum);    return 0;}

 

2.1

#include <stdio.h>int main(){    int i,sum = 1,n;    i=1;    printf("请输入n的值:");    scanf("%d",&n);    while(i <= n)    {        sum = sum*i;        i++;    }    printf("sum = %d\n",sum);    return 0;}

2.2

#include <stdio.h>int main(){    int i,sum = 1,n;    i=1;    printf("请输入n的值:");    scanf("%d",&n);    do{        sum = sum*i;        i++;    }while(i <= n);    printf("sum = %d\n",sum);    return 0;}

2.3

#include <stdio.h>int main(){    int i,sum = 1,n;    printf("请输入n的值:");    scanf("%d",&n);    for(i = 1;i <= n;i++)    sum=sum*i;    printf("sum = %d\n",sum);    return 0;}

 

#include <stdio.h>#include <math.h>int main(){    long int k,sum=1,sum1,sum2;    do{        sum+=k;        k++;    }while(k <= 100);    for(k = 1;k< = 50;k++)        sum1=k*k;    for(k =1/k;      printf("总数为:%d\n",sum+sum1+sum2);    return 0;}

 

#include <stdio.h>int main(){    char c;    int zm = 0,sz = 0,kg = 0,qt = 0;    while((c=getchar())!=\n){        if((c>=a && c<=z) ||(c>=A && c<=Z))            zm++;        if(c== )            kg++;        if(c>=0 &&c<=9)            sz++;        else            qt++;    }    printf("字母个数:%d\n",zm);    printf("空格个数:%d\n",kg);    printf("数字个数:%d\n",sz);    printf("其他字符个数:%d\n",qt);}

 

#include<stdio.h>int main(){    int a,b,m,n;    printf("请输入正整数m和n:\n");    scanf("%d%d",&a,&b);    m=a;    n=b;    while(a!=b)        if(a>b)            a=a-b;        else            b=b-a;    printf("最大公约数为:%d\n",a);    printf("最小公倍数为:%d\n",m*n/a);}

 

 

PS教室电脑没法运行程序只能编写代码,回去用自己电脑发布运行图。

 

第四次作业