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
How can I read/write structures from/to data files?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
can anyone suggest some site name..where i can get some good data structure puzzles???
Why C language is a procedural language?
Tell me when is a void pointer used?
is it possible to create your own header files?
what is the syallabus of computer science students in group- 1?
What is the right type to use for boolean values in c? Is there a standard type?
What are the scope of static variables?
write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...
What is c basic?
What is line in c preprocessor?
What is the difference between volatile and const volatile?
Why does this code crash?
What is data structure in c programming?