实验四

1.

#include<stdio.h>

int main()

{

    int arr[10];

         int i,j,k;

         for(i=0;i<10;i++)

         {

             scanf("%d ",arr[i]);

         }

         for (i=0;i<9;i++)

         {

                   for(j=0;j<9-i;j++)

                   {

                       if (arr[j]>=arr[j+1])

                            {

                                k=arr[j];

                                     arr[j]=arr[j+1];

                                     arr[j+1]=k;

                            }

                   }

         }

         for (i=0;i<10;i++)

         {

                   printf("%d\n",arr[i]);

         }

    return 0;

}

 

                       

2.

#include <stdio.h>

int main()

{

int arr[3][3];

int i,j,sum;

for (i=0;i<3;i++)

{

    for (j=0;j<3;j++)

         {

         scanf("%d",arr[i][j]);

         }

}

sum=0;

for (i=0;i<3;i++)

{

sum=arr[i][i]+arr[i][2-i]+sum;

}

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

return 0;

}

3.

#include<stdio.h>

int main()

{

   char s[10000];

   int i,j,n;

   j=0;

   i=0;

   scanf("%c",&s[i]);

   while (s[i]!='\n')

   {

       if (s[i]==' ')

            {

            j++;

            }

            i++;

       scanf("%c",&s[i]);

   }

   printf("%d\n",j+1);

   return 0;

}

 

 

4.

#include<stdio.h>

#include<math.h>

int main()

{

         int arr[100]={0};

         int i,j,n;

         n=sqrt(100);

         for (i=2;i<=n;i++)

         {

             for (j=2;j<=100;j++)

                   {

                       if (j%i==0)

                                     arr[j-1]=1;

                   }

         }

    arr[1]=0;

         arr[0]=1;

         arr[2]=0;

         arr[4]=0;

         arr[6]=0;

         for (i=0;i<100;i++)

         {

         if (arr[i]==0)

                   printf("%d ",i+1);

         }

   return 0;

}

posted @ 2019-05-20 14:59  兰布尔  阅读(194)  评论(0编辑  收藏  举报