How to find the value of 2^n, without using semicolon anywhere in program & value of n is defined by user? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to find the value of 2^n, without using semicolon anywhere in program & value of n is defined by user?

please suggest the most time efficient way...

13th Sep 2017, 8:28 AM
Arpit Kharche
Arpit Kharche - avatar
3 Answers
+ 6
Interesting Baptiste! Anyway I find it's a strange requirement.. 😅
13th Sep 2017, 9:14 AM
Zephyr Koo
Zephyr Koo - avatar
+ 4
#include <stdio.h> #include <stdlib.h> int main( int argc, char** argv ) { if( argc > 1 && printf( "%d", 1 << atoi( argv[1] ) ) ){} } No semicolons, but you have to run your program with an argument like: program 12 output: 4096
13th Sep 2017, 9:14 AM
Dennis
Dennis - avatar
+ 3
I could not avoid 2 semicolon whether using a function or not due to the user input problem and return statement #include <stdio.h> int call(unsigned n,unsigned res){ if(scanf("%d",&n) && (res=1)){ while(n-- && (res<<=1)){} } return res; } int main() { if(printf("%d\n",call(0,0))){} return 0; }
13th Sep 2017, 8:54 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar