Monday, June 18, 2012

To evaluate the equation y=x^n, where n is a non-negative integer


/* Program to evaluate the equation y=x^n, where n is a non-negative integer */

#include<stdio.h>

#include<conio.h>

void main()

{

  int count,n;

  float x,y;

  clrscr();

  printf("Enter the values of x and n\n");

  printf("\nX=");

  scanf("%f",&x);

  printf("\N=");

  scanf("%d",&n);

  y=1.0;

  count=1;

  while(count<=n)

  {

    y=y*x;

    count++;

  }

  printf("\n%f to power %d = %f",x,n,y);

  getch();

}

 

OUTPUT

Enter the values of x and n

 

X=2

N=5

 

2.000000 to power 5 = 32.000000

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.