【发布时间】:2020-11-14 14:16:48
【问题描述】:
我有一个问题要解决。我必须制作一个程序,该程序将从数字序列中获取 2 个数字,并比较它们是否是 '' 或 '=' 并且数字列表需要以数字 0 结尾。所以基本上我有一个序列数字 {5, 7, 8, 4, 3, 3, 0} 并且程序必须检查 5,7 对(它是 5 4)然后3, 3 所以是 3 = 3。而 0 基本上是作为出口。
到目前为止,我写下了数字的比较,但现在我只有一个程序,它从用户那里获取 2 个输入并比较它们。但是我有点需要为用户指定让我们说输入 11 个以 0 结尾的数字(因为 0 不会被计入比较)并将这些数字存储在一个数组中,然后让程序在每个之后比较 2 个数字其他(按顺序)带有 或 =。
提前谢谢各位。我对 C 有点陌生,这些数组,特别是 malloc、calloc、realloc 对我来说真的很复杂。
到目前为止,我的代码如下所示:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define post 10
int main(){
int a, b;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
if (a > b)
{
printf("%d > %d\n", a, b);
}
else if(a < b)
{
printf("%d < %d\n", a, b);
}
else
{
printf("%d = %d\n", a, b);
}
system("pause");
return 0;
}
【问题讨论】:
标签: arrays c input comparison