- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Program for product of array
Given an array arr[n] of n number of elements, the task is to find the product of all the elements of that array.
Like we have an array arr[7] of 7 elements so its product will be like
Example
Input: arr[] = { 10, 20, 3, 4, 8 } Output: 19200 Explanation: 10 x 20 x 3 x 4 x 8 = 19200 Input: arr[] = { 1, 2, 3, 4, 3, 2, 1 } Output: 144
The approach used below is as follows −
- Take array input.
- Find its size.
- Iterate the array and Multiply each element of that array
- Show result
Algorithm
Start In function int prod_mat(int arr[], int n) Step 1-> Declare and initialize result = 1 Step 2-> Loop for i = 0 and i < n and i++ result = result * arr[i]; Step 3-> Return result int main() Step 1-> Declare an array arr[] step 2-> Declare a variable for size of array Step 3-> Print the result
Example
#include <stdio.h> int prod_arr(int arr[], int n) { int result = 1; //Wil multiply each element and store it in result for (int i = 0; i < n; i++) result = result * arr[i]; return result; } int main() { int arr[] = { 10, 20, 3, 4, 8 }; int n = sizeof(arr) / sizeof(arr[0]); printf("%d", prod_arr(arr, n)); return 0; }
Output
If run the above code it will generate the following output −
19200
- Related Articles
- C++ Program for dot product and cross product of two vectors
- Maximum product subset of an array in C++ program
- C Program for Program for array rotation?
- C++ program for multiplication of array elements
- C++ program to find the first digit in product of an array of numbers
- Maximum product of a triplet (subsequence of size 3) in array in C++ Program.
- C Program for Reversal algorithm for array rotation
- Maximum sum of pairwise product in an array with negative allowed in C++ program
- Maximum product subset of an array in C++
- Array product in C++ using STL
- A Product Array Puzzle in C?
- A Product Array Puzzle in C++?
- 8086 program to determine product of corresponding elements of two array elements
- Program to find sign of the product of an array using Python
- Python Program for Product of unique prime factors of a number

Advertisements