Write a program which calculate sum of several number and input it into an array. Then, the sum of all the number in the array is calculated.

Answer Posted / pradeepnair

#include<stdio.h>
#include<conio.h>

void main()
{
int val1;
int val2;
int size=0;
int a,b[100];
int i,n,j,k=1;
int sum=0;
int sum1=0;
printf("enter the no of values to be added");
scanf("%d",&val1);
for(i=0;i<val1;i++)
{
scanf("%d",&a);
sum=sum+a;
}
System.out.println("the sum is"+sum);
while(sum>0)
{
val2 = sum%10;
sum=sum/10;
b[k]=val2;
size=size+1;
k--;
}
printf("the values in array are");
for(i=0;i<size;i++)
{
printf("/n",b[i]);

}

for(j=0;j<size;j++)
{
sum1=sum1+b[j];
}
printf("the sum of values an array is $d",sum1)

getch();
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a variable be both constant and volatile?

572


How can I direct output to the printer?

831


regarding pointers concept

1585


Write a program to compute the similarity between two strings - The program should get the two strings as input - Then it will output one single number which is the percentage of similarity between the two strings

2257


What is a spanning Tree?

973






What is a pointer in c?

694


Add Two Numbers Without Using the Addition Operator

361


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

611


what is different between auto and local static? why should we use local static?

651


What is character constants?

720


What is bubble sort technique in c?

600


What is a global variable in c?

600


write a c program to print the next of a particular no without using the arithmetic operator or looping statements?

3201


What is the use of pointers in C?

631


Why pointers are used?

639