How to save values to an array?

Write a C program that: 1. Creates an array of integers of size 5 having the following values? {2,2,5,1,3}?

  • 2. Squares each element in the array. (Use the property that the name of the array is a pointer to the first element in the array) 3. Find the product of the elements of the array. (Use the property that the name of the array is a pointer to the first element in the array) i just need part 3 please !=]

  • Answer:

    int a[]={2,2,5,1,3}; int product(int []); ... int product(r[]){ int i,pro=1; for(i=0;i<5;i++) pro*=r[i]; return pro; }

Duaa-07 at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

int a[]={2,2,5,1,3},i,prduct=1; for(i=0;i<5;i++) a[i]=a[i]*a[i]; //second step// You can write as *(a+i) *= *(a+i); for(i=0;i<5;i++) product *=a[i]; //try product *= *(a+i); printf("%d\n", product);

James Bond

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.