void main() { float y; int i; for(i=0;i<=20;i++){ y=coseno(radian(i)); printf("\t\t el coseno de %d es %f\n",i,y); } }
int main(void) { double soma = 0; int pi, count = 0; long seed = time(NULL); srand((unsigned)seed); for ( pi = 0; pi<1000; pi++) { if ( realRandom() < coseno()) count++; } printf("Valor de PI: %lf\n", 2.0 * (double)pi /(1.0 * count)); }
int main() { float x0, x1, tolerancia, cota; printf("ingrese semilla\n"); scanf("%f", &x0); printf("ingrese tolerancia\n"); scanf("%f", &tolerancia); cota = 5; while (cota > tolerancia) { x1 = coseno(x0); cota = fabs(x1 - x0); x0 = x1; } printf("el resultado es %f\n", x1); return 0; }
int main(int argc, char* argv[]){ bind_textdomain_codeset ("calc", "UTF-8"); setlocale(LC_ALL, ""); bindtextdomain("calc","idioma"); textdomain("calc"); // declaracion de variables locales //variable para leer la categoria de funciones int categoria; //Cambio del manejo de señales, mensaje de error en caso de que no sea posible if (signal (SIGINT, myCatch) == SIG_ERR){ perror ("SIGINT can not change"); } if (signal (SIGSEGV , myCatch) == SIG_ERR){ perror ("SIGTERM can not change"); } //Mensaje de bienvenida printf(_("\n\nWelcome, you are running a calculator developed by the team Icazas!\n\n")); //Ciclo principal do{ //Desplegamos en pantalla el menu de categorias mostrarMenu (); //Leemos un digito en base 10 de maximo 2 caracteres categoria = readInt(10,2); //Si el valor leido es un numero evaluamos el menu //De lo contrario mostramos mensaje de error if (categoria != myNaN ()) { //Con la categoria y la operacion elegidas evaluamos la funcion adecuada switch (categoria) { case 1: { suma(); break; } case 2: { resta(); break; } case 3: { multiplicacion(); break; } case 4: { division(); break;} case 5: { seno(); break; } case 6: { coseno(); break; } case 7: { tangente(); break; } case 8: { arcoseno(); break; } case 9: { arcoCoseno(); break; } case 10:{ coseno(); break; } case 11:{ senoHiper(); break; } case 12:{ coship(); break; } case 13:{ tangenteHiper(); break; } case 14:{ atanDos(); break; } case 15:{ expon(); break; } case 16:{ logaritmoNatural(); break; } case 17:{ decLog(); break; } case 18:{ raizCuadrada(); break; } case 19:{ potencia(); break; } case 20:{ valorAbsoluto(); break; } case 21:{ fmodd(); break;} case 22:{ funcionTecho(); break;} case 23:{ funcionPiso(); break; } case 24:{ frexpre(); break; } case 25:{ ldexpe(); break;} case 26:{ moduloF(); break;} case 27:{ printf(_("\n\nThank you for using our calculator!\n")); printf(_("Come back soon!\n\n")); break; } default:{ printf(_("\n\nYou entered an invalid option!\n")); printf(_("Try again!\n\n")); break; } } } else{ printf(_("\n\nError: It is not a number!\n")); printf(_("Try again!\n\n")); } }while (categoria != 27); return 0; }
void menu_graf(char *file) { FILE * pbm; int flag_opt=0; /* flag_opt = 0 si no entro a ninguna funcion a graficar */ typedef enum {SEN=1,COS,POL0,POL1,POL2,POL3,LN,EXP,DEFAULT,ERROR=255} opt_graf_t; opt_graf_t optgraf; char option[MAX_CHAR]; int matriz[RESOLUCION][RESOLUCION]; float vect_x[RESOLUCION]; float vect_y[RESOLUCION]; cargo_x(vect_x); printf(MENU_GRAF); limpiarbuffer(); fgets(option, MAX_CHAR, stdin); option[strlen(option)-1]='\0'; optgraf=atoi(option); /* si se ingreso algo que no es una opcion debe ir al default */ if (optgraf==0) optgraf=DEFAULT; while (optgraf) { switch(optgraf) { case SEN: seno(vect_x, vect_y); flag_opt=1; break; case COS: coseno(vect_x, vect_y); flag_opt=1; break; case POL0: pol0(vect_x, vect_y); flag_opt=1; break; case POL1: pol1(vect_x, vect_y); flag_opt=1; break; case POL2: pol2(vect_x, vect_y); flag_opt=1; break; case POL3: pol3(vect_x, vect_y); flag_opt=1; break; case LN: ln(vect_x, vect_y); flag_opt=1; break; case EXP: expo(vect_x, vect_y); flag_opt=1; break; default: printf("Entrada inválida!\n"); } /* Este if corta la ejecuccion del programa si ya grafico sale del bucle while(optgraf) */ if(flag_opt==1) break; printf("Presione enter para volver al menu \n"); limpiarbuffer(); system(CLS); printf(MENU_GRAF); fgets(option, MAX_CHAR, stdin); option[strlen(option)-1]='\0'; optgraf=atoi(option); /* Si se ingreso una letra o algo que no es valido*/ if (!optgraf) optgraf=255; } inicializo_matriz(matriz); inicializo_ejes(matriz); cargo_matriz(matriz, vect_y); if(file==NULL) imprimo_matriz(matriz); else { /* Abrimos el pbm para guardar datos como file */ make_pbm_file(&pbm,file); /* grabamos la info y luego cerramos el file* */ write_pbm_file(&pbm, matriz, RESOLUCION, RESOLUCION); close_pbm_file(&pbm); } }