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 - 8 of 8 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

Give your answer:

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

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions