Beta Coder

Learn code like Beta Coder.

Breaking

Saturday, September 12, 2020

C Program to Calculate x^n without using pow()

Calculate x^n without using pow()

Calculate x^n without using pow()
In this program we learn how to calculate x^n without using pow() provided by user using C.
C program to calculate x^n without using pow()
// Calculate x^n without using pow()
#include<stdio.h>
#include<conio.h>
void main()
{
	long int x, n, i, p = 1;
	clrscr();
	printf("\n Enter the value of x and n : ");
	scanf("%ld%ld",&x,&n);
	for(i = 1; i <= n; i++)
		p = p * x;
	printf("\n %ld^%ld = %ld",x,n,p);
	getch();
}
OUTPUT:
   Enter the value of x and n : 3 4
   3^4 = 81

No comments:

Post a Comment