Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AddPoint(x,y) Using C

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int x,y;
}point;

void printPoint( point p )
{

    printf("(%d,%d)",p.x,p.y);
}

point addPoint( point p1, point p2 )
{
    point pResult;
    pResult.x = p1.x + p2.x ;
    pResult.y = p1.y + p2.y ;
    return pResult;
}

int main()
{
    point p1,p2;
    printf("Enter first point: ");
    scanf("%d,%d",p1.x,p1.y);
    printf("Enter second point: ");
    scanf("%d,%d",p2.x,p2.y);
    
}

This is an unfinish code which I dont know what to do next ( Homework ). The question need me to add both points together into 1 point but I’m not sure what to do in int main() as the final step.
‘point addPoint’ is a must-use given from the question (meaning that I can’t edit it).Please go easy on me since I’m kinda bad at this part of coding.

Edited : enter image description here This is what the output supposed to be.

Edit 2 : enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is what I managed to do.

>Solution :

It looks like this would do:

point p3 = addPoint(p1, p2);
printPoint(p1);
printf(" + ");
printPoint(p2);
printf(" = "):
printPoint(p3)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading