예제 #1
0
파일: Division2.c 프로젝트: ad1cted/UTEM
int main ()
{
    int a, b, c,r;
    printf("Ingrese numero a : ");
    scanf("%d",&a);
    printf("Ingrese numero b : ");
    scanf("%d",&b);
    Division(a,b,&c,&r);
    printf("Cuociente es %d\n",c);
    printf("Resto     es %d\n",r);
   
        
    system("pause");
}
예제 #2
0
//Llamar a la funcion
main ()
{
	float a,b;
   cout<<"Operacion Suma"<<endl;
	cout<<"Dar Num_uno"<<endl;
	cin>> a;
	cout<<"Dar Num_dos"<<endl;
	cin>> b;
	cout<<"El resultado es "<<Suma (a,b)<<endl;
   cout<<" "<<endl;

   float c,d;
   cout<<"Operacion Resta"<<endl;
	cout<<"Dar Num_uno"<<endl;
	cin>> c;
	cout<<"Dar Num_dos"<<endl;
	cin>> d;
	cout<<"El resultado es "<<Resta (c,d)<<endl;
   cout<<" "<<endl;

   float g,h;
   cout<<"Operacion Producto"<<endl;
	cout<<"Dar Num_uno"<<endl;
	cin>> g;
	cout<<"Dar Num_dos"<<endl;
	cin>> h;
	cout<<"El resultado es "<<Producto (g,h)<<endl;
   cout<<" "<<endl;

   float i,j;
   cout<<"Operacion Division"<<endl;
	cout<<"Dar Num_uno"<<endl;
	cin>> i;
	cout<<"Dar Num_dos"<<endl;
	cin>> j;
	cout<<"El resultado es "<<Division (i,j)<<endl;
   cout<<" "<<endl;

	getch ();
}
예제 #3
0
ClassLong ClassLong::operator%(unsigned long long int value) 
{
	return Division(this->number, InputNumber(value), 2);
}
예제 #4
0
ClassLong ClassLong::operator%(const ClassLong &right) 
{
	return Division(this->number, right.number, 2);
}
예제 #5
0
Constante* Eval::getValue() const {
    Expression* exp = dynamic_cast<Expression*>(c);
    QStack<Constante*> p;
    if (exp != NULL){
        int i = 0;
        QString s = exp->getExp();
        Constante * result = 0;
        while(i<s.length()){
            //on passe les espaces;
            if(s[i] == ' '){
                if(result != 0){
                    p.push(result);
                    result = 0;
                }
            }
            else if(s[i] >= '0' && s[i] <= '9'){
                if(result == 0)result = Addition(Rationnel(0),Rationnel(0),mModeConstante, mModeComplexes).getValue();
                result->addChiffre(s[i].toAscii() - '0');
            }
            else if(s[i] == '$'){
                if(result == 0) throw EvalException("$ mal placé");
                result->setDollarEntre();
            }
            else if(s[i] == '/'){
                if(result != 0){
                    result->setSlashEntre();
                }
                else{
                    if(p.size() < 2) throw EvalException("Pas assez d'opérandes pour /");
                    Constante *op2 = p.pop(),  *op1 = p.pop();
                    try{
                        result = Division(*op1,*op2,mModeConstante,mModeComplexes).getValue();
                    }
                    catch(DivException e){
                        throw EvalException("division par zéro");
                    }

                    delete op1;
                    delete op2;
                    p.push(result);
                    result = 0;
                }
            }
            else if(s[i] == ',' || s[i] == '.'){
                if(result == 0) throw EvalException(", ou . mal placé");
                result->setVirguleEntree();
            }
            else if(s[i] == '+'){
                if(result!=0){
                    p.push(result);
                    result = 0;
                }
                if(p.size() < 2) throw EvalException("Pas assez d'opérandes pour +");
                Constante *op1 = p.pop(),  *op2 = p.pop();
                result = Addition(*op1,*op2,mModeConstante,mModeComplexes).getValue();
                delete op1;
                delete op2;
                p.push(result);
                result = 0;
            }
            else if(s[i] == '-'){
                if(result!=0){
                    p.push(result);
                    result = 0;
                }
                if(p.size() < 2) throw EvalException("Pas assez d'opérandes pour -");
                Constante *op2 = p.pop(),  *op1 = p.pop();
                result = Soustraction(*op1,*op2,mModeConstante,mModeComplexes).getValue();
                delete op1;
                delete op2;
                p.push(result);
                result = 0;
            }
            else if(s[i] == '*'){
                if(result!=0){
                    p.push(result);
                    result = 0;
                }
                if(p.size() < 2) throw EvalException("Pas assez d'opérandes pour *");
                Constante *op2 = p.pop(),  *op1 = p.pop();
                result = Multiplication(*op1,*op2,mModeConstante,mModeComplexes).getValue();
                delete op1;
                delete op2;
                p.push(result);
                result = 0;
            }
            else{
                throw EvalException("Caractère inconnu");
            }
            i++;
        }
        if(result!=0)p.push(result);
        if(p.size() > 1) throw EvalException("Il manque un opérateur.");
        if(p.size() < 1) throw EvalException("Pile d'évaluation vide.");
        return p.at(0);
    }
    else throw TypeConstanteException("Ceci n'est pas une expression");
}
예제 #6
0
void main()	// main function
{
	int menu, result[100], total=0, count=0;
	char con;
	struct tm time;
		_getsystime(&time);
	int hr, min, sec;

	hr = time.tm_hour;
	min = time.tm_min;
	sec = time.tm_sec;

	int i=0;
	do
	{
		// Menu
		system("CLS");
		printf("_-_-_-_Menu_-_-_-_\n"
			   "[1] Multiplication\n"
			   "[2] Division\n"
			   "[3] Addition\n"
			   "[4] Subtraction\n"
			   "[5] Quit\n\n");

		printf("Choose a selection > ");
		scanf("%d",&menu);

		switch(menu)	// switch statement
		{
		case 1:
			{
				result[i] = Multiplication();	// function call Multiplication();
				output(result[i]);	// function call output();
				count++;	// the times of test
				break;
			}
		case 2:
			{
				result[i] = Division();	// function call Division();
				output(result[i]);	// function call output();
				count++;	// the times of test
				break;
			}
		case 3:
			{
				result[i] = Addition();	// function call Addition();
				output(result[i]);	// function call output();
				count++;	// the times of test
				break;
			}
		case 4:
			{
				result[i] = Subtraction();	// function call Subtraction();
				output(result[i]);	// function call output();
				count++;	// the times of test
				break;
			}
		case 5:
			{
				Quit(total,count,hr,min,sec);	// function call Quit();
				break;
			}
		default:
			{
				printf("Invalid Input! Please re-enter\n");
				main();	// re-run the main function
			}
			i++;
		}
		total = total + result[i];	// sum all the tests' marks
		// ask for user want to continue the test or not
		printf("Do you want to continue? (Y/N) ");
		fflush(stdin);
		scanf("%c",&con);
		toupper(con);
		while(con!='Y' && con!='N' && con!='y' && con!='n')
			{
				printf("Invalid Input! Please re-enter (Y/N)> ");
				fflush(stdin);
				scanf("%c",&con);
				toupper(con);
			}
	}while(con == 'Y' || con=='y');
	Quit(total,count,hr,min,sec);	// Print out the total result & Quit the program
}
예제 #7
0
// PROGRAMA PRINCIPAL
int main(){
	bind_textdomain_codeset ("calculadora", "UTF-8");
	setlocale(LC_ALL,"");
	bindtextdomain("calculadora", "idioma");
	textdomain("calculadora");	
	
	double a, b, resultado;
	long resexp;
	int Opcion;
	char buffer[9];

    while(1){
	printf(_("\n\t\tCALCULATOR\n\n"));
	printf(_("\t 1.- Sum\n"));
	printf(_("\t 2.- Subtraction\n"));
	printf(_("\t 3.- Multiplication\n"));
	printf(_("\t 4.- Division\n"));
	printf(_("\t 5.- Square Root\n"));
	printf(_("\t 6.- Pow\n"));
	printf(_("\t 7.- Natural Logarithm\n"));
	printf(_("\t 8.- Sine\n"));
	printf(_("\t 9.- Cosine\n"));
	printf(_("\t 10.-Tangent\n"));
	printf(_("\t 11.-arc sine\n"));
	printf(_("\t 12.-Arc Cosine\n"));
	printf(_("\t 13.-Arc Tangent\n"));
	printf(_("\t 14.-Ceil\n"));
	printf(_("\t 15.-Arc Tangent (two parameters\n"));
    printf(_("\t 16.-Hyperbolic Cosine\n"));
    printf(_("\t 17.-Hyperbolic Sine\n"));
    printf(_("\t 18.-Hyperbolic Tangent\n"));
    printf(_("\t 19.-Exponential\n"));
    printf(_("\t 20.-Frexp\n"));
    printf(_("\t 21.-Idexp\n"));
    printf(_("\t 22.-Logarithm base ten\n"));
    printf(_("\t 23.-Modf\n"));
    printf(_("\t 24.-Absolute value\n"));
    printf(_("\t 25.-Floor\n"));
    printf(_("\t 26.-Fmod\n"));
	printf(_("\t\t Choose your option: "));
    

    scanf("%s", buffer);

    if( validar_es_entero(buffer, &Opcion) != true )
        Opcion = 999;

    resultado = 0.0;
	switch (Opcion)
	{
	   case 1:
		   resultado = Suma (a, b);
	   break;

  	   case 2:
	   	resultado = Resta (a, b);
	   break;


	   case 3:
	   	resultado = Multiplicacion (a, b);
	   break;


	   case 4:
	   	resultado = Division (a, b);
       break;

       case 5:
	   	resultado = Raiz_cuadrada (a);
 	   break;
      
      case 6:
	   	resexp = Potencia (a, b);
		printf(_("\n The result of the chosen option: "));
		printf(" %ld ",resexp);
 	   break;
      
      case 7:
	   	resultado = Logaritmo (a);
 	   break;
 	   
 	   case 8:
	   	resultado = Seno (a);
 	   break;
 	   
 	   case 9:
	   	resultado = Coseno (a);
 	   break;
 	   
 	   case 10:
	   	resultado = Tangente (a);
 	   break;
 	   
 	   case 11:
	   	resultado = Arcseno (a);
 	   break;
 	   
 	   case 12:
	   	resultado = Arccoseno(a);
 	   break;

           case 13:
	   	resultado = Arctangente(a);
 	   break;
 	   
 	   case 14:
	   	resultado = Ceil(a);
 	   break;
	   case 15:
	   	resultado = ArcoTangente2(a,b);
 	   break;
           case 16:
	   	resultado = CosenoHiperbolico(a);
 	   break;

           case 17:
	   	resultado = SenoHiperbolico(a);
 	   break;
           case 18:
	   	resultado = TangenteHiperbolico(a);
 	   break;
           case 19:
	   	resultado = Exponencial(a);
 	   break;
 	   
 	   case 20:
	   	resultado = Frexp(a,b);
 	   break;
 	   
 	   case 21:
	   	resultado = Idexp(a,b);
 	   break;
 	   
 	   case 22:
	   	resultado = LogB10(a);
 	   break;
 	   
 	   case 23:
	   	resultado = Modf(a,b,resultado);
 	   break;
 	   
 	   case 24:
	   	resultado = ValorAbsoluto(a);
 	   break;
 	   
 	   case 25:
	   	resultado = Fmod(a,b, resultado);
 	   break;
 	  
	   case 26:
	   	resultado = Floor(a);
 	   break; 
 	   
       default:
          Opcion = 999;
         printf(_("Invalid option , try again only digits."));
	   }

       if(Opcion<999)
            printf(_("\n The result of the chosen option: "));
		printf("%lf \n",resultado);		
  
  }

    
  

}
예제 #8
0
int main()
{
    // Part One:


    // FIXME: Declare variables
    // Declare two variables: an integer named "age", and a string named "name" with corresponding values (your name and age)
    int age = 19;
    char name[] = "Stan";

    // FIXME: Print
    // Print the following sentence in the console "You are NAME and you are AGE years old !". Don't forget to add a newline at the end
    printf("You are %s and you are %d years old !\n", name, age);

    // FiXME: Concatenation
    // Create a new string variable called "hello" which value is "Hello ". Add "name" at the end of "hello" (Concatenation) then print it
    char hello[] = "Hello ";
    strcat(hello, name);
    printf("%s\n", hello);

    // FIXME: Array
    // create a new string array called "shoppingList", with three elements of your choice. Create an int variable containing the number of
    // elements in "shoppingList" (using a function of the array/using the array)
    char *shoppingList[3] = {"milk", "a Chevy Camaro", "a life"};
    const int nbOfElements = numberOfElements(shoppingList);

    // FIXME: For-loop - Integer
    // Create a simple for-loop for an integer "i" going from 1 to 10 that print the value of "i"
    for (int i = 0; i < 10; i++)
        printf("%d ", i);
    printf("\n");

    // FIXME: For-loop - shoppingList
    // Create a for loop that iterate through "shoppingList" and prints each element with "You have to buy (elemt)".
    for (int j = 0; j <nbOfElements; j++)
        printf("You have to buy %s\n", shoppingList[j]);


    // FIXME: Foreach-loop
    // Do the same with a foreach-loop.
    // The C programming language doesn't have a foreach, but you can look for macros if you are
    // curious.



    // FIXME: If-statement
    // Modify the first for-loop (with i from 1 to 10) such that it prints "(value of i) is even" when "i" is divisible
    // by 2 (You may want to learn more about "modulo" (%)). Else, print "(value of i) is odd".
    for (int i = 0; i < 10; i++)
    {
        if (i % 2)
            printf("%d is odd\n", i);
        else
            printf("%d is even\n", i);
    }



    // FIXME: Sum Up
    // Create a string variable called "element" with the value of your choice. Then create a for-loop/foreach-loop that checks if "shoppingList"
    // contains "element". If yes, print "You have to buy (value of element) !", and stop the loop (search how to stop a loop).
    // If not, print "Nope, you don't need (value of "element")".
    char element[] = "a life";
    for (int k = 0; k < nbOfElements; k++)
    {
        if (strcmp(element, shoppingList[k]) == 0)
        {
            printf("You have to buy %s !\n", shoppingList[k]);
            break;
        }
        else
        {
            printf("Nope, you don't need %s !\n", shoppingList[k]);
        }
    }



    // Part Two:


    // FIXME: Functions - Ascii
    // Create a function that returns nothing and which doesn't takes any parameter. It should just be named "TriForce"
    // and print the TriForce symbol (one triangle over two other ones, can be found on internet) with "TRIFORCE"
    // Don't forget to call the function !
    TriForce(); //Calling the functions in main()


    // FIXME: Functions - One parameter
    // Create a function that takes a string as parameter and returns "Hello (value of string) !"
    // http://stackoverflow.com/questions/1745726/how-to-store-printf-into-a-variable
    printf("%s", Hello("Stan"));

    // FIXME: Functions - Multiple parameters
    // Create a function that takes two integers as parameters and returns the addition of these two.
    // You can do the same with multiplication, subtraction and division.
    printf("%d\n", Addition(5, 12));
    printf("%d\n", Subtraction(5, 12));
    printf("%d\n", Multiplication(5, 12));
    printf("%d\n", Division(5, 12)); // returns 0 because "a" and "b" are Integers
    printf("%d\n", Division(10, 2));


    // FIXME: User entry
    // Create a string variable that takes what the user enter in the console as value. Then print "You entered (value of string)"
    char userInput[100]; // 100 will be the max length of the input
    printf("Enter a word:");
    scanf("%s", userInput);
    printf("You entered %s\n", userInput);


    // FIXME: While loop
    // Create a while loop that takes a number and divides it by 2 until it is less than 3
    int number = 52;
    while (number > 3)
    {
        number /= 2; //or number = number / 2;
        printf("%d ", number);
    }
    printf("\n");



    // FIXME: do-While loop
    // Do the same with a do-while loop
    int number2 = 84;
    do
    {
        number2 = number2 / 2;
        printf("%d ", number2);
    } while (number2 > 3);
    printf("\n");



    // FIXME: Random generator
    // Create a function that returns a random number
    srand((unsigned)time(NULL)); // time used for seeding
    printf("%d\n", rdm());


    // FIXME: Random generator with bounds
    // Create another function that returns a random number between two bounds given as parameters.
    printf("%d\n", rdmBounds(10, 20));



    // FIXME: Multi-dimensionnal array
    // Create a two dimensionnal int array of 3 columns and 3 rows. Use 2 for-loops to add a random number
    // between 1 and 9 in each of the 9 rooms.
    // You may use one of the two previously created function.
    // Then print them such that they appear like this (with [x1, x9] being the 9 random integers):
    // {x1, x2, x3, }
    // {x4, x5, x6, }
    // {x7, x8, x9, }
    int multiArray[3][3];
    for (int l = 0; l < numberOfElements(multiArray); l++)
        for (int m = 0; m < numberOfElements(multiArray[l]); m++)
            multiArray[l][m] = rdmBounds(1, 9);

    for (int n = 0; n < numberOfElements(multiArray); n++)
    {
        printf("{");

        for (int o = 0; o < numberOfElements(multiArray[n]); o++)
            printf("%d, ", multiArray[n][o]);

        printf("}\n");
    }

    // FIXME: Switch
    // Create a Switch that takes an integer "a" and return a sentence regarding the value of a
    // (Create 3 statements for 3 specific values and a default one)

    int a = 2;

    switch(a)
    {
    case 0:
        printf("a is 0\n");
        break;

    case 2:
        printf("a is 2\n");
        break;

    case 37:
        printf("Who cares about a anyway ?");
        break;

    default:
        printf("I don't know what \"a\" is... :'(\n");
        break;
    }

    // FIXME: logic Gates
    // Create 7 functions for each logic gates (And (0), Or (1), No (2), Nand (3), Nor (4), Xnor (5), Xor (6)).
    // Each function takes two booleans as parameters and returns the result of the logic gate.
    // (or You can do it with a switch and only one function)

    logic_gates(1, 0, 1);
    logic_gates(1, 1, 1);
    logic_gates(1, 2, 1);

    // FIXME - Reverse
    // Create a function that reverse a string

    reverse("Hello world");
    return 0;
}
예제 #9
0
int main(int argc, const char * argv[])
{
	if (argc < 5) 
	{
        printf("Error: Too few arguments. <first_long_number_filename> [ + | - | * | / | % | ^ ] <second_long_number_filename> <result_long_number_filename>\n");
        return 0;
    }
    
    if (argc > 7) 
	{
        printf("Error: Too many arguments. <first_long_number_filename> [ + | - | * | / | % | ^ ] <second_long_number_filename> <result_long_number_filename> <module_long_number_filename> <-b>\n");
        return 0;
    }
    
    FILE* firstLongNumFile = fopen(argv[1], "r");
    if (!firstLongNumFile) 
	{
        printf("Error: Unable to open file: %s \n", argv[1]);
        return 0;
    }
	fclose(firstLongNumFile);

    const char* operation = argv[2];
    if ((strlen(operation) > 1 || operation[0] == '\0') || operation[0] != '+' && operation[0] != '-' && operation[0] != 'u' && operation[0] != '/' && operation[0] != '%' && operation[0] != 'd') 
	{
        printf("Error: Wrong operation: %s \n", operation);
        return 0;
    }
    
    FILE* secondLongNumFile = fopen(argv[3], "r");
    if (!secondLongNumFile) 
	{
        printf("Error: Unable to open file: %s \n", argv[3]);
        return 0;
    }
    fclose(secondLongNumFile);

	FILE* resultLongNumFile = fopen(argv[4], "r");
    if (!resultLongNumFile) 
	{
        printf("Error: Unable to open file: %s \n", argv[4]);
        return 0;
    }
    fclose(resultLongNumFile);

	int bin = 0;

	if (argc == 5)
		if (argv[2][0] == 'd')
		{
			printf("Error: Input module file\n");
			return 0;
		}

    if (argc == 6) 
	{
		if (argv[2][0] == 'd')
		{
			FILE* moduleLongNumFile = fopen(argv[5], "r");
			if (!moduleLongNumFile) 
			{
				printf("Error: Unable to open file: %s \n", argv[5]);
				return 0;
			}
			fclose(moduleLongNumFile);
		}
		else
		{
			if (strcmp(argv[5], "-b")) 
			{
				printf("Error: Invalid flag: %s \n", argv[5]);
				return 0;
			}
			bin = 1;
		}
		
    }

	if (argc == 7) 
	{
		FILE* moduleLongNumFile = fopen(argv[5], "r");
		if (!moduleLongNumFile) 
		{
			printf("Error: Unable to open file: %s \n", argv[5]);
			return 0;
		}
		fclose(moduleLongNumFile);

        if (strcmp(argv[6], "-b")) 
		{
            printf("Error: Invalid flag: %s \n", argv[6]);
            return 0;
        }
		bin = 1;
    }
    
	struct LongNumber a,b;

  if(bin == 1)
		a = InputBinFile(argv[1]);
	else
		a = InputTextFile(argv[1]);
    
  if(bin == 1)
		b = InputBinFile(argv[3]);
	else
		b = InputTextFile(argv[3]);
    
  
    struct LongNumber result;
    
    switch (operation[0]) {
        case '+':
        {
            result = Sum(a, b);
            break;
        }
        case '-':
        {
            result = Subtracting(a, b);
            break;
        }
        case 'u':
        {
            result = Multiplication(a, b);
            break;
        }
        case '/':
        {
            result = Division(a, b, 1);
            break;
        }
        case '%':
        {
            result = Division(a, b, 2);
            break;
        }
        case 'd':
        {
			struct LongNumber c;
            if(bin == 1)
				c = InputBinFile(argv[5]);
			else
				c = InputTextFile(argv[5]);

			result = Degree(a, b, c);
			free(c.digit);
            break;
        }
        default:
            break;
    }
     
    if (bin == 1)
		OutputBinFile(argv[4], result);
	else
		OutputTextFile(argv[4], result);

    free(a.digit);
    free(b.digit);
    free(result.digit);

	return 0;
}