[Code example] Struct Add points page 130

User avatar

Topic author
BJT
Site Admin
Site Admin
Posts: 141
Joined: Thu Apr 20, 2017 4:43 pm
Instruction: University Student
Gender:
Age: 27
Venezuela

Struct Add points page 130

Post by BJT » Sat May 13, 2017 10:16 pm

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct point
  5. {
  6.     int x;
  7.     int y;
  8. };
  9.  
  10. struct point addpoint(struct point p1, struct point p2);
  11.  
  12. int main()
  13. {
  14.     struct point p1={5,6},p2={10,20};
  15.     p1=addpoint(p1,p2);
  16.     printf("%d %d\n",p1.x,p1.y);
  17.     return EXIT_SUCCESS;
  18. }
  19.  
  20. struct point addpoint(struct point p1, struct point p2)
  21. {
  22.     p1.x+=p2.x;
  23.     p1.y+=p2.y;
  24.     return p1;
  25. }

output

Code: Select all

15 26
word count: 79

Link:
BBcode:
HTML:
Hide post links
Show post links

Who is online

Users browsing this forum: No registered users and 2 guests