Write a C program to make pow() function which takes two integer and return power of number1 to number2

 TASK-

 Write a function pow() which takes two integer parameters a and n and returns nth power of a, write a program to use this function.

CODE:

#include <stdio.h>
int pow(int n,int a);
int main(){
	int n,a,p;
printf("Enter the number and its power : ");
scanf("%d%d",&n,&a);
p=pow(n,a);
printf("\n %d to the %d is %d",n,a,p);
getchar();
return 0;
}
int pow(int n,int a)
{
	int i,p=1;
	for (i=1;i<=a;i++)
	{
	p=p*n; //p=1,then if n=2, which follow p=1,then p=p*n
	}
	return p;
}


EXPECTED OUTPUT:




NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

2 Comments

Post a Comment
Previous Post Next Post