Write a program in C to add five 32 bit numbers available at successive memory locations and to divide the result by sixth numer available at next successive location.

Main()
{ long int i, sum=0,*p;
p=1001; /* assume the numbers are from 1001 location */
for (i=0;i<5;i++)
{ sum= sum+ *p ;
p=p+1;
}
sum=sum/(*p) ; /* use only /*(p) not /*p since it may come to comment */
printf (\

Questions by pvpfirst

Showing Answers 1 - 1 of 1 Answers

sivarajan

  • Apr 20th, 2006
 

#include
int my_array[] = {1,23,-4,5,6,9};

// for example of a random arraying *ptr ;int sum;long tot;int main(void)
{
int i;
ptr = my_array;

//since the name of the array is a pointer for(i=0; i<5; i++)
{
printf("n the value of my_array[%d]is %d and is stored in %p ",i,my_array[i],
(void *)&(my_array[i]));
printf("n ptr + %d = %dt",i, *(ptr+i));
sum = sum + *(ptr++);
printf("nthe value of the sum is %d",sum);
}
tot = sum/(*ptr);
printf("nthe value of the total is %dn",tot);
return 0;
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions