#include <stdio.h>int main() { int num1, num2, c; printf("\n Seleccione un numero"); printf("\n 1. Suma"); printf("\n 2. Resta"); printf("\n 3. Multiplicar"); printf("\n 4. Dividir"); printf("\n Introduzca el valor que desee "); c = getchar(); switch(c) { case '1': goto SUMAR; break; case '2': goto RESTAR; break; case '3': goto MULTIPLICAR; break; case '4': goto DIVIDIR; break; case '\n': printf("\n Introduce un valor"); break; default: printf("\n Introduce un numero valido"); break; } SUMAR: num1 = getchar(); num2 = getchar(); printf("\n La suma de los dos numeros es %d", num1 + num2); RESTAR: num1 = getchar(); num2 = getchar(); printf("\n La suma de los dos numeros es %d", num1 - num2); MULTIPLICAR: num1 = getchar(); num2 = getchar(); printf("\n La suma de los dos numeros es %d", num1 * num2); DIVIDIR: num1 = getchar(); num2 = getchar(); printf("\n La suma de los dos numeros es %d", num1 / num2); return 0;}
#include <stdio.h>#include <stdlib.h>float suma(float a, float b){ float res; res = a+b; return res;}float resta(float a, float b){ float res; res = a-b; return res;}float mult(float a, float b){ float res; res = a*b; return res;}float dividir(float a, float b){ float res; res = a/b; return res;}int main() { int num; float c,d,real; do{ printf("\n Seleccione un numero"); printf("\n 1. Suma"); printf("\n 2. Resta"); printf("\n 3. Multiplicar"); printf("\n 4. Dividir"); printf("\n Introduzca el valor que desee "); fflush(stdout); scanf("%d",&num); while(getchar()!='\n'); switch(num) { case 1: printf("Introduzca primer sumando\n"); fflush(stdout); scanf("%f",&c); while(getchar()!='\n'); printf("Introduzca segundo sumando\n"); fflush(stdout); scanf("%f",&d); while(getchar()!='\n'); real=suma(c,d); printf("El resultado de sumar %f y %f es: %f\n",c,d,real); fflush(stdout); system("pause"); system("cls"); break; case 2: printf("Introduzca minuendo\n"); fflush(stdout); scanf("%f",&c); while(getchar()!='\n'); printf("Introduzca sustraendo\n"); fflush(stdout); scanf("%f",&d); while(getchar()!='\n'); real=resta(c,d); printf("El resultado de restar %f y %f es: %f\n",c,d,real); fflush(stdout); system("pause"); system("cls"); break; case 3: printf("Introduzca primer numero\n"); fflush(stdout); scanf("%f",&c); while(getchar()!='\n'); printf("Introduzca segundo numero\n"); fflush(stdout); scanf("%f",&d); while(getchar()!='\n'); real=mult(c,d); printf("El resultado de multiplicar %f y %f es: %f\n",c,d,real); fflush(stdout); system("pause"); system("cls"); break; case 4: printf("Introduzca primer numero\n"); fflush(stdout); scanf("%f",&c); while(getchar()!='\n'); printf("Introduzca segundo numero\n"); fflush(stdout); scanf("%f",&d); while(getchar()!='\n'); real=dividir(c,d); printf("El resultado de dividir %f y %f es: %f\n",c,d,real); fflush(stdout); system("pause"); system("cls"); break; } }while(num<5); return 0;}