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.

Answers were Sorted based on User's Feedback



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

Answer / devi

#include<stdio.h>
#include<conio.h>
void main()
{
int a[200],i,n;
float sum=0,avg;
clrscr();
printf("Enter the n values");
scanf("%d",&n);
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
avg=sum/n;
printf("Sum of %d array values is:%f",n,avg);
getch();
}

Is This Answer Correct ?    7 Yes 5 No

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

Answer / 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

More C Interview Questions

What is the difference between null pointer and wild pointer?

0 Answers  


Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.

0 Answers  


name the language for writing c compiler?

3 Answers   Microsoft,


What kind of structure is a house?

0 Answers  


What is sorting in c plus plus?

0 Answers  






write a method for an array in which it can display the largest n next largest value.

1 Answers   Value Labs,


How can I find leaf node with smallest level in a binary tree?

1 Answers  


What is structure padding and packing in c?

0 Answers  


how many header file is in C language ?

44 Answers   College School Exams Tests, CTS, IBM, IMS, Infosys, ME, Sign Solutions, Wipro, XVT,


Describe the modifier in c?

0 Answers  


What are multibyte characters?

0 Answers  


How does pointer work in c?

0 Answers  


Categories