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

Do you know pointer in c?

0 Answers  


why programs in c are running with out #include<stdio.h>? some warnings are display in terminal but we execute the program we get answer why? eg: main() { printf("hello world "); }

0 Answers  


What is the purpose of void in c?

0 Answers  


what are the different storage classes in c?

0 Answers   TCS,


What are the advantages of c preprocessor?

0 Answers  






without using arithmatic operator convert an intger variable x into x+1

3 Answers  


Explain the differences between public, protected, private and internal.

2 Answers  


What will be the outcome of the following conditional statement if the value of variable s is 10?

0 Answers  


is forign key will be unique key any table or not?

2 Answers  


Is it better to use a macro or a function?

0 Answers  


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

0 Answers   Wipro,


Write a C program to perform some of the operation which can be performed using Single linked list

1 Answers   Qualcomm,


Categories