uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

funcs_ex2.c (678B)


      1 #include <stdio.h>
      2 
      3 /* 
      4  * Write a function that computes the basic operations.
      5  * Take the first 2 arguments by value and the rest
      6  * by pointer.
      7  */
      8 
      9 static void
     10 calc(float x, float y, float *sum, float *diff, float *prod, float *ratio)
     11 {
     12         *sum = x + y;
     13         *diff = x - y;
     14         *prod = x * y;
     15         if (y != 0)
     16                 *ratio = x / y;
     17 }
     18 
     19 int
     20 main(int argc, char *argv[])
     21 {
     22         float x = 20, y = 10;
     23         float sum, diff, prod, ratio = 0;
     24 
     25         calc(x, y, &sum, &diff, &prod, &ratio);
     26         printf("x: %.2f | y: %.2f | sum: %.2f | diff: %.2f | prod: %.2f | ratio: %.2f\n",
     27                 x, y, sum, diff, prod, ratio);
     28 
     29         return 0;
     30 }