Course Content
Detailed Content of Programming in C
0/1
Introduction
0/1
Structure of C program
0/1
Answers of ‘C’ Pointers Programs
0/1
About Lesson

Calculate Factorial of a Number using a While Loop.

#include <stdio.h>

int main() {
int num, factorial = 1, i = 1;

// Taking input for the number
printf(“Enter a non-negative integer: “);
scanf(“%d”, &num);

// Calculating the factorial of the number using a while loop
while (i <= num) {
factorial *= i;
i++;
}

printf(“Factorial of %d: %dn”, num, factorial);

return 0;
}