cuốn sách gpt4 ai đã làm

c - 如果整数序列的后续数字大于前一个,则显示 'increasing'

In lại Tác giả: Vũ trụ không gian 更新时间:2023-11-04 06:26:22 25 4
mua khóa gpt4 Nike

Write a program that reads a sequence of integers and print 'increasing' if each subsequent number is greater than the previous, or print 'not increasing' otherwise. End of reading numbers ending is when you read a negative number.

这是我到目前为止得到的:

#include 
int main()
{
int a[100],i;

for(i=0; ; i++)
{
scanf("%d",&a[i]);
if(a[i]<0)
phá vỡ;
}

for(i=0;;i++)
{
if(a[i]<0)
phá vỡ;

if(a[i+1]>a[i])
{
printf("increasing\n");
}
else if(a[i+1]<>
printf("not increasing\n");
}

return 0;
}

Ví dụ đầu vào:1 4 6 2 6 3 -1
示例输出:

tăng dần
tăng dần
not increasing
tăng dần
not increasing

然后我得到:

tăng dần
tăng dần
not increasing
tăng dần
not increasing
not increasing

我的问题是最后一个不需要的“不增”怎么去掉?

câu trả lời hay nhất

一个简单的解决方法是更改此测试(在第二个循环中),从:

 if(a[i]<0)
phá vỡ;

đến:

 if(a[i + 1]<0)
phá vỡ;

但是请注意,这不是很可靠,但对于简单的家庭作业来说可能已经足够了。

关于c - 如果整数序列的后续数字大于前一个,则显示 'increasing',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26348725/

25 4 0
không gian vũ trụ
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress