zoukankan      html  css  js  c++  java
  • 第四章

    #include<stdio.h>
    #include<math.h>
    int main(void)
    {
        int denominator,flag;
        double item,pi;
        flag=1;
        denominator=1;
        item=1.0;
        pi=0;
    
        while(fabs(item)>=0.0001){
            item=flag*1.0/denominator;
            pi=pi+item;
            flag=-flag;
            denominator=denominator+2;
        }
        pi=pi*4;
        printf("pi=%.4f
    ",pi);
    
        return 0;
    
    }

    #include<stdio.h>
    int main(void)
    {
        int count,num;
        double grade,total;
    
        num=0;
        total=0;
        count=0;
        printf("Enter grade:");
        scanf("%lf",&grade);
    
        while(grade>=0){
            total=total+grade;
            num++;
            if(grade<60)
                count++;
            scanf("%lf",&grade);
        }
        if(num!=0){
            printf("Grade average is %.2f
    ",total/num);
            printf("Number of fauilure is %d
    ",count);
        }
        else
            printf("Grade average is 0
    ");
    
        return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int count,number;
    
        count=0;
        printf("Enter a number:");
        scanf("%d",&number);
        if(number<0)number=-number;
        do{
            number=number/10;
            count++;
        }while(number!=0);
        printf("It contains%d digits.
    ",count);
    
        return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,m;
    
        printf("Enter a number:");
        scanf("%d",&m);
        for(i=2;i<=m/2;i++)
            if(m%i==0)
                break;
            if(i>m/2&&m!=1)
                printf("%d is a prime number!
    ",m);
            else
                printf("No!
    ");
    
            return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int mynumber=38;
        int count=0,yournumber;
        for(count=1;count<=5;count++){
            printf("Input your number:");
            scanf("%d",&yournumber);
            if(yournumber==mynumber){
                printf("Ok!you are right!
    ");
                break;
            }
            else
                if(yournumber>mynumber)
                    printf("Sorry!your number is bigger than my number!
    ");
                if(yournumber<mynumber)
                    printf("Sorry!your number is smaller than my number!
    ");
        }
        printf("Game is over!
    ");
        
        return 0;
    }

    #include<stdio.h>
    double fact(int n);
    int main(void)
    {
        int i;
        double sum;
        sum=0;
        for(i=1;i<=100;i++)
            sum=sum+fact(i);
        printf("1!2!+...+100!=%e
    ",sum);
    
        return 0;
    }
    double fact(int n)
    {
        int i;
        double result;
         result=1;
         for(i=1;i<=n;i++)
             result=result*i;
    
         return result;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,j;
        double item,sum;
    
        sum=0;
        for(i=1;i<=100;i++){
            item=1;
            for(j=1;j<=i;j++)
                item=item*j;
            sum=sum+item;
        }
        printf("1!+2!+...+100!=%e
    ",sum);
    
        return 0;
    }

     

    #include<stdio.h>
    int main(void)
    {
        int i,mark,max,n;
    
        printf("Enter n:");
            scanf("%d",&n);
        printf("Enter %d marks:",n);
        scanf("%d",&mark);
        max=mark;
        for(i=1;i<n;i++){
            scanf("%d",&mark);
            if(max<mark)
                max=mark;
        }
        printf("Max=%d
    ",max);
        return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int mark,max;
        printf("Enter marks:");
        scanf("%d",&mark);
        max=mark;
        while(mark>=0){
            if(max<mark)
                max=mark;
            scanf("%d",&mark);
        };
        printf("Max=%d
    ",max);
        return 0;
    }

     

    #include<stdio.h>
    int main(void)
    {
        int x;
        printf("Enter x:");
        scanf("%d",&x);
        while(x!=0){
            printf("%d ",x%10);
            x=x/10;
        }
            return 0;
        }
    #include<stdio.h>
    #include<math.h>
    int main(void)
    {
        int count,i,m,n;
    
        count=0;
        for(m=2;m<=100;m++){
            n=sqrt(m);
            for(i=2;i<=n;i++)
                if(m%i==0)
                    break;
                if(i>n){
                    printf("%6d",m);
                    count++;
                    if(count%10==0)
                        printf("
    ");
                }
        }
        printf("
    ");
        return 0;
    }

     

    
    
    #include<stdio.h>
    int main(void)
    {
        int i,x1,x2,x;
        x1=1;
        x2=1;
        printf("%6d%6d",x1,x2);
        for(i=1;i<=8;i++){
            x=x1+x2;
            printf("%6d",x);
            x1=x2;
            x2=x;
        }
        printf("
    ");
        return 0;
    }
    
    

    #include<stdio.h>
    int main(void)
    {
        int child,men,women;
    
        for(men=0;men<=45;men++)
            for(women=0;women<=45;women++)
                for(child=0;child<=45;child++)
                    if(men+women+child==45&&men*3+women*2+child*0.5==45)
                        printf("men=%d,women=%d,child=%d
    ",men,women,child);
                    return 0;
    }

     

    #include<stdio.h>
    int main(void)
    {
        int child,women,men;
    
        for(men=0;men<=15;men++)
            for(women=0;women<=22;women++){
                child=45-women-men;
                if(men*3+women*2+child*0.5==45)
                    printf("men=%d,women=%d,child=%d
    ",men,women,child);
            }
            return 0;
    }

     

  • 相关阅读:
    EF中,保存实体报错:Validation failed for one or more entities. 如何知道具体错误在哪?
    个人常用的移动端浅灰底index.html
    分享一段js,判断是否在iPhone中的Safari浏览器打开的页面
    2017年3月25日,祝自己23岁生日快乐!
    JavaScript监控页面input输入整数且只能输入2位小数
    iPhone IOS10安装APP没提示连接网络(无法联网)的解决办法
    iPhone屏蔽IOS更新、iPhone系统更新的提示(免越狱,有效期更新至2021年)
    iPhone Anywehre虚拟定位提示“后台服务未启动,请重新安装应用后使用”的解决方法
    C# OracleDBhelper
    戴尔灵越15-5000/3558等系列修改BIOS设置U盘启动
  • 原文地址:https://www.cnblogs.com/liyang1995/p/3355519.html
Copyright © 2011-2022 走看看