Guest User

Untitled

a guest
Oct 20th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. int potencia(double x,int n)
  5. {
  6. int i;
  7. double producto=1;
  8. double resultado=1;
  9.  
  10. if (n==0) return 1;
  11. if (n==1) return x;
  12.  
  13. for (i=1;i<=n;i++)
  14. {
  15. producto*=(double) x;
  16. resultado=producto;
  17. }
  18.  
  19. printf("\nEl resultado es : %lf",resultado);
  20. }
  21.  
  22. int main()
  23. {
  24. int n;
  25. double x;
  26.  
  27. printf("Este programa calcula x^n...\n\nIngrese x: ");
  28. scanf("%lf",&x);
  29. printf("\nIngrese n: ");
  30. scanf("%d",&n);
  31. potencia (x,n);
  32. printf("\n\n");
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment