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
What does p mean in physics?
hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
What is difference between far and near pointers?
What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.
What is the purpose of type declarations?
Here is a neat trick for checking whether two strings are equal
What is keyword in c?
Which is better oop or procedural?
Why does everyone say not to use gets?
Why is void main used?
Explain output of printf("Hello World"-'A'+'B'); ?
What is the purpose of the statement: strcat (S2, S1)?
What is a nested formula?
What is New modifiers?