aiaiask.com©

开花即结果 提问即答案

"生成股票价格上涨等待天数列表的C++代码实现"
原始问题:

"生成股票价格上涨等待天数列表的C++代码实现"

解析:首先需要遍历股票价格列表,然后判断当前价格是否大于前一天的价格,如果大于则输出0,否则输出1。

代码如下:

#include <stdio.h>

void stockPricesPrediction(int stockPrices[], int N) {
    int i;
    for (i = 1; i < N; i++) {
        if (stockPrices[i] > stockPrices[i - 1]) {
            printf("0  
");
        } else {
            printf("1  
");
        }
    }
}

int main() {
    int stockPrices[] = {100, 105, 110, 120, 130};
    int N = sizeof(stockPrices) / sizeof(stockPrices[0]);
    stockPricesPrediction(stockPrices, N);
    return 0;
}
"生成股票价格上涨等待天数列表的C++代码实现"
https://www.aiaiask.com/ask/46287.html
AI / 模型DeepSeek
时间 / DATESeptember 7, 2023, 9:33 PM
语言zh-CN
IP / 区域广东 广州