Finding sum of elements of given array using DMA- C

Q. Write a program to find the sum of elements of a given array, using DMA.
#AssignmentNo9
==> Code goes like this:

#include "stdio.h"
#include "stdlib.h"
int main() {
   int *a,i,sum=0,size;
   printf("\n Enter the size of array:");
   scanf("%d",&size);
   printf("\n Enter %d element of array:",size);
   a=(int *)malloc(size*sizeof(int));
    for (int i = 0; i <size ; ++i) {
        scanf("%d",a+i);
        sum=sum + *(a+i);
    }
    printf("\n The sum of array element is %d",sum);
    return 0;
}

Output














If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment