Write C program to find factorial of any number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h> int main() { int num,i; long long fact=1; // Reading a number from user printf("Enter any number to calculate factorial: "); scanf("%d",&num); fact = 1; i = 1; //Run loop from 1 to number entered by user while(i <= num) { fact = fact * i; i++; } printf("Factorial of %d = %lld", num, fact); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> int main() { int i, num; long long fact=1; // Reading a number from user printf("Enter any number to calculate factorial: "); scanf("%d", &num); //Run loop from 1 to number entered by user for(i=1; i<=num; i++) { fact = fact * i; } printf("Factorial of %d = %lld", num, fact); return 0; } |
03 July 2019 2085 Written By: Rohit
© 2020 Tech Study. All rights reserved | Developed by Tech Study| Privacy Policy | Sitemap