Showing posts with label Struct. Show all posts
Showing posts with label Struct. Show all posts

Function should print the cartesian coordinates of the struct argument

How to write a function should print the cartesian coordinates of the struct argument in C Programming Language ?



  1. /*This function should print the cartesian coordinates of the struct argument*/
  2. void printCartesian(struct cartesian_t n){
  3.         printf("Result in cartesian:");
  4.         printf("%.3f ", n.x);
  5.         if ((n.y) >= 0){
  6.                 printf("+");
  7.         }
  8.         else{}
  9.         printf("%.3f \n", n.y);
  10. }

Add x and y coordinates to create a new struct in C Program

How to Add x and y coordinates to create a new struct in C Programming Language ?


/*Supply two cartesian_t structs and add x and y coordinates to create a new struct*/

  1. struct cartesian_t add(struct cartesian_t a, struct cartesian_t b){
  2.         struct cartesian_t coordsSum;
  3.         coordsSum.x = (a.x) + (b.x);
  4.         coordsSum.y = (a.y) + (b.y);
  5.         return coordsSum;
  6. }