C program to calculate the sum of the pointer.

 

C program
C PROGRAM

C program to calculate the sum of the pointer

#include<stdio.h>

#include<string.h>

void main()

{    

int*p,sum=0,i;

int x[5]={5,9,6,3,8};

i=0;

 p=x;

clrscr();

printf("\nNOTATION VALUE ADDRESS \n\n");

while(i<5)

{

printf("x[%d] \t %d \t %u \n",i,*p,p);

 sum=sum+*p;

i++,p++;

}

printf("sum=%d",sum);

getch();

}

OUTPUT :

NOTATION VALUE ADDRESS 


x[0] 5 953465056 

x[1] 9 953465060 

x[2] 6 953465064 

x[3] 3 953465068 

x[4] 8 953465072 

sum=31

Process finished.

Comments

Popular posts from this blog

Write a program to calculate a students result based on two examinations, 1 sports event, and 3 activities conducted. The weightage of activities= 30%, sports= 20% , and examinations= 50%.

Determine the intensity of shear of an oil having viscosity= 1 poise. The oil is used for lubricating the clearance between a shaft of diameter 10 cm and its journal bearing. The clearance is 1.5mm and the shaft rotates at 150 r.p.m.