Home > Blockchain >  AddPoint(x,y) Using C
AddPoint(x,y) Using C

Time:11-18

#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

This is what I managed to do.

CodePudding user response:

It looks like this would do:

point p3 = addPoint(p1, p2);
printPoint(p1);
printf("   ");
printPoint(p2);
printf(" = "):
printPoint(p3)
  •  Tags:  
  • c
  • Related