c - 如何用 C 语言为 Ubuntu 控制台程序编写条件循环

标签 c linux

您将如何或是否可以在 ubuntu 终端中用 C 语言编写条件 if 循环。这是我在大学必须写的一个项目。

据我所知,我认为该语言是 C 语言。

我将用伪代码编写我的问题,任何帮助都会很棒。

global x variable
global y variable

please enter X (x has to be a value between 1-100)
if anything other than 1-100 then repeat and ask for x again

once the value has been identified as 1-100
please enter Y
if anything other than 1-100 enter ask again

once the two values have been entered scan into a 2d array.

示例:

please enter x: d
please enter x: d
please enter x: 5
please enter y: f
please enter y: 5

1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5 
1 2 3 4 5

感谢您的任何建议。

我的讲师再次说过,这个模块是 C 语言,Ubuntu Linux 中的控制台只是为了澄清。

这是我到目前为止所拥有的;对其中的所有评论感到抱歉,我必须发表评论以展示他们作为任务的一部分所做的事情。

#include <stdio.h>  //this defines the library to use within c//  
#include <stdlib.h> //this defines the library to use within c//
#include <time.h>   //this defines the library to use within c//

int x; /*this sets the initial variables to program*/
int y; /*this sets the initial variables to program*/

int main(void){

printf("Please Enter Size X Of Array:");/*This is where the x limit of the array is set*/
scanf("%d",&x);

我希望它在这里检查输入的值是否在 1-100 之间,如果不是,则打印再次输入数组的大小 X(Y 相同)

printf("\n");

printf("please Enter Size Y Of Array:");/*This is where the y limit of the array is set*/
scanf("%d",&y);

    int array[x][y];/*this sets the initial variables to program*/

任何人都可以发布您将如何执行此操作,因为当我尝试时它不起作用。谢谢。

最佳答案

do {
    printf("Please Enter Size X Of Array:");/*This is where the x limit of the array is set*/
    scanf("%d",&x);
} while (x<1 || x>100);

关于c - 如何用 C 语言为 Ubuntu 控制台程序编写条件循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10463191/

相关文章:

C libpcap 解析 DLT 条目,一些讨厌的错误

c - 实现无限循环时,使用 while(1) vs for(;;) vs goto(在 C 中)有区别吗?

linux - 如何为 Linux 应用程序添加版本信息

Linux 终端(Vim)无法粘贴整个代码?

linux - 将locale-gen生成的数据复制到另一台电脑

linux - 如何在 Linux 中的 IBM WebSphere Application Server 中每 120 秒执行一次 jython 脚本?

c、malloc 和 realloc 结构体数组

c - 防止 MSYS 'bash' 终止捕获 ^C 的进程

Linux 与 Win 运行时计时

C : timer inside while/loop + scanf?