Search C Program | nimishsoft@gmail.com

Calculate factorial using while loop

/* Calculate factorial using while loop */

#include<stdio.h>
int main()
{
    int a,f,i;
    printf("Enter a number: ");
    scanf("%d",&a);
    f=1;
    i=1;
    while(i<=a)
    {
        f = f * i;
        i++;
    }
    printf("Factorial: %d",f);
    return 0;
}


Related Post:
Calculate factorial using for loop
http://cbasicprogram.blogspot.in/2012/02/calculate-factorial-using-for-loop.html

13 comments:

  1. osum work done by using only while loop

    ReplyDelete
    Replies
    1. Attention everyone, the file provided above is not working. I have been looking for the working file and finally found it.



      ✔️Click Here To Download http://gestyy.com/e0GAyS
      ✔️Click Here To Download

      ✔️Click Here To Download http://exe.io/XONVsO6l

      ✔️Click Here To Download


      ✔️Click Here To Download
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .

      .

      .
      .

      .

      .
      .
      .
      .

      Mn.
      ..

      .
      .
      .
      ..
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      ..
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .xz
      .
      .sdcccxxx

      Delete
  2. #include
    #include
    #include

    int main()
    {
    int a,b=1;
    printf("Enter a number.");
    scanf("%d",&a);
    while(a>1)
    {
    b=a*b;
    a=a-1;
    }

    printf("The answer is %d",b);



    return 0;
    }





    ReplyDelete
  3. Why does it gives -25216 if we input 8??

    ReplyDelete
    Replies
    1. because int range is -32,768 to 32,767, try this program with long variables
      http://codepad.org/0QF7Czjm

      Delete
  4. Replies
    1. because we are multiplying, if we make it 0,every value would be 0.

      Delete
  5. The program lacks one thing..if we give 0 then it would not return its factorial as its factorial is zero and it would return zero..the issue can be fixed by a combination of else with while loop..

    ReplyDelete
  6. Nice....
    I got what I was finding....
    Thanks..

    ReplyDelete