void testDivision(){
	printf("testDivision\n");
	complex a;
	a.real = 16;
	a.imag = 4;
	
	complex b;
	b.real = 2;
	b.imag = 10;

	complex c;
	c = division(a,b);

	double r = 72 / (double)104;
	double i = -152 / (double)104;

	assert(c.real == r && c.imag == i);
}
Exemple #2
0
int main(void) {

  int a = 1, b = 2, c = 4, x = 0;

  while(1){
    printf("Bienvenue dans le programme de test");
    
    x = multiplication(a,b);
    printf("Voici le résultat de la multiplication : %d\n", x);
    
    x = 0;
    x = division(c,b);
    printf("Voici le résultat de la division : %d\n", x);
    
    x = 0;
    x = addition(c,b);
    printf("Voici le résultat de l'addition : %d\n", x);
    
    x = 0;
    }
}
Exemple #3
0
int main(void)
{
 int op,a,b,c;

printf("\tcalculadora de enteros\n");
printf("ingrese un numero entero\n");
scanf("%d",&a);
printf("ingrese otro numero entero\n");
scanf("%d",&b);

printf("digite la operacion q desea realizar\n");
print("1-suma, 2-resta, 3-multiplicacion, 4-division\n\t");
scanf("%d",&op);

switch(op)
{
case 1:
      c = suma(a,b);
      printf("\nel resultado de la suma es: %d",c);
      break;

case 2:
      c = resta(a,b);
      printf("\nel resultado de la resta es: %d",c);
      break;

case 3:
      c = multiplicacion(a,b);
      printf("\nel resultado de la multiplicacion es: %d",c);
      break;

case 4:
      c = division(a,b);
      printf("\nel resultado de la division es: %d",c);
      break;
}

return 0;
}
Exemple #4
0
int main()
{
	int opcion;
	float numero1;
	float numero2;
	float resultado;
	printf("Programa calculadora\n");
	do{
		imprime_menu();
		scanf("%d", &opcion);
		switch(opcion) {
			case SUMA:
				introducir_datos(&numero1, &numero2);
				resultado = suma(numero1, numero2);
				imprimir_resultado(resultado);
				break;
			case RESTA:
				introducir_datos(&numero1, &numero2);
				resultado = resta(numero1, numero2);
				imprimir_resultado(resultado);
				break;
			case MULTIPLICACION:
				introducir_datos(&numero1, &numero2);
				resultado = multiplicacion(numero1, numero2);
				imprimir_resultado(resultado);
				break;
			case DIVISION:
				introducir_datos(&numero1, &numero2);
				resultado = division(numero1, numero2);
				imprimir_resultado(resultado);
				break;
			default:
				break;
		}
	}while (opcion != 5);

	return 0;
}
main()
{
	int A, B, S, differ,time,divise,operate;
	printf("please enter a number A:");
	scanf("%d", &A);
	printf("please enter a number B:");
	scanf("%d", &B);
	printf("请选择要进行的操作:\n");
	printf("1.加法\n");
	printf("2.除法\n");
	printf("3.乘法\n");
	printf("4.减法\n");
	printf("0.退出\n");
	scanf("%d", &operate);

	switch (operate)
	{
	case 1:
		S = sum(A, B);
		printf("%d\n", S);
		break;
	case 2:
		differ = difference(A, B);
		printf("%d\n", differ);
		break;
	case 3:
		time = times(A, B);
		printf("%d\n", time);
		break;
	case 4:
		divise = division(A, B);
		printf("%d\n", divise);
		break;
	case 0:
		break;
	}	

}
int main(void) {
	
	int op1 = 10;
	int op2 = 5;
	
	int erg;
	
	erg = addition( op1 , op2 );
	printf("%d + %d = %d\n", op1, op2, erg);
	
	erg = subtraktion( op1 , op2 );
	printf("%d - %d = %d\n", op1, op2, erg);
	
	erg = multiplikation( op1 , op2 );
	printf("%d * %d = %d\n", op1, op2, erg);

	erg = division( op1 , op2 );
	printf("%d / %d = %d\n", op1, op2, erg);
	
	sinnlos();
	
	return 0;
}
Exemple #7
0
void opcion(opt_t opt)
{
    switch(opt)
    {
        case SUMA: suma_simplecalc();
            break;
            
        case RESTA: resta_simplecalc();
            break;
            
        case MULT: multiplicacion_simplecalc();
            break;
            
        case DIVISION: division();
            break;
            
        case POT: dialogo_pot();
            break;
            
        case FACT: dialogo_fact();
            break;
            
        case COMBIN: dialogo_comb();
            break;
            
        case ALEATORIO: dialogo_alea();
            break;
            
        case GRAFICO: menu_graf();
            break;
            
        default: printf("Entrada inválida, ingrese una opción del menú \n");
            break;
    }
    
    
}
Exemple #8
0
int main()
{
    char seguir='s';
    int opcion;
    int flag1erOperando=0;
    int flag2doOperando=0;
    float operandoUno;
    int intoperandoUno;
    float operandoDos;

    do
    {
        system("cls");
        printf("CALCULADORA\n\nSelecciona una opcion del menu:\n\n");
        printf("1- Ingresar 1er operando (A=x)\n");
        printf("2- Ingresar 2do operando (B=y)\n");
        printf("3- Calcular la suma (A+B)\n");
        printf("4- Calcular la resta (A-B)\n");
        printf("5- Calcular la division (A/B)\n");
        printf("6- Calcular la multiplicacion (A*B)\n");
        printf("7- Calcular el factorial (A!)\n");
        printf("8- Calcular todas las operaciones\n");
        printf("9- Salir\n");

        scanf("%d",&opcion);
        while(opcion<1 || opcion>9)
        {
            printf("Error! Ha ingresado una opcion de menu inexistente.\nIngrese una opcion correcta:\n");
            scanf("%d",&opcion);
        }

        switch(opcion)
        {
            case 1:
                system("cls");
                flag1erOperando=1;
                operandoUno = pedirNum();
                intoperandoUno=(int)operandoUno;
                printf("Has elegido el numero: %f \n",operandoUno);
                system("pause");
                break;

            case 2:
                system("cls");
                flag2doOperando=1;
                operandoDos = pedirNum();
                printf("Has elegido el numero: %f \n",operandoDos);
                break;

            case 3:
                if(valOperandos(flag1erOperando,flag2doOperando))
                {
                    system("cls");
                    printf("El resultado de (A+B) es:\n%f \n",suma(operandoUno,operandoDos));
                    system("pause");
                }
                else
                {
                    if(flag1erOperando==0 && flag2doOperando==0)
                    {
                    printf("Debe ingresar los dos operandos para realizar esta operacion \n");
                    system("pause");

                    }
                    else
                    {

                        if(flag1erOperando==1)
                        {
                        printf("Debe ingresar el 2do operando para realizar esta operacion \n");
                        }
                        else
                        {
                        printf("Debe ingresar el 1er operando para realizar esta operacion \n");
                        }
                        system("pause");
                    }

                }
                break;

            case 4:
                if(valOperandos(flag1erOperando,flag2doOperando))
                {
                    system("cls");
                    printf("El resultado de (A-B) es:\n%f \n",resta(operandoUno,operandoDos));
                    system("pause");
                }
                else
                {
                    if(flag1erOperando==0 && flag2doOperando==0)
                    {
                    printf("Debe ingresar los dos operandos para realizar esta operacion \n");
                    system("pause");

                    }
                    else
                    {

                        if(flag1erOperando==1)
                        {
                        printf("Debe ingresar el 2do operando para realizar esta operacion \n");
                        }
                        else
                        {
                        printf("Debe ingresar el 1er operando para realizar esta operacion \n");
                        }
                        system("pause");
                    }

                }
                break;

            case 5:
                if(valOperandos(flag1erOperando,flag2doOperando))
                {
                    system("cls");
                    printf("El resultado de (A/B) es:\n%f \n",division(operandoUno,operandoDos));
                    system("pause");
                }
                else
                {
                    if(flag1erOperando==0 && flag2doOperando==0)
                    {
                    printf("Debe ingresar los dos operandos para realizar esta operacion \n");
                    system("pause");

                    }
                    else
                    {

                        if(flag1erOperando==1)
                        {
                        printf("Debe ingresar el 2do operando para realizar esta operacion \n");
                        }
                        else
                        {
                        printf("Debe ingresar el 1er operando para realizar esta operacion \n");
                        }
                        system("pause");
                    }

                }
                break;

            case 6:
                if(valOperandos(flag1erOperando,flag2doOperando))
                {
                    system("cls");
                    printf("El resultado de (A*B) es:\n%f \n",multiplicacion(operandoUno,operandoDos));
                    system("pause");
                }
                else
                {
                    if(flag1erOperando==0 && flag2doOperando==0)
                    {
                    printf("Debe ingresar los dos operandos para realizar esta operacion \n");
                    system("pause");

                    }
                    else
                    {

                        if(flag1erOperando==1)
                        {
                        printf("Debe ingresar el 2do operando para realizar esta operacion \n");
                        }
                        else
                        {
                        printf("Debe ingresar el 1er operando para realizar esta operacion \n");
                        }
                        system("pause");
                    }

                }
                break;

            case 7:
                if(valOperandoUno(flag1erOperando))
                {
                    if(operandoUno != intoperandoUno || operandoUno<1)
                    {
                        printf("\nError. No se puede realizar el factorial de este numero.\n");
                        system("pause");
                    }
                    else
                    {
                    system("cls");
                    printf("El factorial de (A) es:\n%d \n",factorial(operandoUno));
                    system("pause");
                    }
                }
                else
                    {
                    printf("Debe ingresar el 1er operando (A) para realizar esta operacion \n");
                    system("pause");
                    }
                break;

            case 8:
                if(flag1erOperando==0 && flag2doOperando==0)
                    {
                    printf("Debe ingresar los dos operandos para realizar esta operacion \n");
                    system("pause");

                    }
                    else
                    {
                    system("cls");
                    printf("El resultado de (A+B) es:\n%f \n",suma(operandoUno,operandoDos));
                    printf("El resultado de (A-B) es:\n%f \n",resta(operandoUno,operandoDos));
                    printf("El resultado de (A/B) es:\n%f \n",division(operandoUno,operandoDos));
                    printf("El resultado de (A*B) es:\n%f \n",multiplicacion(operandoUno,operandoDos));
                    if(operandoUno != intoperandoUno || operandoUno<1)
                    {
                        printf("El factorial de (A) es:\nError. No se puede realizar el factorial de este numero.\n");
                    }
                    else
                    {
                    printf("El factorial de (A) es:\n%d \n",factorial(operandoUno));
                    }
                    system("pause");
                    }
                break;

            case 9:
                seguir = 'n';
                break;
        }
    }while(seguir=='s');


    return 0;
}
Exemple #9
0
int main() {
    struct Complex *complex = (struct Complex *) calloc(COMPLEX_SIZE_DEFAULT, sizeof(struct Complex));
    int size = COMPLEX_SIZE_DEFAULT;
    int count_of_elements = COMPLEX_SIZE_DEFAULT;
    
    struct Complex c1, c2, result;

    complex[0].re = COMPLEX1_RE;
    complex[0].im = COMPLEX1_IM;
    complex[1].re = COMPLEX2_RE;
    complex[1].im = COMPLEX2_IM;

    c1.re = COMPLEX1_RE;
    c1.im = COMPLEX1_IM;
    c2.re = COMPLEX2_RE;
    c2.im = COMPLEX2_IM;

    while (1) {
        char ch;
		print_main_menu(c1, c2);
        ch = getchar();
        clear_input();
        switch (ch) {
        case '1':
        {
            int index = 0;
            change_complex_interface(&c1, complex, count_of_elements);
            break;
        }
        case '2':
        {
            int index = 1;
            change_complex_interface(&c2, complex, count_of_elements);
            break;
        }
        case 'a':
        case 'A':
            result = add(c1, c2);
            print_complex(result);
            break;
        case 's':
        case 'S':
            result = sub(c1, c2);
            print_complex(result);
            break;
        case 'm':
        case 'M':
            result = mul(c1, c2);
            print_complex(result);
            break;
        case 'd':
        case 'D':
			{
				int error = 0;
				result = division(c1, c2, &error);
				if (!error)
					print_complex(result);
			break;
			}
        case 'r':
        case 'R':
            complex = read_file_interface(complex, &size, &count_of_elements);
            break;
        case 'w':
        case 'W':
            complex = write_file_interface(complex, &size, &count_of_elements);
            break;
        case 'q':
        case 'Q':
            return 0;
        default:
            printf("Incorrect input, please choose an existing element\n");
        }
    }
    return 0;
}
Exemple #10
0
bigInt::bigInt(string s,string form)
{
	for (int i=0; i < size; i++)// premordial nulling
		a[i]=0;

	uint string_size = s.size();
	for (int i=0; i < string_size; i++)
		s[i]-=48;

	if (form == "dec")
	{
		uint wc=0,bc=0,bit=0;
		while(s!="999")
		{
			bit=division(s);
			bit=bit<<bc;
			a[wc]=a[wc]|bit;
			bc++;
			if(bc>(sizeof(uint)*8-1))
			{
				bc=0;
				wc++;
			}
		}
	}

	else if(form == "hex")
	{
		int word = 0,j = 0;
		uint tmp;
		for ( int i = string_size - 1; i >= 0; i--)
		{
			switch(s[i])
			{
			case 'a'-48:
			case 'A'-48:
				{
					tmp = 10;
					break;
				}
			case 'b'-48:
			case 'B'-48:
				{
					tmp = 11;
					break;
				}
			case 'c'-48:
			case 'C'-48:
				{
					tmp = 12;
					break;
				}
			case 'd'-48:
			case 'D'-48:
				{
					tmp = 13;
					break;
				}
			case 'e'-48:
			case 'E'-48:
				{
					tmp = 14;
					break;
				}
			case 'f'-48:
			case 'F'-48:
				{
					tmp = 15;
					break;
				}
			default:
				tmp = s[i];
			}

			tmp = tmp<<j;
			a[word] += tmp;
			j += 4;
			if(j == (sizeof(uint) * 8))
			{
				j = 0;
				word++;
			}
		}
	}
}
Exemple #11
0
int main()
{
    char seguir='S';
    int opcion=0, flag=0, flag1=0;
    double x=0, y=0;

    while(seguir=='S')
    {
            printf("1- Ingresar 1er operando (A=%.2f)\n",x);
            printf("2- Ingresar 2do operando (B=%.2f)\n",y);
            printf("3- Calcular la suma (A+B)\n");
            printf("4- Calcular la resta (A-B)\n");
            printf("5- Calcular la division (A/B)\n");
            printf("6- Calcular la multiplicacion (A*B)\n");
            printf("7- Calcular el factorial (A!)\n");
            printf("8- Calcular todas las operacione\n");
            printf("9- Salir\n\n");
            printf("Ingrese una opcion: ");
            scanf("%d",&opcion);

        switch(opcion)
        {
            case 1:
                   printf("\nIngrese el primer operando:  ");
                   scanf ("%Lf",&x);
                   flag=1;
                   break;

            case 2:
                   printf("\nIngrese el segundo operando: ");
                   scanf ("%Lf",&y);
                   flag1=1;
                   break;

            case 3:
                    if(flag==0||flag1==0)
                {
                    printf("error reingrese un numero");
                    system("pause");
                    break;

                }

               printf("RESULTADO DE LA SUMA: %.2Lf:",suma(x,y));
               system("pause");
                break;
            case 4:
                     if(flag==0||flag1==0)
                {
                    printf("error reingrese un numero");
                    system("pause");
                    break;

                }
                printf("RESULTADI DE LA RESTA: %.2Lf: ",resta(x,y));
               system("pause");
                break;
            case 5:
                   if(flag==0||flag1==0)
                {
                    printf("error reingrese un numero");
                    system("pause");
                    break;

                }
               printf("RESULTADO DE LA DIVISION: %Lf : ",division(x,y));
               system("pause");

                break;
            case 6:
                   if(flag==0||flag1==0)
                {
                    printf("error reingrese un numero");
                    system("pause");
                    break;

                }
                printf("RESULTADO DE LA MULTIPLICACION:  %Lf",multiplicacion(x,y));
                system("pause");


                break;
            case 7:
                     if(flag==0||flag1==0)
                {
                    printf("error reingrese un numero");
                    system("pause");
                    break;

                }
                printf("FACTORIAL DEL PRIMER OPERANDO:  %.2Lf ",factorial(x));
                system("pause");


                break;
            case 8:
                   if(flag && flag1)
                   {
                        printf("\n%.2Lf + %.2Lf = %.2Lf\n", x, y, suma(x,y));
                        printf("\n%.2Lf - %.2Lf = %.2Lf\n", x, y, resta(x,y));
                        printf("\n%.2Lf / %.2Lf = %.2Lf\n", x, y, division (x,y));
                        printf("\n%.2Lf x %.2Lf = %.2Lf\n", x, y, multiplicacion (x,y));
                        printf("\n%.0Lf! = %.0Lf\n\n", x, factorial (x));
                   }
                   else
                        printf("Falta ingresar un operando\n");

                   break;
            case 9:
                   seguir = 'n';


        }

        system("pause");
        system("cls");


    }
    return 0;
}
vector<vector<Event> > ChaingraphTracking::operator()(TraxelStore& ts) {
  LOG(logINFO) << "Calling chaingraph tracking with the following parameters:\n"
	       << "\trandom forest filename: " << rf_fn_ << "\n"
	       << "\tappearance: " << app_ << "\n"
               << "\tdisappearance: " << dis_ << "\n"
    	       << "\tdetection: " << det_ << "\n"
    	       << "\tmisdetection: " << mis_  << "\n"
    	       << "\tcellness_by_random_forest: " << use_rf_  << "\n"
    	       << "\topportunity cost: " << opportunity_cost_ << "\n"
    	       << "\tforbidden cost: " << forbidden_cost_ << "\n"
    	       << "\twith constraints: " << with_constraints_ << "\n"
    	       << "\tfixed detections: " << fixed_detections_ << "\n"
    	       << "\tmean division distance: " << mean_div_dist_ << "\n"
    	       << "\tminimal division angle: " << min_angle_  << "\n"
    	       << "\tcplex ep gap: " << ep_gap_ << "\n"
    	       << "\tn neighbors: " <<  n_neighbors_ << "\n"
   	       << "\twith divisions: " << with_divisions_  << "\n"
   	       << "\tcplex timeout: " << cplex_timeout_ << "\n"
   	       << "\talternative builder: " << alternative_builder_;

	cout << "-> building feature functions " << endl;
	SquaredDistance move;
	BorderAwareConstant appearance(app_, earliest_timestep(ts), true, 0);
	BorderAwareConstant disappearance(dis_, latest_timestep(ts), false, 0);
	GeometryDivision2 division(mean_div_dist_, min_angle_);

	Traxels empty;
	// random forest?
	boost::function<double(const Traxel&)> detection, misdetection;
	if (use_rf_) {
		LOG(logINFO) << "Loading Random Forest";
		vigra::RandomForest<RF::RF_LABEL_TYPE> rf = RF::getRandomForest(rf_fn_);
		std::vector<std::string> rf_features;
		rf_features.push_back("volume");
		rf_features.push_back("bbox");
		rf_features.push_back("position");
		rf_features.push_back("com");
		rf_features.push_back("pc");
		rf_features.push_back("intensity");
		rf_features.push_back("intminmax");
		rf_features.push_back("pair");
		rf_features.push_back("sgf");
		rf_features.push_back("lcom");
		rf_features.push_back("lpc");
		rf_features.push_back("lintensity");
		rf_features.push_back("lintminmax");
		rf_features.push_back("lpair");
		rf_features.push_back("lsgf");

		LOG(logINFO) << "Predicting cellness";
		RF::predict_traxels(ts, rf, rf_features, 1, "cellness");

		detection = NegLnCellness(det_);
		misdetection = NegLnOneMinusCellness(mis_);
	} else if (ts.begin()->features.find("detProb") != ts.begin()->features.end()) {
          for (TraxelStore::iterator it = ts.begin(); it != ts.end(); ++it) {
            Traxel trax = *it;
            trax.features["cellness"] = trax.features["detProb"];
            assert(trax.features["detProb"].size() == 2);
            ts.replace(it, trax);
          }
          detection = NegLnCellness(det_);
          misdetection = NegLnOneMinusCellness(mis_);
	} else {
	  detection = ConstantFeature(det_);
	  misdetection = ConstantFeature(mis_);
	}

	cout << "-> building hypotheses" << endl;
	SingleTimestepTraxel_HypothesesBuilder::Options builder_opts(n_neighbors_, 50);
	SingleTimestepTraxel_HypothesesBuilder hyp_builder(&ts, builder_opts);
	boost::shared_ptr<HypothesesGraph> graph = boost::shared_ptr<HypothesesGraph>(hyp_builder.build());

	cout << "-> init MRF reasoner" << endl;
	std::auto_ptr<Chaingraph> mrf;

	if(alternative_builder_) {
	  pgm::chaingraph::TrainableModelBuilder b(appearance,
						 disappearance,
						 move,
						 opportunity_cost_,
						 forbidden_cost_);
	  
	  if (with_divisions_) {
		  b.with_divisions(division);
	  }

	  b.with_detection_vars(detection, misdetection);
	  mrf = std::auto_ptr<Chaingraph>(new Chaingraph(b, with_constraints_, ep_gap_, fixed_detections_, cplex_timeout_));
	} else {
	  pgm::chaingraph::ECCV12ModelBuilder b(appearance,
					      disappearance,
					      move,
					      opportunity_cost_,
					      forbidden_cost_);
	  
	  if (with_divisions_) {
		  b.with_divisions(division);
	  }

	  b.with_detection_vars(detection, misdetection);
	  mrf = std::auto_ptr<Chaingraph>(new Chaingraph(b, with_constraints_, ep_gap_, fixed_detections_, cplex_timeout_));
	}

	cout << "-> formulate MRF model" << endl;
	mrf->formulate(*graph);

	cout << "-> infer" << endl;
	mrf->infer();

	cout << "-> conclude" << endl;
	mrf->conclude(*graph);

	cout << "-> storing state of detection vars" << endl;
	last_detections_ = state_of_nodes(*graph);

	cout << "-> pruning inactive hypotheses" << endl;
	prune_inactive(*graph);

	cout << "-> constructing events" << endl;

	return *events(*graph);
}
Exemple #13
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;
}
Exemple #14
0
int main(void)
{
    int x, y;
    char sign;
    float numerator, denominator;

    do {
        printf("> ");

        scanf("%c",&sign);

        switch(sign) {
            case '+':
                scanf("%d%d",&x,&y);
                printf("# %d\n",additional(x,y));
                break;

            case '-':
                scanf("%d%d",&x,&y);
                printf("# %d\n",subtraction(x,y));
                break;

            case '/':
                scanf("%f%f",&numerator,&denominator);
                printf("# %.2f\n",division(numerator,denominator));
                break;

            case 'd':
                scanf("%d%d",&x,&y);
                printf("# %d\n",divisionRemain(x,y));
                break;

            case 'm':
                scanf("%d%d",&x,&y);
                printf("# %d\n",modulo(x,y));
                break;

            case '*':
                scanf("%d%d",&x,&y);
                printf("# %d\n",multiply(x,y));
                break;

            case '^':
                scanf("%d%d",&x,&y);
                printf("# %ld\n",power(x,y));
                break;

            case '!':
                scanf("%d",&x);
                printf("# %lld\n",factorial(x));
                break;

            case 's':
                scanf("%d",&x);
                printf("# %d\n",sum(x));
                break;

            case 'a':
                scanf("%d",&x);
                printf("# %.2f\n",average(x));
                break;

            case 'c':
                scanf("%d%d",&x,&y);
                printf("# %lld\n",combinations(x,y));
                break;
            }
        getchar();
    }
    while(sign != 'q');

    return 0;
}
Exemple #15
0
void menu()
{
	system("cls");// efface le terminal
	printf("saisissez votre fonctions : \n");
	printf("1 : multiplication par 3 \n");
	printf("2 : division par 2 \n");
	printf("3 : moyenne de 3 nombres \n");
	printf("4 : convertion degre vers radian \n");
	int n; //variable correspondant au choix
	scanf_s("%d", &n);
	switch (n) //gère les differents cas
	{
		default : //renvoie au menu en cas de numéro inconnu
		{
			menu();
		}
		case 1 : //appelle la première fonction
		{
		system("cls"); // efface le terminal
			printf("entrez un nombre entier :");
			int nombre = 0;
			scanf_s("%d", &nombre);
			triple(nombre);
			printf("%d \n", triple(nombre));
			system("PAUSE");
			menu();
		}
		case 2 : // appelle la deuxième fonction
		{
			system("cls"); // efface le terminal
			printf("entrez un nombre entier :");
			int nombre = 0;
			scanf_s("%d", &nombre);
			division(nombre);
			system("PAUSE");
			menu();
			
		}
		case 3 : //appelle la 3eme fonction
		{
			system("cls"); // efface le terminal
			int a = 0, b = 0;
			float c = 0;
			printf("entrez le premier nombre entier : \n");
			scanf_s("%d", &a);
			printf("entrez le deuxieme entier : \n");
			scanf_s("%d", &b);
			printf("entrez un nombre reel : \n");
			scanf_s("%f", &c);
			printf("la moyenne est : %.3f \n", moyenne(a, b, c));
			system("PAUSE");
			menu();
			
		}
		case 4 : //appelle la 4eme fonction
		{
			system("cls"); // efface le terminal
			printf("entrez un angle en degres : \n");
			float deg = 0;
			scanf_s("%f", &deg);
			printf("l'angle en degré vaut : %f \n", convDegRad(deg));
			system("PAUSE");
			menu();
		}
	}
}
int main()
{
    int opcion=0;
    float primerOperando;
    float segundoOperando;
    float sumar;
    float restar;
    float multiplicar;
    float dividir;
    int factorial;


    do
    {
        system("cls");
        printf("calculadora\n");
        printf("1- Ingresar 1er operando (A=x)\n");
        printf("2- Ingresar 2do operando (B=y)\n");
        printf("3- Calcular la suma (A+B)\n");
        printf("4- Calcular la resta (A-B)\n");
        printf("5- Calcular la division (A/B)\n");
        printf("6- Calcular la multiplicacion (A*B)\n");
        printf("7- Calcular el factorial (A!)\n");
        printf("8- Calcular todas las operacione\n");
        printf("9- Salir\n");
        scanf("%d",&opcion);



        switch(opcion)

        {

            case 1:

                system("cls");
                printf("ingrese el primer operando: ");
                scanf("%f",&primerOperando);


            break;
            case 2:
                system("cls");
                printf("ingrese el segundo operando: ");
                scanf("%f",&segundoOperando);

            break;
            case 3:

                {
                system("cls");
                sumar= suma(primerOperando, segundoOperando);
                printf("la suma es:%.2f",sumar);
                getch();
                }

                break;
            case 4:

                {
                system("cls");
                restar=resta(primerOperando, segundoOperando);
                printf("la resta es:%.2f",restar);
                getch();
                 }

                break;
            case 5:
                system("cls");
                if(segundoOperando<=0)
                {
                    printf("error.debe ingresar un divisor mayor a 0");
                    getch();
                }
                else
                {dividir=division(primerOperando,segundoOperando);
                printf("la division es:%.2f",dividir);
                getch();
                }
                break;
            case 6:

                {
                system("cls");
                multiplicar=multiplicacion(primerOperando,segundoOperando);
                printf("la multiplicacion es:%.2f",multiplicar);
                getch();
                 }

                break;
            case 7:
                if(primerOperando<=0)
                {
                    system("cls");
                    printf("Error:ingrese un numero mayor a 0\n");
                    system("pause");
                }
                else
                {
                system("cls");
                factorial=factorial2(primerOperando);
                printf("el factorial es:%d",factorial);
                getch();
                }


                break;
            case 8:

                {
                system("cls");
                sumar= suma(primerOperando, segundoOperando);
                printf("la suma es:%.2f\n",sumar);
                restar=resta(primerOperando, segundoOperando);
                printf("la resta es:%.2f\n",restar);
                dividir=division(segundoOperando,primerOperando);
                printf("la division es:%.2f\n",dividir);
                multiplicar=multiplicacion(primerOperando,segundoOperando);
                printf("la multiplicacion es:%.2f\n",multiplicar);
                getch();
                }

                break;
            case 9:
                printf("Presione cualquier tecla para salir");
            break;
            default:
                system("cls");
                printf("Error.debe ingresar solamente las opciones de 1 a 9");
                getch();
            break;
        }
}
    while(opcion!=9);
    return 0;
}
int main()
{
    char seguir='s';
    int opcion=0;
    double operadorUno=0,operadorDos=0;
    double resultado;
    int band=0,band1=0;
    while(seguir=='s')
    {
        printf("1- Ingresar 1er operando (A=%0.Lf)         \n",operadorUno);
        printf("2- Ingresar 2do operando (B=%0.Lf)         \n",operadorDos);
        printf("-------------------------------------------\n");
        printf("3- Calcular la suma (A+B)                  \n");
        printf("4- Calcular la resta (A-B)                 \n");
        printf("5- Calcular la division (A/B)              \n");
        printf("6- Calcular la multiplicacion (A*B)        \n");
        printf("7- Calcular el factorial (A!)              \n");
        printf("8- Calcular todas las operacione           \n");
        printf("-------------------------------------------\n");
        printf("9- Salir                                   \n");
        printf("-------------------------------------------\n");

        scanf("%d",&opcion);
        switch(opcion)
        {
            case 1:
                printf("Ingrese operador uno: ");
                scanf("%Lf",&operadorUno);
                band=1;
                system("cls");
                break;
            case 2:
                printf("Ingrese operador dos: ");
                scanf("%Lf",&operadorDos);
                band1=1;
                system("cls");
                break;
            case 3:
                    if(band==1&&band1==1)
                        {
                            resultado=suma(operadorUno,operadorDos);
                            printf("La suma es: %.2Lf\n",resultado);
                        }
                    else
                            printf("Error, ingrese los operadores.\n");
                        system("pause");
                        system("cls");
                    break;
            case 4:
                    if(band==1&&band1==1)
                        {
                            resultado=resta(operadorUno,operadorDos);
                            printf("La resta es: %.2Lf\n",resultado);
                        }
                    else
                            printf("Error, ingrese los operadores.\n");
                        system("pause");
                        system("cls");
                    break;
            case 5:
                    if(band==1&&band==1)
                        {
                            if(operadorDos<0||operadorDos>0)
                                {
                                    resultado=division(operadorUno,operadorDos);
                                    printf("La division es: %.2Lf\n",resultado);
                                }
                            else
                                    printf("Error, no se puede dividir por cero\n");
                        }
                    else
                            printf("Error, ingrese los operadores.\n");
                        system("pause");
                        system("cls");
                    break;
            case 6:
                    if(band=1&&band1==1)
                        {
                            resultado=multiplicacion(operadorUno,operadorDos);
                            printf("La multiplicacion es: %.2Lf\n",resultado);
                        }
                    else
                            printf("Error, ingrese los operadores.\n");
                    system("pause");
                    system("cls");
                break;
            case 7:
                    if(band==1)
                        {
                            resultado=factorial(operadorUno);
                            printf("El resultado del factoreo del operador uno es: %.2Lf\n",resultado);
                        }
                    else
                            printf("Error, ingrese operador uno.\n");
                    system("pause");
                    system("cls");
                break;
            case 8:
                    if(band==1&&band1==1)
                        {
                            resultado=suma(operadorUno,operadorDos);
                                printf("\nLa suma es: %.2Lf\n",resultado);
                            resultado=resta(operadorUno,operadorDos);
                                printf("\nLa resta es: %.2Lf\n",resultado);
                            if(operadorDos<0||operadorDos>0)
                                {
                                    resultado=division(operadorUno,operadorDos);
                                    printf("\nLa division es: %.2Lf\n",resultado);
                                }
                            else
                                    printf("\nError, no se puede dividir por cero\n");

                            resultado=multiplicacion(operadorUno,operadorDos);
                                printf("\nLa multiplicacion es: %.2Lf\n",resultado);
                            resultado=factorial(operadorUno);
                                printf("\nEl resultado del factoreo del operador uno es: %.2Lf\n",resultado);
                        }
                        else
                                printf("Error, ingrese los operadores.\n");
                        system("pause");
                        system("cls");
                break;
            case 9:
                seguir = 'n';
                break;
        }//swich
    }//while
    return 0;
    }//main
Exemple #18
0
/*
 * Executes the Instruction based on the opcode.
 */
static inline void execute_instruction(Instruction instr){
    switch(instr.op) {
        case MOVE:{
            conditionalMove(registers, instr.reg1, instr.reg2, instr.reg3);
            programCounter++;
            break;
        }
        case SEGLOAD:{
            UM_Word ID = registers[instr.reg2];
            UM_Word offset = registers[instr.reg3];
            UM_Word toStore = segmentedLoad(memorySegments, ID, offset);
            registers[instr.reg1] = toStore;
            programCounter++;
            break;
        }
        case SEGSTORE:{
            UM_Word ID = registers[instr.reg1];
            UM_Word offset = registers[instr.reg2];
            UM_Word value = registers[instr.reg3];
            segmentedStore(memorySegments, ID, offset, value);
            programCounter++;
            break;
        }
        case ADD:{
            addition(registers, instr.reg1, instr.reg2, instr.reg3);
            programCounter++;
            break;
        }
        case MULTIPLY:{
            multiplication(registers, instr.reg1, instr.reg2, instr.reg3);
            programCounter++;
            break;
        }
        case DIVIDE:{
            division(registers, instr.reg1, instr.reg2, instr.reg3);
            programCounter++;
            break;
        }
        case NAND:{
            bitwiseNAND(registers, instr.reg1, instr.reg2, instr.reg3);
            programCounter++;
            break;
        }
        case HALT: {
            programCounter = 0;
            break;
        }
        case MAP:{
            UM_Word length = registers[instr.reg3];
            registers[instr.reg2] = mapSegment(memorySegments, length);
            programCounter++;
            break;
        }
        case UNMAP:{
            UM_Word ID = registers[instr.reg3];
            unmapSegment(memorySegments, ID);
            programCounter++;
            break;
        }
        case OUTPUT:{
            output(registers, instr.reg3);
            programCounter++;
            break;
        }
        case INPUT:{
            input(registers, instr.reg3);
            programCounter++;
            break;
        }
        case LOADPROG:{
            UM_Word ID = registers[instr.reg2];
            if(ID != 0){
                loadProgram(memorySegments, ID);
                numInstructions = instructionLength(memorySegments);
                //programPointer = getInstructions(memorySegments);
            }
            programCounter = registers[instr.reg3];
            break;
        }
        case LOADVAL:{
            registers[instr.reg1] = instr.value;
            programCounter++;
            break;
        }
    }
}
Exemple #19
0
int
main(int argc, char **argv) {
  division(1,3,10);
  return 0;
}
int main()
{
    char seguir='s';
    int opcion=0;
    int num1=0, num2=0, flag=0;

           do{
        printf("\n1- Ingresar 1er operando (A=%d)\n",num1);
        printf("2- Ingresar 2do operando (B=%d)\n",num2);
        printf("3- Calcular la suma (A+B)\n");
        printf("4- Calcular la resta (A-B)\n");
        printf("5- Calcular la division (A/B)\n");
        printf("6- Calcular la multiplicacion (A*B)\n");
        printf("7- Calcular el factorial (A!)\n");
        printf("8- Calcular todas las operacione\n");
        printf("9- Salir\n");

        scanf("%d",&opcion);

        switch(opcion)
        {
            case 1:
                system("cls");
                printf("Ingrese numero");
                scanf("%d",&num1);
                flag = 1;
                break;
            case 2:
                system("cls");
                printf("Ingrese numero");
                scanf("%d",&num2);
                flag = 1;
                break;
            case 3:
                if(flag == 0)
                {
                    system("cls");
                    printf("Por favor ingrese los numeros primero");
                }
                else{
                system("cls");
                suma(num1,num2);
                }
                break;
            case 4:
                if(flag == 0)
                {
                    system("cls");
                    printf("Por favor ingrese los numeros primero");
                }
                else{
                system("cls");
                resta(num1,num2);
                }
                break;
            case 5:
                if(flag == 0)
                {
                    system("cls");
                    printf("Por favor ingrese los numeros primero");
                }
                else{
                system("cls");
                if(num2 == 0)
                {
                    printf("Error, no se puede dividir por cero,reingrese numero");
                    scanf("%d",&num2);
                }
                division(num1,num2);
                }
                break;
            case 6:
                if(flag == 0)
                {
                    system("cls");
                    printf("Por favor ingrese los numeros primero");
                }
                else{
                system("cls");
                multiplicacion(num1,num2);
                }
                break;
            case 7:
           if(flag == 0)
                {
                    system("cls");
                    printf("Por favor ingrese los numeros primero");
                }
                else{
                     factorial(num1);
                }
                break;
            case 8:
                if(flag == 0)
                {
                    system("cls");
                    printf("Por favor ingrese los numeros primero");
                }
                else{
            suma(num1,num2);
            resta(num1,num2);
            division(num1,num2);
            multiplicacion(num1,num2);
                }
                break;
            case 9:
                seguir = 'n';
                break;
        }


        }while(seguir == 's');

        system("pause");
    return 0;
}
Exemple #21
0
int main()
{
    char seguir='s';
    int opcion=0,band=0, band1=0, a, b;

    while(seguir=='s')
    {
        printf("1- Ingresar 1er operando (A= %d )\n",a);
        printf("2- Ingresar 2do operando (B= %d)\n",b);
        printf("3- Calcular la suma (A+B)\n");
        printf("4- Calcular la resta (A-B)\n");
        printf("5- Calcular la division (A/B)\n");
        printf("6- Calcular la multiplicacion (A*B)\n");
        printf("7- Calcular el factorial (A!)\n");
        printf("8- Calcular todas las operacione\n");
        printf("9- Salir\n");

        scanf("%d",&opcion);

        switch(opcion)
        {
            case 1:
                      printf("Ingrese el primer operando: \n");
                      scanf("%d", & a);
                      band=1;
                break;
            case 2:
                      printf("Ingrese el segundo operando: \n");
                      scanf("%d", & b);
                      band1=1;
                break;
            case 3:
                     printf("La suma es %d \n",suma(a,b));
                break;
            case 4:
                     printf("La resta es %d \n",resta(a,b));

                break;
            case 5:
                     printf("La division es %.2f \n",division(a,b));
                break;
            case 6:
                     printf("La multiplicacion es %d \n",multiplicacion(a,b));

                break;
            case 7:
                     printf("El factorial es %d \n",factorial(a));
                break;
            case 8:
                     printf("La suma es %d \n",suma(a,b));
                     printf("La resta es %d \n",resta(a,b));
                     printf("La division es %.2f \n",division(a,b));
                     printf("La multiplicacion es %d \n",multiplicacion(a,b));
                     printf("El factorial es %d \n",factorial(a));
                break;
            case 9:

                seguir = 'n';
                break;
        }// fin switch

    }//fin while
    getch();
    return 0;
}
Exemple #22
0
int main(void)
{
  
  char a, o;    
  int flush, r;
  float digits_a, digits_b;
  
  flush = r = 0; 
  digits_a = digits_b = 0;
 
do
  {
    digits_a = get_operand();
    
    o = get_operator();
    while (o != 'c')
      {

	
	digits_b = get_operand();
	
	
	switch(o)
	  {
	    
	  case '+':
	    r = add(digits_a, digits_b);
	    break;
	    
	    
	  case '-':
	    r = subtract(digits_a, digits_b);
	    
	    
	  case '*':
	    r = multiply(digits_a, digits_b);
	    break;
	    
	    
	  case '/':
	    r = division(digits_a, digits_b);
	    break;
	    	    
	    
	  case 'e':
	    r = exponent(digits_a, digits_b);
	    break;
	    
	    
	  default:
	    printf("\nINVALID OPERATOR\n");
	    break;
	    
	  } /* end of SWITCH */
	
	printf("\n\nResult = %d\n",r);
	
	digits_a = r;
	o = get_operator();
	
      } /* while o != clear */
    
    printf("\nEnter  n  to quit, or\n");
    printf("enter  y  to do another operation: ");
    
    a = getchar();
    
    if (a == 'y')
      {
	while (flush != '\n')
	  {
	    flush = getchar();
	  }
      }
  }while (a == 'y');

return 0;
}
static int _divisionByZeroTestFunction()
{
    int divisionByZero =  division(1, 0);
    FAIL(StringFromFormat("Should have divided by zero. Outcome: %d", divisionByZero).asCharString());
    return divisionByZero;
}
Exemple #24
0
int main()
{
    float a;
    float b;
    int opcion;
    float auxResultado;  ///variable auxiliar para llamar a la funcion dependiendo de lo que ingrese el usuario
    int flagA=0;         ///variable "FlagA" para determinar el ingreso del dato
    int flagB=0;         ///variable "FlagB" para determinar el ingreso del dato


    do
        {

		menuOpciones();
		scanf("%d",&opcion);

		switch(opcion)
        {

        case 1:
            printf("Ingrese el primer operando: ");
            scanf("%f",&a);
            if(a<=0 || a>=0)
            {
                flagA=1; ///Si se ingresa algun numero, se le asigna 1 a esta variable
            }

            break;

        case 2:
            printf("Ingrese el segundo operando: ");
            scanf("%f",&b);
            if(b<=0 || b>=0)
            {
                flagB=1; ///Si se ingresa algun numero, se le asigna 1 a esta variable
            }

            break;

        case 3:
            if(flagA==1 && flagB==1) ///Si ambos flags estan en 1, quiere decir que ambos operandos se ingresaron.
            {
                auxResultado=suma(a,b);
                printf("\n La suma de %.2f + %.2f es igual a %.2f \n",a,b,auxResultado);

            }
            else ///Si no, se informa el error y seguido de un ENTER "retorna" al menu.
            {
                printf("Error, faltan operandos.\n");
            }

            break;

        case 4:
            if(flagA==1 && flagB==1)
            {
                auxResultado=resta(a,b);
                printf("\n La resta de %.2f - %.2f es igual a %.2f \n",a,b,auxResultado);
            }

            else
            {
                printf("Error, faltan operandos.\n");
            }

            break;

        case 5:
            if(flagA==1 && flagB==1)
            {
                auxResultado=producto(a,b);
                printf("\n El producto de %.2f * %.2f es igual a %.2f \n",a,b,auxResultado);
            }
            else
            {
                printf("Error, faltan operandos.\n");
            }

            break;

        case 6:
            if(b==0)
            {
                printf("ERROR. No se puede dividir por 0.\n");
            }
            else
            {
                if(flagA==1 && flagB==1)
                {
                    auxResultado=division(a,b);
                    printf("\n La division %.2f / %.2f es igual a %.2f \n",a,b,auxResultado);
                }

                else
                {
                    printf("Error, faltan operandos.\n");
                }
            }



            break;

        case 7:
            if(flagA==1)///Se verifica que el flagA este en 1 (operando cargado).
            {
                if(a>=0)///Se verifica que no sea un numero negativo.
                    {
                    auxResultado=factorial_numero(a);
                    printf("\n El factorial del numero %.2f es: %.2f \n", a, auxResultado);
                    }
                else
                {
                    printf("\n No existe el factorial de un numero negativo. \n");
                }
            }
            else
            {
                printf("Falta el primer operando.\n");
            }

            if(flagB==1)
            {

                if(b>=0)
                    {
                        auxResultado=factorial_numero(b);
                        printf("\n El factorial del numero %.2f es: %.2f \n", b, auxResultado);
                    }

                else
                    {
                        printf("\n No existe el factorial de un numero negativo. \n");
                    }
            }

            else
               {
                   printf("Falta el segundo operando.\n");
               }

            break;

        case 8:

            if(flagA==1 && flagB==1 )///En este caso necesitamos de los dos flags(dos operandos cargados)para realizar todas las operaciones juntas.
            {
                //SUMA
                auxResultado=suma(a,b);
                printf("\n 3) La suma de %.2f + %.2f es igual a %.2f \n",a,b,auxResultado);

                //RESTA
                auxResultado=resta(a,b);
                printf("\n 4) La resta de %.2f - %.2f es igual a %.2f \n",a,b,auxResultado);

                //MULTIPLICACION
                auxResultado=producto(a,b);
                printf("\n 5) El producto de %.2f * %.2f es igual a %.2f \n",a,b,auxResultado);

                //DIVISION

                        if(b==0)
                        {
                            printf("\n 4) No se pudo calcular la division. Se ingreso 0 como divisor. \n");
                        }

                        else
                        {
                            auxResultado=division(a,b);
                            printf("\n 6) La division %.2f / %.2f es igual a %.2f \n",a,b,auxResultado);
                        }


                //FACTORIAL


                        if(a>=0)
                        {
                            auxResultado=factorial_numero(a);
                            printf("\n 7) El factorial del numero %.2f es: %.2f \n", a, auxResultado);
                        }

                        else
                        {
                            printf("\n 7) No existe el factorial de un numero negativo. \n");
                        }

                        if(b>=0)
                        {
                            auxResultado=factorial_numero(b);
                            printf("\n    El factorial del numero %.2f es: %.2f \n", b, auxResultado);
                        }

                        else
                        {
                            printf("\n    No existe el factorial de un numero negativo. \n");
                        }


                        break;
                        case 9:
                            printf("\n                             chau...\n");
                            break;
                        }

                        else
                        {
                            printf("Error, faltan operandos.\n");
                        }

        }///FIN SWITCH
            system("pause");
            system("cls");

            if(flagA==1)///Si al menos un operando est� cargado, se muestran en pantalla luego de limpiar.
            {
            printf("\n          ��������������������������������������������������������������� ");
            printf("\n               Primer OP: %.2f            Segundo OP: %.2f         ",a,b);
            }
        }///FIN DO
            while (opcion!=9);



            return 0;
}
int main()
{
    char seguir='s';//Variable para terminar el bucle while
    int opcion=0;//Opcion del menu
    float num1=0;
    float num2=0;
    /*Las variables num1 y num2 son los numeros ingresados por el
    usuario. Se inicializan en 0 para que no entre en el programa
    ningun dato basura que haya quedado en la direccion de memoria
    */

    while(seguir=='s')
    {
        printf("1- Ingresar 1er operando (A=%.2f)\n", num1);
        printf("2- Ingresar 2do operando (B=%.2f)\n", num2);
        printf("3- Calcular la suma (A+B)\n");
        printf("4- Calcular la resta (A-B)\n");
        printf("5- Calcular la division (A/B)\n");
        printf("6- Calcular la multiplicacion (A*B)\n");
        printf("7- Calcular el factorial (A!)\n");
        printf("8- Calcular todas las operacione\n");
        printf("9- Salir\n");

        scanf("%d",&opcion);

        system("cls");//Limpia la consola

        switch(opcion)
        {
            case 1://Pide el primer numero
                printf("Ingrese el 1er operando: ");
                scanf("%f", &num1);
                system("cls");
                continue;
            case 2://Pide el segundo numero
                printf("Ingrese el 2do operando: ");
                scanf("%f", &num2);
                system("cls");
                continue;
            case 3://Llama a la funcion suma y muestra el resultado
                printf("El resultado de la suma es: %.2f\n", suma(num1, num2));
                break;
            case 4://Llama a la funcion resta y muestra el resultado
                printf("El resultado de la resta es: %.2f\n", resta(num1, num2));
                break;
            case 5://Llama a la funcion division y muestra el resultado
                printf("El cociente de la division es: %.2f\n", division(num1, num2));
                break;
            case 6://Llama a la funcion multiplicacion y muestra el resultado
                printf("El producto de la multiplicacion es: %.2f\n", multiplicacion(num1, num2));
                break;
            case 7://Llama a la funcion factorial para cada operando y muestra los resultados
                factorial(num1);
                factorial(num2);
                break;
            case 8://Llama a todas las funciones y muestra todos los resultados
                printf("El resultado de la suma es: %.2f\n", suma(num1, num2));
                printf("El resultado de la resta es: %.2f\n", resta(num1, num2));
                printf("El producto de la multiplicacion es: %.2f\n", multiplicacion(num1, num2));
                printf("El cociente de la division es: %.2f\n", division(num1, num2));
                factorial(num1);
                factorial(num2);
                break;
            case 9://Salir del programa
                seguir = 'n';
                break;
            default://Verifica que se ingrese una opcion valida del menu
                printf("La opcion es invalida, por favor elija una opcion del menu.\n");
        }
        system("pause");//Congela la consola para ver el resultado
        system("cls");//Limpia la pantalla
        num1 = 0;//Vuelvo a asignarle 0 a las variables num1 y num2 para empezar el programa de nuevo
        num2 = 0;
    }
    return 0;
}
Exemple #26
0
int main()
{
	int choice,  res,  no1, no2, ch;
	double n, m, s1, s2, res1, ans, val, num;
	float x, y;
	double result = 0, n1 = 0, fradecimal;
	long y1;
	char c;
	char frabinary[100], hexa[MAX];
	long int binaryval;
	div_t1 temp;
	poly * poly1, * poly2, * poly3;
	FILE *fp;
	printf("\n\n....NEW USER FIRST READ THE MANUAL TEXT FILE TO UNDERSTANS THE FUNCTIONS USAGE....\n\n");
	while(1) {
		printmenu1();
		printf("Enter your choice\n");
		scanf("%d", &ch);
		switch(ch) {
			case 1:
			
				fp = fopen("Manual.txt", "r");
				if(!fp)
					printf("Cannot open file\n");
				while((c = fgetc(fp) )!= EOF)
					printf("%c", c);
					fclose(fp);
				break;
			case 2:
				while(1) {
					printmenu();
					printf("Enter your choice\n");
					scanf("%d" ,&choice);
					switch(choice) {
						case 1:
							printf(".....sqrt() function finds the square root of a number.....\n");	
							printf("Enter your number:\n");
							scanf("%lf", &n);
							m = sqrt(n); //square root
							if( m == 0) {
								printf(" You entered negative number\n");
								break;				
							}
							printf("square root is %.3lf\n", m);
							waita();
							break;
						case 2:
							printf(".....mod() finds remainder when one number is divided 									by 2nd 	number.....\n"); 
						
							printf("enter the number to be divided :\t\n");
							scanf("%lf",&s1);
							printf("enter the divisor:\t\n");
							scanf("%lf",&s2);
							ans = fmod(s1, s2); //remainder
							printf("remainder is : %lf\n", ans);
							waita();
							break;
						case 3:
							printf(".....fabs()  finds the absolute value of floating 									point number.....\n");
						
							printf("Enter the number to find the absolute value\n");
							scanf("%lf", &val);
							res1 = fabs(val);  //absolute value
							printf("The absolute value of %lf is %lf\n", val, res1);
							waita();
							break;
						case 4:
							printf(".....ceilx() function finds ceil value of a 									number.....\n");	
							printf("Enter the value\n");
							scanf("%lf", &val);
							ans = ceilx(val); //ceil function
							printf("Value=%lf\n", ans);
							waita();
							break;   
 	
						case 5:
							printf(".....floorx() function finds floor value of a 										number.....\n");	
							printf("Enter the value\n");
							scanf("%lf", &val);
   							ans = floorx(val); //floor function
							printf("Value=%lf\n", ans);
							waita();
							break;
						case 6:
							printf(".....expoential() function finds expoential value of a 									number 	i.e. e^x.....\n");
							printf("Enter the value of x\n");
    							scanf("%lf", &n);
   						        printf("e^x = %lf\n", exponential(n)); //exponential function
							waita();
							break;
						case 7:
							printf(".....hypot()finds the value of hypotenuse when two 									sides are given.....\n");
							
							printf("Enter sides: \n");
							scanf ("%lf %lf",&s1,&s2);
							printf("Hypotenus of %f %f is: %f\n", s1, s2,hypot(s1,s2)); 								//hypotenuse function
							waita();
							break;
						case 8: 
							printf(".....cbrt() finds the cube root of proper number i.e. 									cbrt(8)= 2.....\n"); 
						 
							printf("enter the number to find the cube root\n");
 							scanf("%lf",&n1);
 							if(n1 < 0) {
 	
 								 printf("enter only +ve integer value\n");
						  		 waita();
 								 break;
 							}
 							result = cbrtx(n1); //cube root function
 							if(result)
 								 printf("cube root of %lf is %lf\n",n1,result);
 								else {
								printf("not a proper value for finding the cube 										root\n");
								waita();
 								break;
							}	
							
							waita();
							break;
						case 9:
							printf(".....pow() function finds the x^y power.....\n");
							printf("Enter the number and the power\n");
							scanf("%lf%lf", &s1, &s2);
							res1 = Pow(s1, s2); //power function
							printf("The %lf^%lf is %lf\n", s1, s2, res1);
							
							waita();
							break;
						case 10:
							printf(".....trunc() function truncates the floating 									points.....\n");	
							printf("Enter the value for truncating\n");
							scanf("%lf", &s1);
							res1 = trunc(s1); // truncating a number
							printf("The value after truncating is %lf\n", res1);
							
							waita();
							break;
						case 11:
							printf(".....round() function rounds up a floating point 									number..... \n");
							printf("Enter the value for rounding\n");
							scanf("%lf", &s1);
							res1 = round(s1); //rounding a number
							printf("The value after rounding is %lf\n", res1);
							
							waita();
							break;
						case 12:
							printf(".....abs() function finds absolute value of integer 									number.....\n");
							printf("Enter the integer number to find the absolute value\n");
							scanf("%lf", &n);
							if(n - (int)n == 0) {
								res = abs(n);  //absolute value
								printf("The absolute value of %lf is %d\n", n, res);
								waita();
								break;
							}
							else {
								printf("Enter integer number\n");
								waita();
								break;
							}
							waita();
							break;
						case 13:
							printf(".....fmax() function finds maximum between two 									numbers.....\n");	
							printf("Enter two numbers to find maximun number\n");	
							scanf("%lf%lf", &s1, &s2);
							res1 = fmax(s1,s2);
							printf("The max number is %f\n",res1);
							waita();
							break;
						case 14:
							printf(".....fmin() function finds minimum between two 									numbers.....\n");	
							printf("Enter two numbers to find minimum number\n");	
							scanf("%lf%lf", &s1, &s2);
							res1 = fmin(s1,s2);
							printf("The min number is %f\n",res1);
							waita();
							break;
						case 15:
							printf(".....fdim()finds +ve difference bet^n 2 no's & if fails 									it returns 0.....\n"); 
						
							printf("Enter two numbers to find difference of two numbers\n");
							scanf("%lf%lf", &s1, &s2);
							res1 = fdim(s1,s2);
							if(res1 == 0) {
								printf("This functions returns 0 when  first number is 										less than or equal to second number\n");
								waita();
								break;
							}		
							printf("The positive Difference  is %f\n",res1);
							waita();
							break;
						case 16:
							printf(".....roundf() function rounds up a floating 										value.....		\n");	
							printf("Enter the value for rounding\n");
							scanf("%f", &x);
							y = roundf(x);
							printf("The value after rounding is %f\n", y);
							waita();
							break;
						case 17:
							printf(".....lround() function rounds up a long value.....\n");
							printf("Enter the value for rounding\n");
							scanf("%lf", &n);
							y1 = lround(n);
							printf("The value after rounding is %li\n", y1);
							waita();
							break;
						case 18:
							printf(".....add_poly() function adds two polynomials.....\n");
							printf("\nCreate 1st expression\n");
							create(&poly1);
							printf("\nStored the 1st expression");
							show(poly1);
		
							printf("\nCreate 2nd expression\n");
							create(&poly2);
							printf("\nStored the 2nd expression");
							show(poly2);
						
							add_poly(&poly3, poly1, poly2);
							show(poly3);
							waita();
							break;
						case 19:
							printf(".....sub_poly() function subtract two 											polynomials.....		\n");	
							printf("\nCreate 1st expression\n");
							create(&poly1);
							printf("\nStored the 1st expression");
							show(poly1);	
							printf("\nCreate 2nd expression\n");
							create(&poly2);
							printf("\nStored the 2nd expression");
							show(poly2);
	
							sub_poly(&poly3, poly1, poly2);
							show(poly3);
							waita();
							break;
						case 20:
							printf(".....division() function givesquotient and remainder 									after division.....\n");
							printf("Enter divident\n");
							scanf("%d", &no1);
							printf("Enter divisor\n");
							scanf("%d", &no2);
							temp = division(no1, no2);
							printf("quotient=%d\tremainder=%d\n", temp.quot, temp.rem);
							waita();
							break;			
						case 21:
							printf(".....ldexp() function returns value * 									2^expoential.....		\n");
							printf("Enter the value\n");
							scanf("%lf", &n);
							printf("Enter the integer exponent\n");
							scanf("%d", &no1);
							m = ldexp(n, no1);
							printf("value=%lf\n", m);	
							waita();
							break;;
						case 22:
							printf(".....exp2() function returns 2^expoential.....\n");
							printf("Enter the expoential\n");
							scanf("%lf", &n);
							m = exp2(n);
							printf("exp2(%lf)=%lf\n", n, m);
							waita();
							break;
						case 23:
							printf(".....tgamma() fuction calculates gamma value.....\n");
							printf("Enter the number to find gamma value\n");
							scanf("%lf", &num);
							if( num <= 0) {
								printf("Gamma of negative number and 0 is not 										defined		\n");	
								waita();
								break;
							}
							ans = tgamma(num);
							printf("gamma(%lf)=%lf\n", num, ans);
							waita();
							break;			
						case 24:
							printf(".....fact() function returns factorial of a 										number.....		\n");	
							printf("Enter number to find factorial\n");
							scanf("%lf", &n);
							ans = fact(n);
							printf("The factorial of %lf is %lf\n", n, ans);
							waita();
							break;
						case 25:
							printf(".....square() function calculates square of a 									number.....\n");	
							printf("Enter number to find square of entered number\n");
							scanf("%lf", &n);
							ans = square(n);
							printf("The square of %lf is %lf\n",n, ans);
							waita();
							break;
						case 26:
							printf(".....cube() function calculates cube of a 									number.....		\n");	
							printf("Enter number to find cube of a entered number\n");
							scanf("%lf", &n);
							ans = cube(n);
							printf("The cube of %lf is %lf\n",n, ans);
							
							waita();
							break;
						case 27:
							printf("dec_bin() function converts decimal number into 								binary			\n");
							printf("Enter any fractional Decimal number\n");
							scanf("%lf", &fradecimal);
							printf("eduivalent binary value is %lf\n",dec_bin(fradecimal));
							waita();
							break;
						case 28:
							printf("bin_dec() function converts binary number into 								decimal 		\n");
							printf("Enter any fractional Binary number\n");
							scanf("%s", frabinary);
							printf("eduivalent decimal value is %lf\n",bin_dec(frabinary));
							waita();
							break;
						case 29:
							printf("This fun. converts decimal number to octal number\n");
							printf("Enter a decimal number:\n ");
       							scanf("%d", &no1);
       							printf("%d in decimal = %d in octal\n", no1, 									decimal_octal(no1));	
							waita();
							break;
						case 30:
							printf("This fun. converts octal number to decimal number\n");
							printf("Enter a octal number:\n ");
       							scanf("%d", &no1);
       							printf("%d in octal = %d in decimal\n", no1, 									decimal_octal(no1));	
							waita();
							break;
						case 31:
							printf("This fun. converts binary number to octal number\n");
							printf("Enter a binary number:\n ");
       							scanf("%d",&no1);
        						printf("%d in binary = %d in octal\n", no1, binary_octal(no1));
							waita();
							break;
						case 32:
							printf("This fun. converts octal number to binary number\n");
							printf("Enter a octal number:\n ");
        						scanf("%d",&no1);
        						printf("%d in octal = %d in binary\n",no1, octal_binary(no1));
							waita();
   
							break;
						case 33:
							printf("This function converts binary into hex number\n");
							printf("Enter the binary number:\n ");
    							scanf("%ld", &binaryval);
    
    							printf("Equivalent hexadecimal value: %lX\n", 									binary_hex(binaryval));
							waita();
							break;
						case 34:
							printf("This function converts hex into binary number\n");
							printf("Enter the value for hexadecimal\n ");
    							scanf("%s", hexa);
   							hex_binary(hexa);
							waita();
							break;
						case 35:
							return 0;
						default:
							printf(".....wrong choice.....\n");
					}	
				}	
			case 3:	
				return 0;
			default:
				printf("Invalid Choice\n");
			}	
			
		} 
		return 0;		
	}