#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
int main ()
{
char n;
printf ("Programma che svolge ogni tipo di operazione aritmetica tra 2 numeri a e b\n'n' per chiudere\nPremere 'invio' per continuare\n");
double somma, differenza, prodotto, quoziente,a ,b, resto;
while (n=getchar()!='n')
{
printf ("Inserisci a\n");
scanf ("%lf",&a);
if (isalpha(a))
{
printf("Errore! non hai inserito un numero");
}
printf ("Inserisci b\n");
scanf ("%lf",&b);
if (isalpha(b))
{
printf("Errore! non hai inserito un numero");
}
somma = a + b;
differenza = a - b;
prodotto = a * b;
quoziente = a / b;
resto = fmod (a,b);
printf ("somma = %.2lf + %.2lf = %.2lf\n",a,b,somma);
printf ("differenza = %.2lf - %.2lf = %.2lf\n",a,b,differenza);
printf ("prodotto = %.2lf * %.2lf = %.2lf\n",a,b,prodotto);
printf ("quoziente = %.2lf / %.2lf = %.2lf\n",a,b,quoziente);
printf ("resto = %.2lf %% %.2lf = %.2lf\n",a,b,resto);
fflush(stdin);
}
return 0;
}
Another question(In addition to that of the title): How do I (if the if it is checked )return to the main function ( and then restart the program to make the while loop ) ?
Aucun commentaire:
Enregistrer un commentaire