PROCEDURE:-
CODE:-
#include<stdio.h>
void main()
{
int n,x,i=1;sum=0;
printf(“enter value for n”);
scanf(“%d”,&n);
printf(“enter %d different values”,n);
while(i<=n)
{
scanf(“%d”,&x);
sum=sum+x;
i++;
}
printf(“sum of %d numbers is %d”, n, sum);
}
Input:- enter value for n 4
enter 4 different values 20 20 20 20
Output:- sum of 4 numbers is 80
- input an integer value n and set sum to 0
- repeat step 3 until all the n different values are read
- read an integer add this to previous sum
- print the sum
CODE:-
#include<stdio.h>
void main()
{
int n,x,i=1;sum=0;
printf(“enter value for n”);
scanf(“%d”,&n);
printf(“enter %d different values”,n);
while(i<=n)
{
scanf(“%d”,&x);
sum=sum+x;
i++;
}
printf(“sum of %d numbers is %d”, n, sum);
}
Input:- enter value for n 4
enter 4 different values 20 20 20 20
Output:- sum of 4 numbers is 80
Comments
Post a Comment