
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
First digit in product of an array of numbers in C++
In this tutorial, we are going to learn how to find first digit of the product of an array.
Let's see the steps to solve the problem.
Initialize the array.
Find the product of the elements in the array.
Divide the result until it's less than 10.
Print the single-digit
Example
Let's see the code.
#include <bits/stdc++.h> using namespace std; int productOfArrayDigits(int arr[], int n) { int product = 1; for (int i = 0; i < n; i++) { product *= arr[i]; } return product; } int firstDigitOfNumber(int n) { while (n >= 10) { n /= 10; } return n; } int main() { int arr[] = { 1, 2, 3, 4, 5, 6 }; cout << firstDigitOfNumber(productOfArrayDigits(arr, 6)) << endl; return 0; }
Output
If you run the above code, then you will get the following result.
7
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- Related Articles
- C++ program to find the first digit in product of an array of numbers
- Product of all other numbers an array in JavaScript
- Product of all prime numbers in an Array in C++
- Product of all the Composite Numbers in an array in C++
- Find last k digits in product of an array numbers in C++
- Find the Product of first N Prime Numbers in C++
- Count of Numbers in Range where first digit is equal to last digit of the number in C++
- Absolute Difference between the Product of Non-Prime numbers and Prime numbers of an Array?
- Product of numbers present in a nested array in JavaScript
- Product of maximum in first array and minimum in second in C
- Maximum product subset of an array in C++
- Check if all sub-numbers have distinct Digit product in Python
- Finding product of an array using recursion in JavaScript
- Maximum product subset of an array in C++ program
- LCM of an array of numbers in Java

Advertisements