vendredi 18 février 2022

How to convert a while loop into a for loop?

How do I change this while loop into a for loop?

#include <stdio.h>

int main() 
{
    int number;
    long int factorial = 1;

    printf("\nEnter the number:");
    scanf("%d", &number);

    do {
        factorial = factorial * number--;
    } while (number > 1);

    printf("\nThe factorial is %d",factorial);    
}

Aucun commentaire:

Enregistrer un commentaire