Ming solution C language portal, Chapter 5 answers

 

Exercise 5-1

/ * 
    For sequentially 1,2,3,4,5 assigned to each element of the array and the display (for statement) 
* / 

#include <stdio.h> int main ( void ) 
{ int I;
     int V [ . 5 ] ;     / * int [. 5] array * / for (I = 0 ; I < . 5 ; I ++)         / * array element assignment * / 
        V [I] = I; for (I = 0 ; I < . 5 ; I ++)         / * display the value of the element * / 
        the printf ( " V [D%] D =% \ n- " , I, V [I]);


    

    

    

    return 0;
}

Exercise 5-2 

/ * 
    For sequentially 1,2,3,4,5 assigned to each element of the array and the display (for statement) 
* / 

#include <stdio.h> int main ( void ) 
{ int I;
     int V [ . 5 ] ;     / * int [. 5] array * / for (I = 0 ; I < . 5 ; I ++)         / * array element assignment * / 
        V [I] = I + . 1 ; for (I = . 4 ; I> = 0 ; i--)         / * display the value of the element * / 
        the printf ( " V [D%] D =% \ n- "


    

    

    , I, v [i]) ; 

    return  0 ; 
}

Exercise 5-3

/ * 
    From the beginning with 1,2,3,4,5 sequentially initializes each element of an array and show 
* / 

#include <stdio.h> int main ( void ) 
{ int I;
     int V [ . 5 ] = { . 5 , 4 , 3 , 2 , 1 };         / * initialization * / for (I = 0 ; I < . 5 ; I ++)             / * display the value of the element * / 
        the printf ( " V [% D] =% D \ n- " , I , V [I]); return 0 ; 
}


    

    

     

Exercise 5-4

/ * 
    Copy of all elements in the array to another array 
* / 

#include <stdio.h> int main ( void ) 
{ int I;
     int A [ . 5 ] = { . 17 , 23 is , 36 };     / * use { 17,23,36,0,0} initialize * / int B [ . 5 ]; for (I = 0 ; I < . 5 ; I ++ ) { 
        B [ . 4 - I] = A [I]; 
    } 
    the puts ( "   ab & " ); 
    the puts ( "


    
    

    

---------");
    for (i = 0; i < 5; i++)
        printf("%4d%4d\n", a[i], b[i]);

    return 0;
}

Exercise 5-5

/ * 
    For all elements of the array will be reverse order 
* / 

#include <stdio.h>
 #define Number. 7 int main ( void ) 
{ int I;
     int X [Number];                     / * int [Number] array * / for (I = 0 ; I <Number; I ++) {     / * input element value * / 
        the printf ( " X [% D]: " , I); 
        Scanf ( " % D " , & X [I]); 
    } for (I = 0 ; I < . 3 ; I ++) {    


    

    
    
    / * Array elements in reverse order * / 
        int TEMP = X [I]; 
        X [I] = X [ . 6 - I]; 
        X [ . 6 - I] = TEMP; 
    } 

    the puts ( " reverse order of. " );
     for (I = 0 ; I <Number; I ++)         / * display the value of the element * / 
        the printf ( " X [D%] D =% \ n- " , I, X [I]); 

    return  0 ; 
}

 

Exercise 5-6

It will become 1

Exercise 5-7

#include <stdio.h>

#define number    80    

int main(void)
{
    int v[number];
    int num;
    int i;
    printf("数据个数:");
    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        printf("%d号:",i+1);
        scanf("%d", &v[i]);
    }
    printf("{");
    for (i = 0; i < num-1; i++) {
        
        
        printf("%d, ", v[i]);
    }
    printf("%d", v[num-1]);
    printf("}");
    


    return 0;
}

 

Exercise 5-8

1  / * 
2      student input and shows the distribution of scores
 . 3  * / 
. 4  
. 5 #include <stdio.h>
 . 6  
. 7  #define NUMBER 80 / * Maximum number of * /
 . 8  
. 9  int main ( void )
 10  {
 . 11      int I, J;
 12 is      int NUM;                 / * actual number of * / 
13 is      int tensu [nUMBER];         / * student score * / 
14      int bunpu [ . 11 ] = { 0 };     / * map * / 
15 
16      printf ( " Please enter the number of students: " );
 17      scanf ( " % d " , & NUM);
 18          
19      printf ( " Please enter% d people score \ the n-. " , NUM);
 20  
21      for (i = 0 ; I <NUM; I ++ ) {
 22 is          the printf ( " No% 2D: " , I + . 1 );
 23 is          Scanf ( " % D " , & tensu [I]);
 24          bunpu [tensu [I] / 10 ] + + ;
 25     }
 26 is  
27      the puts ( " \ n-profile --- --- " );
 28      
29  
30      
31 is  
32      for (I = 0 ; I <= . 9 ; I ++) {                 / * less than 100 * / 
33 is          the printf ( " 3D% -% 3D: " , * I 10 , I * 10 + . 9 );
 34 is          for (J = 0 ; J <bunpu [I]; J ++ )
 35              the putchar ( ' * ' );
 36          the putchar ('\n');
37     }
38     printf("      100:");
39     for (j = 0; j < bunpu[10]; j++)            /* 100分 */
40         putchar('*');
41     putchar('\n');
42     
43 
44     return 0;
45 }

Exercise 5-9

Guess you like

Origin www.cnblogs.com/nightswatch-candle/p/11819416.html