Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to calculate x raise to y or power(x,y) using while loop

Posted By: Reginheraht Fischer     Category: C Programming     Views: 21021

Write a program to calculate x raise to y or power(x,y) using while loop.

Code for Program to calculate x raise to y or power(x,y) using while loop in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
    int x,y;
    double power();
    clrscr();

    printf("Enter value of x : ");
    scanf("%d",&x);
    printf("Enter value of y : ");
    scanf("%d",&y);

    printf("%d to power %d is = %f\n",x,y,power(x,y));
    getch();
}
double power(x,y)
int x,y;
{
    double p;
    p=1.0;
    if(y>=0)
        while(y--)
            p*=x;
    elsewhile(y++)
            p/=x;
    return(p);
}
  
Share: 



Reginheraht Fischer
Reginheraht Fischer author of Program to calculate x raise to y or power(x,y) using while loop is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!