Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void addition ( double operand1, double operand2, double *ergebnis){
  4.   *ergebnis = operand1 + operand2;
  5.     }
  6.  
  7. void subtraktion ( double operand1, double operand2, double *ergebnis){
  8.     *ergebnis = operand1 - operand2;
  9.     }
  10.  
  11. void multiplikation ( double operand1, double operand2, double *ergebnis){
  12.     *ergebnis = operand1 * operand2;
  13.     }
  14.  
  15. void division (double operand1, double operand2, double *ergebnis){
  16.     *ergebnis = operand1 / operand2;
  17.     }
  18.  
  19.  
  20. int main (void)
  21. {
  22.  
  23.     double operand1, operand2, ergebnis;
  24.     char operator1;
  25.    
  26.  
  27.     printf("Dies ist ein Taschenrechnerprogramm fuer die vier Grundrechenarten!\n\n");
  28.     printf("Geben Sie bitte nun den ersten Operanden ein!\n");
  29.     scanf_s("%lf", &operand1);
  30.     printf("Geben Sie bitte den zweiten Operator ein\n");
  31.     scanf("%lf",&operand2);
  32.     printf("Geben Sie bitte nun den Operator ein!\n");
  33.     scanf_s("%c",&operator1);
  34.    
  35.     if(operator1 == '+' ) {
  36.         printf ("\n\n");
  37.         addition (operand1, operand2, &ergebnis);
  38.         printf ("%5.2f", operand1);
  39.         printf (" + ");
  40.         printf ("%5.2f", operand2);
  41.         printf (" = ");
  42.         printf ("%5.2f ", ergebnis);
  43.     }      
  44.  
  45.     if(operator1 == 2) {
  46.         printf ("\n\n");
  47.         subtraktion (operand1, operand2, &ergebnis);
  48.         printf ("%5.2f", operand1);
  49.         printf (" - ");
  50.         printf ("%5.2f", operand2);
  51.         printf (" = ");
  52.         printf ("%5.2f", ergebnis);
  53.     }
  54.  
  55.     if (operator1 == 3) {
  56.         printf ("\n\n");
  57.         multiplikation (operand1, operand2, &ergebnis);
  58.         printf ("%5.2f", operand1);
  59.         printf (" * ");
  60.         printf ("%5.2f", operand2);
  61.         printf (" = ");
  62.         printf ("%5.2f", ergebnis);
  63.     }
  64.  
  65.     if (operator1 == 4) {
  66.         printf ("\n\n");
  67.         division (operand1, operand2, &ergebnis);
  68.         printf ("%5.2f", operand1);
  69.         printf (" / ");
  70.         printf ("%5.2f", operand2);
  71.         printf (" = ");
  72.         printf ("%5.2f", ergebnis);
  73.     }
  74.  
  75. getchar ();
  76. getchar ();
  77.    
  78. return 0;
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement