Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form

Write a program that initializes values 2, 6, 3, 5, 4 and 7 in one-dimensional array and computes the factorial.

Posted on October 16, 2021 By myustaadg.com
Spread the love

Write a program that initializes values 2, 6, 3, 5, 4 and 7 in one-dimensional array. It computes the factorial of value of each element of the array and displays the result on the screen.

So let’s Write Code:

Introduction to C++ Programming | Download and Install Dev C++ Compiler

Let’s build logic First:

Algorithm for code:

  • Step 1: Start
  • Step 2: Declare and initialize an array.
  • Step 3: Declare variables.
  • Step 4: Initialize f is equal to one and i is equal to zero.
  • Step 5: Check if n>=1 then f * n and store in f.
  • Step 6: Repeat Step 5 until i < = 5
  • Step 7: Print values
  • Step 8: End Program

Code:

Write a program that initializes values 2, 6, 3, 5, 4, and 7 in a one-dimensional array. It computes the factorial value of each element of the array and displays the result on the screen.

#include"iostream" 
using namespace std;
main()
{
long arr[] = {2,6,3,5,4,7},i = 0, f, n;
while(i<=5)
{
f = 1;
n = arr[i];
for(; n>=1; n--)
f = f * n;
cout<<"Factorial of "<<arr[i]<<": "<<f<<endl;
i++;
}
}

Hope You will learn Something. Happy Coding.

Visit my YouTube Channel as Well๐Ÿ˜‡ https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4

Click on the below Links for more Programming Exercises:

Conditional Structure Exercises: ๐Ÿ‘‰https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/

Array Exercises: ๐Ÿ‘‰https://myustaadg.com/category/programming-exercises/arrays-exercises/

Arrays Exercises, Programming Exercises Tags:Array examples, Array Exercises, Array exercises in C++, Arrays, Arrays in C++, C++ Factorial, C++ Program to Find Factorial, C++ Program to Find Factorial of a Number, factorial in c++, factorial of a number, Factorial of an Array of integers, Factorial Program in C++, factorial program in c++ using while loop, factorial using array in c++, How do you find the factorial of a loop in C++?, how to calculate factorial of vales, Program for factorial of a number, Program to find factorial of Number in C++, Write a program that initializes values 2 6 3 5 4 and 7 in a one-dimensional array. It computes the factorial value of each element of the array and displays the result on the screen.

Post navigation

Previous Post: Write a program that inputs values into a one-dimensional array and finds odd and even Numbers.
Next Post: Write a program that sorts an array in ascending order by passing the array to a function.

More Related Articles

Write a program that inputs values in an array and finds out the largest value from the array using a function. Arrays Exercises
Write a program that asks the user their annual income and shows on the screen the tax rate that corresponds to them | Python Programming Programming Exercises
Write a program that reads a positive integer, , entered by the user and then displays on the screen the sum of all integers from 1 to . The sum of the positive first integers can be calculated as follows: Sum =n(n+1)/2 | python Programming Programming Exercises
Write a program that inputs values into a one-dimensional array of ten elements. Draws a bar chart or histogram. Arrays Exercises
Write a program that asks the user for the number of hours worked and the cost per hour. Then show payment on the screen that corresponds to you | Python Programming Programming Exercises
Write a program that inputs data into a table and displays it on the screen in tabular form. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme