首页 > 代码库 > 作业4

作业4

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

技术分享

#include <stdio.h>int main(){    int i,n,jiec=1;    printf("请输入一个整数n:");    scanf("%d",&n);    i = n;    while(i>=1){        jiec=jiec*i;        i--;    }    printf("%d!=%d\n",n,jiec);    return 0;}
#include <stdio.h>int main(){    int i,n,jiec=1;    printf("请输入一个整数n:");    scanf("%d",&n);    i=n;    do{        jiec=jiec*i;        i--;    }while(i>=1);    printf("%d!=%d\n",n,jiec);    return 0;}
#include <stdio.h>int main(){    int i,n,jiec=1;    printf("请输入一个整数n:");    scanf("%d",&n);    jiec=1;    for(i=1;i<=n;i++){        jiec=jiec*i;    }    printf("%d!=%d\n",n,jiec);    return 0;}

技术分享

#include <stdio.h>int main(){    int k,sum=0,i,a=1,b=0;    float c,d=0,e=0;    for(k=1;k<=100;k++)        sum+=k;    for(i=1;i<=50;i++)      a=i*i;      b=b+a;    for(c=1;c<=10;c++)        d=d+1/c;        e=sum+c+d;    printf("所求和为;%f\n",e);    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++;        else if(c== )            kg++;        else            qt++;    }    printf("字母个数:%d\n",zm);    printf("空格个数:%d\n",kg);    printf("其他个数:%d\n",qt);    return 0;}

技术分享

#include <stdio.h>int main(){    int m,n,t,i,gys=1,gbs;     printf("请输入两个整数:");    scanf("%d%d",&m,&n);    if(n>m){        t=m;        m=n;        n=t;    }    for(i=n;i>=1;i--)        if(m%i==0&&n%i==0)            break;        printf("m=%d,n=%d",m,n);    if(i!=0){        gys=i;        printf("最大公约数为:%d\n",gys);    }    gbs = m*n/gys;    printf("最小公倍数为:%d\n",gbs);    return 0;} 

技术分享

#include<stdio.h>int main(){    int n,k1,k2,k3;    for(k1=0;k1<=9;k1++)    for(k2=0;k2<=9;k2++)    for(k3=1;k3<=9;k3++){    if(k3*100+k2*10+k1==k1*k1*k1+k2*k2*k2+k3*k3*k3)      printf("%d\n",k3*100+k2*10+k1);    }    return 0;}

技术分享

作业4