跳过 5 的倍数旁边的两个值后显示数组

问题描述 投票:0回答:1

用 C 编写一个程序,读取数组中的 n 个值并显示该数组 跳过 5 的倍数旁边的两个值之后。

不知道如何发展这个问题的逻辑。我怎样才能找到解决这个问题的方法??

arrays c logic
1个回答
0
投票

我明白,你想显示数组项。如果某项乘数为 5,则跳过下 2 项。在该代码下方:(如果您需要进一步帮助,请在评论中告知)

#include <stdio.h>
#include <stdlib.h>

int main (int argc, char **argv, char **envp) {
    int n;
    printf ("Please enter size of the array: ");
    scanf ("%d", &n);
    int arr [n];
    for (int i = 0; i < n; ++ i) {
        printf ("Please enter %dth element of the array: ", i);
        scanf ("%d", &arr [i]);
    }
    for (int i = 0; i < n; ++ i) {
        if ((arr [i] % 5) == 0) {
            i = i + 2;
        }
        printf ("%dth element of the array is: %d\n", i, arr [i]);
    }
    return EXIT_SUCCESS;
}
© www.soinside.com 2019 - 2024. All rights reserved.