您将如何或是否可以在 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/