write a c/c++ program that takes a 5 digit number and
calculates 2 power that number and prints it?

Answers were Sorted based on User's Feedback



write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?..

Answer / parth ujenia

The condition is input take "5 digit" !
and according to above C prog
output of:12345
is: 27825

because range of integer data type is -32768 to 32767.

Is This Answer Correct ?    7 Yes 1 No

write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?..

Answer / m.choudhury

The problem is 2^(axxxx) where x belongs to {0,1,.....9} & a
belongs to {1,2,3,.....9}. This is clearly not equivalent to
2*(axxxx).

The solution will be easier if we can give the answer in
HEXADECIMAL format.

2^2=(4)DEC=(100)BINARY=(4)HEX
2^4=(16)DEC=(10000)BINARY=(10)HEX
2^7=(128)DEC=(10000000)BINARY=(80)HEX
.
.
.
2^n=(X)DEC=(100.....0)BINARY{n no. of zero after 1}=(Z)HEX
(X is the decimal of 2^n, Z is HEXADECIMAL of 2^n)

To get Z get HEX of (1a) where a = n%4 is the number of
zeros after 1.

Then path n/4 no. of zeros with that.

can anyone suggest the code for integer representation of
2^n , (where n is any integer), with polynomial time
complexity ?

Is This Answer Correct ?    1 Yes 0 No

write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?..

Answer / sudarshan

#include<stdio.h>
void main()
{
int a,b;
scanf("%d",&a);
b=a*a;
printf("%d",b);
getch();
}

Is This Answer Correct ?    6 Yes 7 No

write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?..

Answer / suvi

#include<stdio.h>
void main()
{
float a,b;
scanf("%f",&a);
b=a*a;
printf("%.0f",b);

}

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More C Interview Questions

What is a static variable in c?

0 Answers  


What does calloc stand for?

0 Answers  


Distinguish between actual and formal arguments.

0 Answers  


what is the stackpointer

2 Answers  


Why do we need volatile in c?

0 Answers  






Explain is it valid to address one element beyond the end of an array?

0 Answers  


can any one tell that i have a variable which is declared as static but i want this variable to be visible to the other files? how?

2 Answers  


Is c functional or procedural?

1 Answers  


write a program to find out number of on bits in a number?

17 Answers   Huawei, Microsoft,


b) 4 c) 6 d) 7 32. Any C program a) must contain at least one function b) need not contain ant function c) needs input data d) none of the above 33. Using goto inside for loop is equivalent to using a) continue b) break c) return d)none of the above 34. The program fragment int a=5, b=2; printf(“%d”,a+++++b); a) prints 7 b)prints 8 c) prints 9 d)none of the above 35. printf(“ab” , “cd”,”ef”); prints a) ab abcdef c) abcdef, followed by garbage value d) none of the above 36. Consider the following program segment. i=6720; j=4; while((i%j)==0) { i=i/j; j=j+1; } On termination j will have the value a) 4 b) 8 c) 9 d) 6720

1 Answers   HCL,


Write a C program to get the desired output. 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 . . . 1 n..............n 1 Note: n is a positive integer entered by the user.

4 Answers  


What do mean by network ?

0 Answers  


Categories