Home Forums C Programming ‘while’ statement ??

Viewing 1 reply thread
  • Author
    Posts
    • #2164
      SilviaJamieson
      Participant

      Hi, as i said i am new to all this computer stuff, I think that if i can see how codes are written a few times, then i can start to understand it better. Please help me to better understand this language.

      Write a C program using a while-statement to compute n factorial (n!) of a nonnegative integer n where
      p = 1 (for n = 0)
      p = double = n*(n-1)*(n-2)*…*2*1 (for n€1)
      „ For example : 5! = 5*4*3*2*1 = 120
      „ Prompt user to enter the value of n, computes
      and prints its factorial (p)

      Best wishes ……..daisy

    • #3490
      GWILouisaxwzkla
      Participant

      could do:


      /****************************************************************
      * File Name : c:programstempCG.cpp
      * Date : December,7,2008
      * Comments : new project
      * Compiler/Assembler :
      * Modifications :
      *
      *
      *
      *
      *
      * Program Shell Generated At: 2:47:31 p.m.
      =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


      #include
      //#include
      //#include
      //#include
      //#include
      //#include

      //using namespace std;

      //main function ******************************

      int main ( )
      {

      int number;
      int factorial = 1;
      int i = 1;

      printf ( "Enter a positive integer : " );
      scanf ( "%i" , & number );



      while ( i <= number )
      {
      factorial = i * factorial;
      i ++;
      }

      printf ( "the factorial is %i " , factorial );

      return 0 ;
      }




Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.