Ad Code

NEW POST

6/recent/ticker-posts

write a program in C to display n terms of number and their sum,:)

...

 Concept: 

Here we use array to execute the program first I declare the array of size 100. You can set limit of your choice 

Now first line of program prints to enter the limits (means that how many we want to enter the number),

Second line prints to enter the numbers, and by the use of scanf we take input upto entered limits. We use FOR loop to enter the number the loop will run upto limits entered in first line.

And we have declare add=0, in this we can add the entered numbers using loop.

Below is the code:


//write a program in C to display n terms of number and their sum,:)
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,add=0,n;
clrscr();
printf("enter limits to enter numbers\n");
scanf("%d",&n);
printf("enter %d numbers\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
add=add+a[i];
}
printf("sum of entered number are : %d.\n",add);
getch();
}

Post a Comment

0 Comments