fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.  
  6. signed int m, n;
  7. int i;
  8. float p;
  9. printf("Enter the number and its power (exponent)\n");
  10. scanf("%d%d",&m,&n);
  11. p=1;
  12. if (n==0)
  13. {
  14. printf("%d raised to %d is: %f",m,n,p);
  15. }
  16.  
  17. if (n>0)
  18. {
  19. for( i = 0 ; i < n ; i++ )
  20. p*=m;
  21. if(m>0)
  22. printf("%d raised to %d is: %f",m,n,p);
  23. if(m<0)
  24. printf("%d raised to %d is: %f",m,n,-p);
  25. }
  26.  
  27. if (n<0)
  28.  
  29. {
  30. n=-n;
  31. for( i = 0 ; i < n ; i++ )
  32. p*=m;
  33. if(m>0)
  34. printf("%d raised to %d is: %f",m,-n,1/p);
  35. if(m<0)
  36. printf("%d raised to %d is: %f",m,-n,-(1/p));
  37. }
  38. }
Success #stdin #stdout 0s 10320KB
stdin
-2 -3
stdout
Enter the number and its power (exponent)
-2 raised to -3 is: 0.125000