Sum of numbers using array

Program:

#include<stdio.h>
int main()
{
int num[10],i,sum=0,n;
printf("Enter no. of elements: "); /* not more than 10 */
scanf("%d",&n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
  scanf("%d",&num[i]);
  sum=sum+num[i];
}
printf("Sum of %d numbers: %d",n,sum);
return 0;

}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...