c作业4(实验三)

1.计算s=22+42+62........+1002

#include <stdio.h>

int main()

{

         long int s=0;

         int i;

         for (i=22;i<=1002;)

         {

                   s=s+i;

                   i+=20;

         }

         printf("s=%ld\n",s);

         return 0;

}

                       

 

 

#include <stdio.h>

int main()

{

         long int s=0;

         int i=22;

         do

         {

                   s=s+i;

                   i+=20;

         }

         while (i<=1002);

         printf("s=%ld\n",s);

         return 0;

}

 

 

#include <stdio.h>

int main()

{

         long int s=0;

         int i=22;

         while (i<=1002)

         {

                   s=s+i;

                   i+=20;

         }

         printf("s=%ld\n",s);

         return 0;

}

 

 

 

 

 


2.输出水仙花数

#include <stdio.h>

int main()

{

int i,j,a,b,c;

for (j=0,i=100;i<1000;i++)

{

         a=i/100;

         b=i/10-a*10;

         c=i%10;

         if (a*a*a+b*b*b+c*c*c==i)

         {

                   printf("%d\n",i);

                   j++;

         }

}

printf("The narcissistic number have %d\n",j);

return 0;

}

 

 

 

 

 

 

 

 

 

 3.排列组合

#include <stdio.h>

int main()

{

int i,j,k;

int m=0;

for (i=1;i<6;i++)

{

         for (j=1;j<6;j++)

         {

                   if (i!=j)

                   {

                            for (k=1;k<6;k++)

                            {

                                     if (i!=k&&j!=k)

                                     {

                                               printf("%5d",i*100+j*10+k);

                                               m++;

                                     }

                            }

                   }

         }

}

printf("\n%d\n",m);

return 0;

}

posted @ 2019-05-06 14:28  兰布尔  阅读(159)  评论(0编辑  收藏  举报