Computer Science, asked by ramlakshman97, 1 year ago

write a c program to find sum of elements in array by using pointers.??​

Answers

Answered by akku833
2

Here is source code of the C program to calculates the sum of array elements using pointer. The program is successfully compiled and tested using Turbo C compiler in windows environment. The program output is also shown below.

/*

* C program to read N integers and store them in an array A.

* Find the sum of all these elements using pointer.

*/

#include <stdio.h>

#include <malloc.h>

void main()

{

int i, n, sum = 0;

int *a;

printf("Enter the size of array A \n");

scanf("%d", &n);

a = (int *) malloc(n * sizeof(int));

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);


ramlakshman97: thank u sir... and another question is here..plz answer to this question..what is DMA? Explain different types of DMA functions with example...
akku833: Direct memory access (DMA) is a method that allows an input/output (I/O) device to send or receive data directly to or from the main memory, bypassing the CPU to speed up memory operations. The process is managed by a chip known as a DMAcontroller (DMAC).
ramlakshman97: types of DMA functions??
akku833:  It is a mechanism that allows I/O devices to access main memory without having to go through the CPU , which is a time consuming process. ... With the help of DMA (direct memory access) we can directly transter data from memory to i/o device
ramlakshman97: thank u..
akku833: its ohk..
Answered by gurukulamdivya
1

Answer:

#include <stdio.h>

#include <malloc.h>

 void main()

{

int i, n, sum = 0;

int *a;

       printf("Enter the size of array A \n");

scanf("%d", &n);

         a = (int *) malloc(n * sizeof(int));

         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);

 }

Similar questions