Write a program that takes a 5 digit number and calculates
2 power that number and prints it(should not use big
integers and exponential functions)

Answers were Sorted based on User's Feedback



Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should..

Answer / venu

sol 1:
int fun(int i5DigitNum)
{
return 2<< i5DigitNum; // will overflow if the number is > 32
}

sol 2:
//assumption 32 bit machine
temp = i5DigitNum/32 + i5DigitNum%32 == 0 ? 0 :1 ;
char * temp2 = malloc(temp*4)
temp2[0] = 1 << i5DigitNum%32;

// now print this array as number!! :(

Is This Answer Correct ?    4 Yes 4 No

Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should..

Answer / nitin katakdound

int main(int argc, char *argv)
{
long two_power, five_digit_number;

if(scanf("%ld",&five_digit_number)){
two_power = five_digit_number*five_digit_number;}
printf("\n 2 power of that number is %ld",two_power);

return 0;
}

Is This Answer Correct ?    13 Yes 29 No

Post New Answer

More C Interview Questions

what is dangling pointer?

1 Answers   LG Soft,


what is c programing

11 Answers   Wipro,


how to create c progarm without void main()?

1 Answers   NIIT,


What is scope rule in c?

0 Answers  


what is the difference between exit() and _exit() functions?

2 Answers  






18)struct base {int a,b; base(); int virtual function1(); } struct derv1:base{ int b,c,d; derv1() int virtual function1(); } struct derv2 : base {int a,e; } base::base() { a=2;b=3; } derv1::derv1(){ b=5; c=10;d=11;} base::function1() {return(100); } derv1::function1() { return(200); } main() base ba; derv1 d1,d2; printf("%d %d",d1.a,d1.b) o/p is a)a=2;b=3; b)a=3; b=2; c)a=5; b=10; d)none 19) for the above program answer the following q's main() base da; derv1 d1; derv2 d2; printf("%d %d %d",da.function1(),d1.function1(),d2.function1 ()); o/p is a)100,200,200; b)200,100,200; c)200,200,100; d)none 20)struct { int x; int y; }abc; you can not access x by the following 1)abc-->x; 2)abc[0]-->x; abc.x; (abc)-->x; a)1,2,3 b)2&3 c)1&2 d)1,3,4

1 Answers  


what is link list?

3 Answers  


What is the difference between array and pointer?

0 Answers  


what information does the header files contain?

6 Answers   BSNL, Cisco, GDA Technologies,


4. main() { int c=- -2; printf("c=%d",c); }

0 Answers  


What is pragma c?

0 Answers  


how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12

0 Answers  


Categories