Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- int potencia(double x,int n)
- {
- int i;
- double producto=1;
- double resultado=1;
- if (n==0) return 1;
- if (n==1) return x;
- for (i=1;i<=n;i++)
- {
- producto*=(double) x;
- resultado=producto;
- }
- printf("\nEl resultado es : %lf",resultado);
- }
- int main()
- {
- int n;
- double x;
- printf("Este programa calcula x^n...\n\nIngrese x: ");
- scanf("%lf",&x);
- printf("\nIngrese n: ");
- scanf("%d",&n);
- potencia (x,n);
- printf("\n\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment