Tuesday, August 16, 2022

Factorial a Number Using Function in C

 

Machine Problem

Write a program that uses a function that will ask the user to give a number and then the program will compute the factorial equivalent of the given number by the user.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

Please subscribe to my channel  https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg

=================================================


Want to support my channel?

GCash Account

Jake Pomperada


09173084360


Paypal

https://paypal.me/jakerpomperada


Patreon

https://www.patreon.com/jakerpomperada

Thank you very much for your support.





Program Listing

// factorial.cpp

// Author    : Mr. Jake R. Pomperada, BSCS,MAED-IT

// Date      : August 26, 2018   Sunday  5:19 PM

// Location  : Bacolod City, Negros Occidental Philippines.

// Website   : http://www.jakerpomperda.com

// Email     : jakerpomperada@jakerpomperada.com and jakerpomperada@gmail.com



#include <iostream>

#include <conio.h>


using namespace std;


 // function prototype declaration  

int factorial(int);  


int main()

{  

                

int num_input=0;

int solve=0;


cout <<"\n\n";

cout <<"\tFactorial a Number Solver";

cout <<"\n\n";

cout<<"\tGive a Number : ";

cin>>num_input;

solve= factorial(num_input);   

cout <<"\n\n";                                      

cout<<"\tThe factorial value of "<<num_input<<" is "<<solve<<".";

cout <<"\n\n";

cout << "\tEnd of Program";

cout <<"\n\n"; 

getch();

}


// function factorial


int factorial(int a)

{

int fact=1;


while(a>=1)

{

fact=fact*a;

a--;

}


return fact;

}


 



No comments:

Post a Comment