#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
int i,n;
float a[50],sum=0;
clrscr();
printf("enter No. of elements in the array);
scanf("%d",%26amp;n);
for(i=0;i%26lt;n;i++)
scanf("%f",%26amp;a[i]);
for(i=0;i%26lt;n;i++)
sum=sum+a[i];
printf("Sum of no.s in the array is %f",sum);
getch();
}
Can anyone tell me a how get summing of the elements of array in C programming?
a loop
sum = 0;
for( i = 0; i %26lt; "size of array"; i++) sum += array[i];
Reply:How about a for loop?
sum = 0;
for( i = 0; i %26lt; 100; i++) sum += array[i];
Reply:if you want to add all elements of an array than u wud hav to take an array and using for loop enter the elements. after that processing each element u wud hav to add that.
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
int arr[12],i,sum=0;
printf("Enter the elements\n");
for(i=0;i%26lt;12;i++)
{
scanf("%d",%26amp;arr[i]);
sum=sum+arr[i];
}
for(i=0;i%26lt;12;i++)
printf("%d",arr[i]);
}
sd cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment