This program calculates the factorial of a given number using a loop and a goto statement. The long int data type is used to accommodate large values of factorial.
Here's how the program works:
While this program works correctly, using a goto statement is generally not considered good programming practice because it can make the code difficult to read and maintain. A better alternative would be to use a for or while loop to calculate the factorial.
#include<iostream> using namespace std; int main() { long int a,n=1; cout<<"\nEnter the number :"; cin>>a; start: n=n*a; a--; if(a>0) { goto start; } cout<<"\nThe Total value is :"<<n; return 0; }To download raw file Click Here
Enter the number :5 The Total value is :120
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions