简体   繁体   English

AddPoint(x,y) 使用 C

[英]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.这个问题需要我将两个点加起来为 1 点,但我不确定在 int main() 作为最后一步要做什么。 '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. 'point addPoint' 是问题给出的必须使用(意味着我无法编辑它)。请 go 对我轻松一点,因为我在这部分编码方面有点糟糕。

Edited:编辑: 在此处输入图像描述 This is what the output supposed to be.这就是 output 应该是的。

Edit 2:编辑2: 在此处输入图像描述

This is what I managed to do.这就是我设法做到的。

It looks like this would do:看起来会这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM