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
Why doesnt the call scanf work?
Is printf a keyword?
What is #error and use of it?
Differentiate between a for loop and a while loop? What are it uses?
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
Are pointers really faster than arrays?
What is fflush() function?
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
What are conditional operators in C?
What are the advantages of c preprocessor?
What is a substring in c?
Explain do array subscripts always start with zero?
What do you understand by normalization of pointers?