codescracker


c

C Program to Add n Numbers



« Previous Program Next Program »


Add n Numbers in C

To add n numbers in C programming, you have to ask to the user to enter the value of n, then ask to enter n numbers to perform addition of all the entered n numbers to display the addition result on the screen

C Programming Code to Add n Numbers

Following C program first ask to the user to enter the value of n and then ask to enter n Number to add them. So this C program add n Number entered by the user:

/* C Program - Add n Numbers */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int i, n, sum=0, num;
	printf("How many number you want to enter and add them ?");
	scanf("%d",&n);
	printf("Enter %d number :",n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num);
		sum=sum+num;
	}
	printf("Sum of all the %d number is %d",n,sum);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program to add n numbers

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test