实验四

一:

#include <stdio.h>

void bubble(int arr[], int L, int R){

       int i;

       if (L == R){

             

       }else{

              for(i = 0;i <=R-1; i++){

                     if(arr[i] > arr[i+1]){

                            int temp = arr[i];

                            arr[i] = arr[i+1];

                            arr[i+1] = temp;

                     }

              }

              bubble(arr,L,R-1);

       }

 

}

int main(int argc, char const *argv[])

{

       int arr[10];

       int i,z;

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

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

       }

       bubble(arr, 0, 9);

       for(z = 0; z < 10 ; z++){

              printf("%d ", arr[z]);

       }

 

       return 0;

}

 

 二:

#include <stdio.h>

 

int main(){

       int arr[3][3];

       int m, n;

       int a;

       for(m = 0; m < 3; m++){

              for(n = 0; n < 3; n++){

                     scanf("%d", &arr[m][n]);

              }

       }

       a = arr[0][0] + arr[1][1] + arr[2][2] + arr[0][2] + arr[1][1] + arr[2][0];

       printf("%d", a);

 

       return 0;

}

三:

#include <stdio.h>

 

int main(){

       char string[10000];

       int i,n;

       gets(string);

       for(i = 0, n = 0; ;i++){

              if(string[i] == ' '){

                     n++;

              }else if(string[i] == '\0'){

                     break;

              }else{

                     continue;

              }

       }

 

      

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

 

       return 0;

 

 

 

 

}

四:

#include<stdio.h>

void main(){

       int i,j;

       for(i=2;i<=100;i++){

              int t=1;

              for(j=2;j<i;j++){

                     if(i%j==0){

                            t=0;break;

                     }

              }if(t==1)

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

              }

       }

 

posted on 2019-05-20 14:40  p201821440017  阅读(116)  评论(0编辑  收藏  举报

导航