Two numbers are entered through keyboard, write a program to find the value of one number raised to the power another.

This question is related to Aztec-Systems Interview

Showing Answers 1 - 31 of 31 Answers

tarun00000

  • Oct 25th, 2008
 

Code
  1.  

  2.  

  3. #include

  4. #include

  5. main()

  6. {

  7. int a,b,c;

  8. clrscr();

  9. printf("enter two no.:");

  10. scanf("%d%d",&a,&b);

  11. c=a+b;

  12. pritf("sum of no.is=%d",c);

  13. getch();

  14. }

  15.  

  Was this answer useful?  Yes

sarabjit

  • Oct 14th, 2009
 

Code
  1. #include

  2. int main()

  3. {

  4. int a,b,i,prod=1;

  5. printf("Enter a number :");

  6. scanf("%d",&a);

  7. printf("Enter its power:");

  8. scanf("%d",&b);

  9. for(i=0;iprod = prod*a;

  10. printf("pow(a,b) = %d", prod);

  11. getch();

  12. return 0;

  13. }

  Was this answer useful?  Yes

jechanter

  • Feb 8th, 2010
 

Code
  1. main()

  2. {

  3.         scanf("%d",&a); // base

  4.          scanf("%d",&b); //power

  5.          for(int i=0;i             a=a*b;

  6.         printf("result is..%d",a);

  7. }

  Was this answer useful?  Yes

Shivam

  • Jul 15th, 2013
 

Code
  1. #include<conio.h>

  2. #include<stdio.h>

  3. #include<math.h>

  4. main()

  5. {

  6.     int a,b,num,i;

  7.     printf("enter the number ");

  8.     scanf("%d",&a);

  9.     printf("enter the number  in power");

  10.     scanf("%d" , &b);

  11.   num = pow(a,b);

  12.  

  13.    printf("%d" , num);

  14.     getch();

  15. }

Code
  1. #include<stdio.h>

  2. #include<iostream>

  3. using namespace std;

  4. /* Function to calculate x raised to the power y */

  5. float power(int x,  int y)

  6. {

  7.  float pow=1.0;

  8. int temp=y;

  9. if((temp>>31)==-1) temp=-1*temp;

  10. if(temp==1 && (y>>31)==-1) return (1.0/x);

  11. else if(temp==1 && !(y>>31)) return x;

  12.    while(temp>0){

  13.  

  14.         if(y>0){

  15.         if((temp&1)==0)

  16.         pow*=x*x;

  17.         else pow*=x*x*x;

  18.         }

  19.         else pow=(pow/(x*x));

  20.         temp=temp/2;

  21.    }

  22. return pow;

  23.  

  24. }

  25.  

  26. /* Program to test function power */

  27. int main()

  28. {

  29.     int x =

  30.      int y = 2;

  31.  

  32.     printf("%f", power(x, y));

  33.     getchar();

  34.     return 0;

  35. }

  Was this answer useful?  Yes

sudhakar

  • Jul 19th, 2014
 

how to work the scanf function?

  Was this answer useful?  Yes

shweta gupta

  • Jul 21st, 2014
 

it traverse the char type format specifier from left to right and assign the value from stdin to the address of the variable. Scanf return type is int and return the number of argument.


Its syantax is scanf(const char *,...), there is the ... represent the variable argument list.

  Was this answer useful?  Yes

Ripam Paul

  • Feb 17th, 2016
 

Here is the answer if you dont wanna use the pow.

Code
  1. #include<stdio.h>

  2.         main()

  3.         {

  4.                 int num, pwr, res=1;

  5.                

  6.                 printf("Enter an Number and the power respectively

  7. ");

  8.                 scanf("%d%d", &num, &pwr);

  9.                

  10.                 while(pwr>0)

  11.                 {

  12.                         res=res*num;

  13.                         pwr=pwr-1;

  14.                 }

  15.                 printf("

  16. your acquired result is: %d",res);

  17.         }

  Was this answer useful?  Yes

Mukeshwar Singh

  • Jun 22nd, 2019
 

Easy!

Code
  1. #include <stdio.h>

  2. #include <math.h>

  3. int main()

  4. {

  5.     int a,b,c;

  6.   printf("Enter two Numbers");

  7.   scanf("%d%d",&a,&b);

  8.   c = pow(a,b);

  9. printf("The Value of Number is %d",c);

  10. return 0;

  11. }

  12.  

  Was this answer useful?  Yes

Shikha chaudhary

  • Jul 16th, 2020
 

This is the easiest way !!

Code
  1. #include<stdio.h>

  2. void main()

  3. {

  4.     int x, y,  i, ans;

  5.     printf("enter the base number");

  6.     scanf("%d", &x);

  7.     printf("enter the exponent");

  8.     scanf("%d", &y);

  9.  

  10.     ans=x;

  11.     for(i=1;i<y;i++)

  12.     {

  13.         ans=ans*x;

  14.     }

  15.     printf("%d", ans);

  16. }

  17.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions