c program for calculating product of array

#include <stdio.h>

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    int product = 1;

    for (int i = 0; i < 5; i++) {
        product *= arr[i];
    }

    printf("Product of array elements: %d\n", product);

    return 0;
}
  1. Include the standard input/output library stdio.h to use functions like printf.
  2. Define the main function, which is the entry point of the program.
  3. Declare an array arr with a size of 5 and initialize it with values 1, 2, 3, 4, and 5.
  4. Declare a variable product and initialize it with the value 1. This variable will store the product of the array elements.
  5. Start a for loop that iterates from 0 to 4 (inclusive) using the variable i as the loop counter.
  6. Inside the loop, multiply the current element of the array arr[i] with the product variable and store the result back in the product variable. This step calculates the product of all the array elements.
  7. After the loop ends, use the printf function to print the value of the product variable, which represents the product of the array elements.
  8. Finally, return 0 to indicate successful program execution.