作业4

#include<stdio.h>
int main()
{
    int i=1,sum=0;
    do{
        if(i%2==1)
        sum=sum-1/i;
        else
        sum=sum+1/i;
        i++;
    }while(i<=100);
    printf("sum=%d\n",sum);
    return 0;
}
#include<stdio.h>
int main()
{
    double sum;
    int i;
    for(sum=0,i=1;i<=100;i++){
        if(i%2==1){
            sum=1/i;
        }
        else if(i%2==0){
            sum=1/i;
    }
    }
    printf("sum=%d",sum);
    return 0;
} 
#include<stdio.h>
int main()
{
    int i,sum;
    i=1;
    sum=0;
    while(i<=100){
        if(i%2==1)
        sum=sum-1/i;
        else
        sum=sum+1/i;
        i++;
    }printf("sum=%d\n",sum);
    return 0;
}
#include<stdio.h>
int main()
{
    double sum1=1,sum2=0,i;
    while(i<10){        
        i++;
        sum1=sum1*i;
        printf("%.0lf!=%.0lf\n",i,sum1);        
        sum2=sum2+sum1;
    }
    printf("1!+2!+...+10!=%.0lf",sum2);
    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("\n");
    return 0;
}
#include<stdio.h>
int main()
{
    int a=2;
    int b=1;
    int N=0;
    float Y=0;
    printf("input n£º");
    scanf("%d",&N);
    while(a<=N)
    {
    Y=Y+a/b;
    b=a;
    a=a+b;
    }
    printf("sum=%.2f\n",N,Y);
    return 0;    
}
#include<stdio.h>
int main()
{
    double sum=0,a,n,i=1,b;
    printf("Input a,n:");
    scanf("%lf%lf",&a,&n);
    b=a;
    while(i<=n){
        i++;        
        sum=sum+a;                
        a=10*a+b;    
    }
    printf("sum=%lf",sum);
    return 0;
}

 

posted @ 2016-12-23 20:25  Leonardo#*  阅读(109)  评论(0编辑  收藏  举报