C program to calculate sum, product of all One Dimensional Array Elements
This program will read N One Dimensional Array Elements, and calculate the Sum and Product of all elements and print the sum and product.
Logic to implement this program - Read array, Run a loop from 0 to N-1 and add each element in SUM variable and multiply each element in PRODUCT variable. Don’t forget to assign 0 in SUM and 1 in PRODUCT variables before running the loop.
Sum and Product of all 1D Array Elements using C program
Output
Enter elements : Enter arr[0] : 11 Enter arr[1] : 22 Enter arr[2] : 3 Enter arr[3] : 4 Enter arr[4] : 5 Enter arr[5] : 66 Enter arr[6] : 7 Enter arr[7] : 8 Enter arr[8] : 9 Enter arr[9] : 10 Sum of array is : 145 Product of array is : 534965504Using User Define Function
Output
Enter elements : Enter arr[0] : 11 Enter arr[1] : 22 Enter arr[2] : 3 Enter arr[3] : 4 Enter arr[4] : 5 Enter arr[5] : 66 Enter arr[6] : 7 Enter arr[7] : 8 Enter arr[8] : 9 Enter arr[9] : 10 Sum of array is : 145 Product of array is : 534965504need an explanation for this answer? contact us directly to get an explanation for this answer