Wednesday, February 23, 2011

Decision Making and Looping

A program to evaluate the equation 
y = x raised to n power
when n is a non-negative integer, is given.

#include <stdio.h>
void main()
{
int count,n;
float x,y;
printf("Enter the values of x and n:");
scanf("%f %d",&x,&n);
y=1.0;
count=1;
while(count<=n)
{
y=y*x;
count++;
}
printf("\nx = %f; n = %d; x to power n = %f\n",x,n,y);
getch();
}

No comments:

Post a Comment