73 : C Program to add 10 numbers using array

Check out the complete list of c-programs : C Program List    





We have already seen how to add number, but this time we do it using a array. arr[10] holds 10 integer values inputted by user and we later add them and display the sum.

Logic :
//Reading 10 numbers from console and saving them in array
 for(i = 0; i<10;i++) {
     
      printf("Enter no. %d   : \n",i+1);
      scanf("%d",&arr[i]);
      
    
     
 }
 
 //looping the array to calculate the sum.
 for(i = 0; i<10;i++) {
     
       sum = sum + arr[i];

}









/*
 * 1000+ C programs + tutorials
 *
 * 
 * 73_c_program_to_add_10_numbers_using_array.c
 *  
 *  
 *
 *  Created on: Oct 25, 2014
 *  Author: Code2care.org
 */

#include 
//#include 

void main() {


//clrscr();

int arr[10];
int i;
int sum=0;
 

printf("\nC Program to add 10 numbers using arrays : \n\n");
 
 for(i = 0; i<10;i++) {
     
      printf("Enter no. %d   : \n",i+1);
      scanf("%d",&arr[i]);
      
    
     
 }
 
 for(i = 0; i<10;i++) {
     
       sum = sum + arr[i];

}
 printf("Sum : %d",sum);
 
//getch();  
   
}









The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.