Q. Write a program to find the sum of elements of a given array, using DMA.
#BIT_FirstSem_2017_9No_5Marks_Solution
==>Code goes like this:
#include<stdio.h>
int main()
{
int i,n;
float *num,sum=0;
printf("Enter sie of array: ");
scanf("%d",&n);
num=(float *)malloc(n*sizeof(float));
printf("Enter %d array elements: ",n);
for ( i = 0; i < n; i++)
{
scanf("%f",num+i);
sum=sum+*(num+i);
}
printf("Sum of given array elements is %.2f ",sum);
return 0;
}
Output:
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Find the sum of elements of given array, using DMA - C
9:48 PM
Array in C Language
,
AssignmentSolutionC
,
C Programs
,
DMA in C
,
OldQuestionSolution2017C
,
Sum of elements of array in C
Edit
0 comments:
Post a Comment