Slip 16 - A) Write a C program to calculate x^y without using standard library function.

Solution:


#include<stdio.h>
#include<conio.h>
void main()
{
 int x,y,i,r=1,t;
 printf("Enter a number:");
 scanf("%d",&x);
 printf("Enter the power:");
 scanf("%d",&y);
 for(i=1;i<=y;i++)
 {
  t=x;
  r=r*t;
 }
 printf("Result:%d",r);
 getch();
}

Post a Comment

0 Comments