Giiovanna 0 Denunciar post Postado Março 17, 2013 Estou tentando fazer um programa para tirar raiz de qualquer índice. O código: #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <math.h> main () { float x,y,resp; int b; printf("Digite o indice da raiz: "); scanf("%d",&b); while(b==0){ printf("Operacao invalida. Tente outro indice: "); scanf("%d",&b); } printf("Digite o radicando: "); scanf("%f",&x); if(b %2==0) { while(x<0) { printf("Impossivel continuar. Digite outro radicando: "); scanf("%f",&x); } if (x==0) { printf("A raiz %d de 0 é 0",b); } else { resp=pow(x,pow(b,-1)); printf("\nA raiz %d de %f e %f",b,x,resp); } } else { if (x==0) { printf("A raiz %d de 0 e 0",b); } resp=pow(x , pow(b,-1)); printf("\nA raiz %d de %f e %f",b,x,resp); } getch (); return(0); system ("stop"); } Porém, ele não está aceitando raiz negativa de índice impar. Aparece sempre -1. Alguém tem ideia do que pode ser? O problema é na parte vermelha Obrigada Compartilhar este post Link para o post Compartilhar em outros sites
Renato Utsch 24 Denunciar post Postado Março 17, 2013 Não existe raiz de número negativo, pela própria definição de raiz. Mas, de qualquer maneira, isso está na definição da função pow() na standard: C99 Standard, seção 7.12.7.4. Description 2 The pow functions compute x raised to the power y. A domain error occurs if x is finite and negative and y is finite and not an integer value. A domain error may occur if x is zero and y is less than or equal to zero. Abraços :D Compartilhar este post Link para o post Compartilhar em outros sites
matthee 3 Denunciar post Postado Março 17, 2013 E não use DEV-C++. Compartilhar este post Link para o post Compartilhar em outros sites