Thursday, 11 September 2014

Sum of N numbers using Array in C Language Program With Example


C program  for Sum of N numbers using Array technique. This simple C source code is coming under the part of C beginners guide. This sample code can be used for an Engineering, Diploma and all kind of Degree students and professionals.

Sum of 10 numbers using Array
Sum of N numbers using Array in C program is used to calculate the value of array 10 numbers and it will display a sum value by using a looping statement (for loop). Basic formula is (sum=sum+a[i]).


WRITE A C PROGRAM:

//Header files
include <stdio.h>
include <conio.h>
 
void main()
{
//Program variable
int b[10],s,j,su=0;
 
clrscr(); //Function is used to clear previous output
for (j=1;j<=10;j++) //Looping statement
{
printf("ENTER THE NUMBER::---"); //Display function
scanf("%d",&b[j]);//Getting input function
}
for(j=1;j<=10;j++)
b[j]=b[j]*b[j];
for(j=1;j<=10;j++)
printf("\nthe numbers are %d",b[j]);
for(j=1;j<=10;j++)
su=su+b[j];
printf("\n THE SUM OF 10 NUMBERS ARE %d",su);
getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.