• 第四次作业


    1.1

    #include <stdio.h>
    int main(){
        int i,sum=0;
        i = 1;
        while(i <= 100)
        {
            sum += i;
            i++;
        }
        printf("sum = %d
    ",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
    ",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
    ",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
    ",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
    ",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
    ",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
    ",sum+sum1+sum2);
        return 0;
    }

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

     

    #include<stdio.h>
    int main(){
        int a,b,m,n;
        printf("请输入正整数m和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
    ",a);
        printf("最小公倍数为:%d
    ",m*n/a);
    }

  • 相关阅读:
    Java中一对多映射关系(转)
    java映射一对一关系 (转)
    如何创建JUnit
    Java数组转置
    get与post方法(吴老师整理)
    后台获得数据
    JDK1.8的安装与卸载
    使用JSP输出九九乘法表
    foreach
    匿名内部类
  • 原文地址:https://www.cnblogs.com/ws562304130/p/5955784.html
Copyright © 2020-2023  润新知