+ 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...
4 odpowiedzi
+ 6
Interesting Baptiste! Anyway I find it's a strange requirement.. 😅
+ 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
+ 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;
}