Write a Program in C That Do Raise X To The Y Power

// raise x to the y power 
#include <stdio.h>

int main( void )
{
   unsigned int x, y, i, power; // define variables 

   i = 1; // set i 
   power = 1; // set power 
   printf( "%s", "Enter first integer: " );
   scanf( "%u", &x ); // read value for x from user 
   printf( "%s", "Enter second integer: " );
   scanf( "%u", &y ); // read value for y from user 

   while ( i <= y ) { // loop while i is less than or equal to y 
      power *= x; // multiply power by x 
      ++i; // increment i 
   } // end while                                        

   printf( "%u\n", power ); // display power 
} // end main function

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...