Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int pot_pos( int base, int exp ){
- int i, res=base;
- // POTENCIA CERO
- if( exp==0 ) return 1;
- // POTENCIA POSITIVA
- if( exp>0 ){
- for( i=1 ; i<exp ; i++ ){
- res=res*base;
- }
- return res;
- }
- }
- float pot_neg( int base, int exp ){
- int i;
- float res=1.0/base;
- // POTENCIA NEGATIVA
- printf(" Potencia negativa \n ");
- return 0;
- /*
- if( exp<0 ){
- exp=exp*-1;
- for( i=1 ; i<exp ; i++ ){
- res=res*(1/base);
- }
- return res;
- } */
- }
- float raiz( int base, int ind ){
- float i, res;
- if( ind==1 ) return base;
- // RAIZ EXACTA
- for( i=1 ; i<base ; i++ ){
- if( base==pot_pos(i,ind) ) return i;
- }
- //RAIZ INEXACTA
- printf(" Raiz inexacta \n ");
- return 0;
- }
- int main(){
- int menu, retry, num, aux;
- do{
- do{
- system("cls");
- printf(" \n 1. Potencia \n 2. Raiz \n 0. Salir \n ");
- scanf("%d",&menu);
- }while( menu<0 || menu>2 );
- system("cls");
- fflush(stdin);
- switch( menu ){
- case 0: return 0;
- break;
- case 1: printf(" \n -= Potencia =- \n Introduce numero (espacio) exponente: ");
- scanf("%d %d",&num,&aux);
- if( aux>=0 ) printf(" %d \n ",pot_pos(num,aux));
- else printf(" %f \n ",pot_neg(num,aux));
- break;
- case 2: printf(" \n -= Raiz =- \n Introduce numero (espacio) indice: ");
- scanf("%d %d",&num,&aux);
- if( raiz(num,aux)!=0 ) printf(" %f \n ",raiz(num,aux));
- }
- printf(" \n Volver al menu(1=si)? ");
- scanf("%d",&retry);
- }while( retry==1 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement