Monday, February 14, 2011

WAP to calculate and print 2 raise to the power 5 without using any digit in ur prgm

This is nothing just a trick,as we have looked that printf returns the number of charaters printed ....
and we know there is a pow function in the math.h library which returns the result of a number raised to other number.....

so the solution is........


#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
clrscr();
printf("power is %f",pow(printf("hi"),printf("hello")));
getch();
return 0;
}

output:
hellohipower is 32.000000

Explanation:
printf("hi") returns 2 ,printf("hello") return 5 and pow function returns the 2 raise to the power 5..........

Note....pow(arg1,arg2) evalutes from right to left thats why it prints hello first and then hi............


No comments:

Post a Comment

Feel free to comment......