Home › Forums › C Programming › Help with this C coding
- This topic has 2 replies, 3 voices, and was last updated 16 years ago by Adetutu.
Viewing 2 reply threads
- AuthorPosts
- November 18, 2008 at 1:02 pm #2158KalaLindseyParticipant
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.
- November 18, 2008 at 9:47 pm #3484GWILouisaxwzklaParticipant
try:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152<br />/****************************************************************<br />* File Name : c:programshelptempCG.cpp<br />* Date : November,17,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 7:02:58 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br /><br />int number = 0;<br /><br />printf ( "Enter a number to square " );<br />scanf ( "%i" , & number );<br />printf ( "the square is %i n " , number * number );<br />return 0;<br /><br /><br /><br /><br />}<br /><br /><br /> - December 16, 2008 at 6:22 am #3485AdetutuParticipant
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
- AuthorPosts
Viewing 2 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.