Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Thursday, September 29, 2022

C program to calculate the power of an input number using a user-defined function

 C program to calculate the power of an input number using a user-defined function


#include<stdio.h>

#include<conio.h>

int power(int, int );

main()

 {

 int y,x,p;

 printf("Enter the value of y\n");

 scanf("%d",&y);

 printf("Enter the value of x\n");

 scanf("%d",&x);

 p=power(y,x);

 printf("y raise to power x=%d",p);

 getch();

}

int power(int y,int x)

 {

 int p=1,i;

 for(i=1;i<=x;i++)

 {

 p=p*y;

 }

 return p;

}


Output:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages