Array summation - Sum of all elements in array


#include <stdio.h>
#include <conio.h>
#include <malloc.h>
void main()
{
 int i,n,sum=0;
 int *a;
 clrscr();
 printf("Enter the size of array A\n");
 scanf("%d", &n);
 a=(int *) malloc(n*sizeof(int ));   /*Dynamix Memory Allocation */
 printf("Enter Elements of First List\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",a+i);
 }
 /*Compute the sum of all elements in the given array*/
 for(i=0;i<n;i++)
 {
  sum = sum + *(a+i);
 }
 printf("Sum of all elements in array = %d\n", sum);
}

Output:


C programming, C programs, array

06 Aug 2015

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Top