Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Implementar uma calculadora de 4 operações (cada uma das operações deve ser uma
- função ou procedimento independente). Solicitar do usuário 2 números e 1 operador
- em outro procedimento de entrada (tratar o caso de operador desconhecido).
- Imprimir na tela o resultado.*/
- #include <stdio.h>
- #include <stdlib.h>
- float sum(float x, float y);
- float sub(float x, float y);
- float div(float x, float y);
- float mul(float x, float y);
- void input(float *x, float *y, char *op);
- void main(){
- float x, y;
- char op;
- printf("CALCULATOR POWER 2k BY RAFAEL GIBIM\n");
- printf("Digite dois numeros e a operação que deseja realizar\n");
- printf("+: soma\n-: subtracao\n/: divisao\n*: multiplicacao\n");
- input(&x, &y, &op);
- printf("\n%f %c %f = ",x, op, y);
- switch(op){
- case '+':
- printf("%f",sum(x,y));
- break;
- case '-':
- printf("%f",sub(x,y));
- break;
- case '*':
- printf("%f", mul(x,y));
- break;
- case '/':
- printf("%f", div(x,y));
- break;
- }
- printf("\n\n");
- system("Pause");
- }
- void input(float *x, float *y, char *op){
- printf ("n1: ");
- scanf("%f", &*x);
- printf ("n2: ");
- scanf("%f", &*y);
- do{
- fflush(stdin);
- printf ("op: ");
- scanf("%c", &*op);
- if(*op != '+' && *op != '-' && *op != '*' && *op != '/') printf("error: invalid operator");
- }while(*op != '+' && *op != '-' && *op != '*' && *op != '/');
- }
- float sum(float x, float y){
- return x+y;
- }
- float sub(float x, float y){
- return x-y;
- }
- float mul(float x, float y){
- return x*y;
- }
- float div(float x, float y){
- return x/y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement