实验三

1.1 for循环

#include <stdio.h>
int main(){
    int a;
    long int s;
    s=0;
    for(a=22;a<=1002;a+=20){
        s=s+a;
    }
    printf("%d\n",s);
    return 0;
}

1.2 while循环

#include <stdio.h>
int main(){
    int a;
    long int s;
    s=0;
    a=22;
    while(a<=1002){
        s=s+a;
        a=a+20;
    }
    printf("%d\n",s);
    return 0;
}

1.3 do-while循环

#include <stdio.h>
int main(){
    int a;
    long int s;
    s=0;
    a=22;
    do{
        s=s+a;
        a=a+20;
    }while(a<=1002);
    printf("%d\n",s);
    return 0;
}

2.

#include <stdio.h>
int main(){
    int a,i,j,k,n;
    n=0;
    for(a=100;a<=999;a++){
        i=a/100;
        j=(a-i*100)/10;
        k=a%10;
        if(a==i*i*i+j*j*j+k*k*k){
            printf("%d\n",a);
            n=n+1;
        }
    }printf("水仙花数共:%d\n",n);
    return 0;
}

3.

#include <stdio.h>
int main(){
    int i,j,k,n;
    n=0;
    for(i=1;i<=5;i++){
        for(j=1;j<=5;j++){
            if(i==j){
                continue;
            }for(k=1;k<=5;k++){
                 if(i==k||j==k){
                     continue;
                 }printf("%d\n",i*100+j*10+k);
                 n++;
            }
        }
    }
    printf("n:%d\n",n);
    return 0;
}

posted @ 2019-05-06 14:34  婷啊婷阿扎  阅读(145)  评论(0编辑  收藏  举报