Monday 8 December 2014

C program to print power of a number

program to print power of a number
#include<stdio.h>
main()
{
int a,b,result=1;
printf("enter values for a and b\n");
scanf("%d%d",&a,&b);
while(b!=0)
{
result=result*a;
b--;
}
printf("result is %d\n",result);
}
Output:
madan@madan-Lenovo-G570:~/madan$ cc ex48.c
madan@madan-Lenovo-G570:~/madan$ ./a.out
enter values for a and b
3
4
result is 81