Sunteți pe pagina 1din 6

#include <stdio.

h>

int main(void)
{
float num1,
num2;
char oper;

do
{
printf("\t\tCalculadora do curso C Progressivo\n\n");

printf("Operacoes disponiveis\n");
printf("'+' : soma\n");
printf("'-' : subtracao\n");
printf("'*' : multiplicao\n");
printf("'/' : divisao\n");
printf("'%%' : resto da divisao\n");

printf("\nDigite a expressao na forma: numero1 operador


numero2\n");
printf("Exemplos: 1 + 1 , 2.1 * 3.1\n");
printf("Para sair digite: 0 0 0\n");

scanf("%f", &num1);
scanf(" %c",&oper);
scanf("%f", &num2);

system("cls || clear");

printf("Calculando: %.2f %c %.2f = ", num1,oper,num2);

switch( oper )
{
case '+':
printf("%.2f\n\n", num1 + num2);
break;

case '-':
printf("%.2f\n\n", num1 - num2);
break;

case '*':
printf("%.2f\n\n", num1 * num2);
break;

case '/':
if(num2 != 0)
printf("%.2f\n\n", num1 / num2);
else
printf("Nao existe divisao por 0\n\n");
break;

case '%':
printf("%d\n\n", (int)num1 % (int)num2);
break;

default:
if(num1 != 0 && oper != '0' && num2 != 0)
printf(" Operador invalido\n\n ");
else
printf(" Fechando calculadora!\n ");
}

}while(num1 != 0 && oper != '0' && num2 != 0);

#include<stdio.h>
#include<stdlib.h>

float soma(float a,float b);


float subtracao(float a,float b);
float divisao(float a,float b);
float multiplicacao(float a,float b);
float dobro(float a);
float triplo(float a);
float quadrado(float a);
float potencia(float a,float b);
float media (float a,float b);

main()
{
int op=1;
float x,y,total;

do
{
system("cls");
printf("\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",218,196,196,196,1
96,196,194,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,191);
printf("\t%c 1 %c\tSoma %c\n",179,179,179);
printf("\t%c 2 %c\tSubtracao %c\n",179,179,179);
printf("\t%c 3 %c\tDivisao %c\n",179,179,179);
printf("\t%c 4 %c\tMultiplicacao %c\n",179,179,179);
printf("\t%c 5 %c\tDobro %c\n",179,179,179);
printf("\t%c 6 %c\tTriplo %c\n",179,179,179);
printf("\t%c 7 %c\tQuadrado %c\n",179,179,179);
printf("\t%c 8 %c\tPotencia %c\n",179,179,179);
printf("\t%c 9 %c\tMedia %c\n",179,179,179);
printf("\t%c 0 %c\tSair %c\n",179,179,179);
printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",192,196,196,1
96,196,196,193,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,217);
printf("\nEscolha a opcao:\n");

scanf("%d",&op);

if ((op==1)||(op==2)||(op==3)||(op==4)||(op==8)||(op==9))

{
printf("Insira primeiro valor:\n\7");
scanf("%f",&x);
printf("Insira segundo valor:\n\7");
scanf("%f",&y);
}
if ((op==5)||(op==6)||(op==7))
{
printf("Insira valor:\n\7");
scanf("%f",&x);
}
switch(op)
{
case 0:break;("Vai sair da Calculadora!");

case 1:total=soma(x,y);
break;

case 2:total=subt(x,y);
break;

case 3:total=divi(x,y);
break;

case 4:total=mult(x,y);
break;

case 5:total=dobro(x);
break;

case 6:total=triplo(x);
break;

case 7:total=quadrado(x);
break;

case 8:total=potencia(x,y);
break;

case 9:total=media(x,y);
break;

default: printf("opcao Invalida\n");

if ((op==1)||(op==2)||(op==3)||(op==4)||(op==5)||(op==6)||(op==7)||(op==8)||(op
==9))
{
printf("\nResultado da operacao: %.2f\7\n\n\n",total);
}

system("pause");

}
while(op!=0);
}

//Funes da calculadora

float soma(float a,float b)


{
float t;
t=a+b;
return t;
}

float subt(float a,float b)


{
float t;
t=a-b;
return t;
}
float divi(float a,float b)
{
float t;
t=a/b;
return t;
}
float mult(float a,float b)
{
float t;
t=a*b;
return t;
}
float dobro(float a)
{
float t;
t=a*2;
return t;
}
float triplo(float a)
{
float t;
t=a*3;
return t;
}
float quadrado(float a)
{
float t;
t=a*a;
return t;
}
float potencia(float a,float b)
{
int i=0;
float pot=1;
for (;i<b;i++)
pot=pot*a;
return pot;
}
float media (float a,float b)
{
float t;
float med;
t=a+b;
med=t/2;
return med;

S-ar putea să vă placă și