C program to find power of number without using function

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
 int a,b,i,power=1;

 //Accepting value of a & b
 printf("Enter the value of a\n");
 scanf("%d",&a);
 printf("Enter the value of b\n");
 scanf("%d",&b);

//Calculating a raise to b
 for(i=1;i<=b;i++)
 {
  power=power*a;
 }

//Printing answer
 printf("%d^%d=%d",a,b,power);
}

 

OUTPUT:

Enter the value of a
5
Enter the value of b
2
5^2=25

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.