Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /******************************************************************************
- C program
- *******************************************************************************/
- int main()
- {
- setvbuf(stdout, 0, _IONBF, 0);
- setvbuf(stdin, 0, _IONBF, 0);
- int x = 0;
- int y = 0;
- int z = 0;
- int cont = 1;
- int option = 0;
- printf("Please enter a number: ");
- scanf("%d", &x);
- printf("Please enter a number: ");
- scanf("%d", &y);
- while (1){
- printf("Would you like to \n");
- printf("1) Take the sum? \n");
- printf("2) Take the product? \n");
- printf("3) Take the difference? \n");
- printf("4) Take the quotient? \n");
- printf("5) Get the remainder? \n");
- printf("6) Compare both integers? \n");
- printf("7) Compare Three integers? \n");
- printf("8) Even or odd? \n");
- printf("9) Is the first the multiple of the second? \n");
- printf("0) Exit \n");
- printf("Please enter an option: ");
- scanf("%d \n", &option);
- //The is a bug on the terminal after you enter the the scanf for option variable. The terminal asks for input, that then
- //enters the next input into the cont variable. Which it should not be calling and effects the code later
- //The scanf also requests later when called apon by the scanf for cont
- //Sum
- if(option == 1){
- int full = x + y;
- printf("The sum of %d and %d is %d \n", x,y,full);
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 1){
- }
- else if (cont == 0){
- break;
- }
- }
- //Product
- if(option == 2){
- int full = x * y;
- printf("The product of %d and %d is %d \n", x,y,full);
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 1){
- }
- else if (cont == 0){
- break;
- }
- }
- //Difference
- if(option == 3){
- int full = x - y;
- printf("The sum of %d and %d is %d \n", x,y,full);
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 1){
- }
- else if (cont == 0){
- break;
- }
- }
- //Quotient
- if(option == 4){
- int full = x/y;
- printf("The quotient of %d/%d is %d \n", x,y,full);
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 1){
- }
- else if (cont == 0){
- break;
- }
- }
- //Remainder
- if(option == 5){
- float full = x % y;
- printf("The remainder of %d and %d is %f \n", x,y,full);
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 1){
- }
- else if (cont == 0){
- break;
- }
- }
- //Compare two integers
- if(option == 6){
- if (x > y)
- printf("First number is %d which is greater than the second number which is %d \n",x,y);
- else if (x < y)
- printf("Second number is %d which is greater than the first number which is %d \n",y,x);
- else
- printf("Both numbers are equal to %d \n", x);
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 1){
- }
- else if (cont == 0){
- break;
- }
- }
- //Compare three integers
- if(option == 7){
- printf("Enter a third number to compare with %d and %d :",x,y);
- scanf("%d \n", &z);
- int max = x;
- int min = x;
- //Max
- if (x > max){
- max = x;
- }
- if (y > max){
- max = y;
- }
- if (z > max){
- max = z;
- }
- //Min
- if (x < min){
- min = x;
- }
- if (y < min){
- min = y;
- }
- if(z < min){
- min = z;
- }
- printf("The max is %d \n",max);
- printf("The min is %d \n",min);
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 1){
- }
- else if (cont == 0){
- break;
- }
- }
- //Even or Odd
- if(option == 8){
- if (x % 2 == 0){
- printf("%d is Even\n", x);
- }
- else{
- printf("%d is Odd\n", x);
- }
- if (y % 2 == 0){
- printf("%d is Even\n", y);
- }
- else{
- printf("%d is Odd\n", y);
- }
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 1){
- }
- else if (cont == 0){
- break;
- }
- }
- //First a multiple of the second
- if(option == 9){
- if (x % y == 0){
- printf("%d is a multiple of %d\n", y, x);
- }
- else{
- printf("%d is not a multiple of %d\n", y, x);
- }
- printf("Press enter 1 to continue or enter 0 to exit: ");
- scanf("%d \n", &cont);
- if (cont == 0){
- return 0;
- }
- }
- //Exit
- if(option == 0 || cont == 0){
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement