sum of all the elements of an array using pointer IN C program

 C- program to find the sum of all the elements of an array using pointer  

This is  a C program to find the answer of sum of  the array elements using pointer 


Problem Description 
calculate the sum of array elements using pointer.  This c program add the array elements  values uses pointer.



problem solution


  •   First create a pointer variable  , which point an int data.
  •   Take a size of array as input.
  •   after create a size of array  * size of all array elements
  • after iterate for loop taking element as input.
  • again use for loop to access the address stored in pointer ,add the iterator value , so as to all access elements of array .


source code

This source code of the C program  to calculate the sum of array using pointer . this program successfully compilied and tested by netbeans .


Program  


#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
    int *p,a[20];
    int i, n, sum = 0;
    printf("enter the size of array \n");
    scanf("%d",&n);
    printf("\n give the elements one by one ");
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    p=a;
    for(i=0;i<n;i++)
    {
        sum = sum+*p;
        ++p;
    }
    printf("\n\n The sum of array element:%d",sum);

    return (EXIT_SUCCESS);
}

Output


 sum of all the elements of an array using pointer IN C program


Comments

Popular posts from this blog

Create a structure TIME with members hours, minutes and seconds. Write a C program to add two time objects by passing structure variables to function and display result in H: M: S format.

Create a structure named company which has name, address, phone and no of Employee as member variables. Read name of company, its address, phone and no of Employee. Finally display these members’ value.

Write a c program to check a voting AGE condition using if-else