Home Forums C Programming Help with this C coding

Viewing 2 reply threads
  • Author
    Posts
    • #2158
      KalaLindsey
      Participant

      help write an application in C that asks user about a number and computes the 2n (two to the power of n). Print result to the screen.

    • #3484
      GWILouisaxwzkla
      Participant

      try:


      /****************************************************************
      * File Name : c:programshelptempCG.cpp
      * Date : November,17,2008
      * Comments : new project
      * Compiler/Assembler :
      *
      *
      *
      *
      *
      * Program Shell Generated At: 7:02:58 p.m.
      =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


      #include < stdio.h >
      //#include < string.h >
      //#include < conio.h >
      //#include < math.h >
      //#include < iomanip >
      //#include < ctype.h >




      //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@



      //##################################################################################


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

      int main ( )
      {


      int number = 0;

      printf ( "Enter a number to square " );
      scanf ( "%i" , & number );
      printf ( "the square is %i n " , number * number );
      return 0;




      }


    • #3485
      Adetutu
      Participant

      I hope this is program of you assignment. :lol: Any way If you want to calculate 2 to power n(2^n) Please try this piece of code.

      /***********************************************
      Program to Calculate 2 to power n (2^n)
      ***********************************************/
      #include
      int main()
      {
      int n, i , pow = 1;

      printf(“Enter the number (n):: “);
      scanf(“%d” , &n);
      for(i = 0; i < n; i++)
      {
      pow = pow * 2;
      }
      printf(“Result is :: %d”, pow);
      }

      Please feel to revert back.
      Thanks
      Gaurav

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