| |
GeekInterview.com > Placement Papers > Freescale Semiconductor
| Print | |
Question: 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.
Answer: 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 (\ |
| April 04, 2006 05:22:48 |
#1 |
| sivarajan |
Member Since: Visitor Total Comments: N/A |
RE: write a program in C to add five 32 bit numbers av... |
| #include int my_array[] = {1,23,-4,5,6,9}; // for example of a random arrayint *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 = %d\t",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 %d\n",tot); return 0; } |
| |
Back To Question | |