Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Program to illustrate one-dimensional array

Posted By: Rad Fischer     Category: C Programming     Views: 3241

Program to illustrate one-dimensional array

Code for Program to illustrate one-dimensional array in C Programming

main()                                                      
   {                                                           
       int    i ;                                              
       float  x[10], value, total ;                            
                                                               
 /* . . . . . .READING VALUES INTO ARRAY . . . . . . */
printf("ENTER 10 REAL NUMBERS\n") ; for( i = 0 ; i < 10 ; i++ ) { scanf("%f", &value) ; x[i] = value ; } /* . . . . . . .COMPUTATION OF TOTAL . . . . . . .*/
total = 0.0 ; for( i = 0 ; i < 10 ; i++ ) total = total + x[i] * x[i] ; /*. . . . PRINTING OF x[i] VALUES AND TOTAL . . . */
printf("\n"); for( i = 0 ; i < 10 ; i++ ) printf("x[%2d] = %5.2f\n", i+1, x[i]) ; printf("\ntotal = %.2f\n", total) ; } Output ENTER 10 REAL NUMBERS 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 x[ 1] = 1.10 x[ 2] = 2.20 x[ 3] = 3.30 x[ 4] = 4.40 x[ 5] = 5.50 x[ 6] = 6.60 x[ 7] = 7.70 x[ 8] = 8.80 x[ 9] = 9.90 x[10] = 10.10 Total = 446.86
  
Share: 


Didn't find what you were looking for? Find more on Program to illustrate one-dimensional array Or get search suggestion and latest updates.

Rad Fischer
Rad Fischer author of Program to illustrate one-dimensional array is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!