显示precedes数输入。 (C编程) [英] display that precedes the number entered. (C programming)

查看:133
本文介绍了显示precedes数输入。 (C编程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C语言程序设计

要求用户1和100之间选择一个随机数,然后问他要多少个号码,以显示他进入该precedes第一个号码。

Ask user to enter a random number between 1 and 100. Then ask how many numbers he wants to display that precedes first number he enters.

让用户是否进入9,并希望3个数字是precedes 9,你的程序应该显示这个说:
•6 7 8 9

Let’s say if user enter 9 and wants 3 numbers that precedes 9, your program should display this: • 6 7 8 9

不知道需要一些帮助。

推荐答案

有关询问用户一个问题,你可以使用像的printf 看跌

For asking the user a question, you can use something like printf or puts.

要请求号的的用户, scanf函数是可能是你在工作级别的最佳方法。

To request numbers from the user, scanf is probably the best approach for the level you're working at.

举例来说,下面是要求用户的号码,然后给他们下一个数一个完整的程序:

By way of example, here's a complete program that asks the user for a number then gives them the next number:

#include <stdio.h>

int main (void) {
    int num;
    printf ("Enter a number: ");
    if (scanf ("%d", &num) != 1) {
        puts ("That wasn't a valid number");
        return 1;
    }
    printf ("The next number is %d\n", num + 1);
    return 0;
}

浅析了code和它做什么它运行的时候,应该足以让你开始。

Analysing that code, and what it does when it runs, should be enough to get you started.

有关您的具体项目,下面的伪code应该有所帮助:

For your specific project, the following pseudo-code should help:

print "Enter the ending number: "
input endnum
print "Enter the count of preceding numbers: "
input count

num = endnum - count
do:
    print num
    num = num + 1
while num <= endnum

这是你可以使用的算法,我不会为它为C code,因为如果你这样做你自己,你会成为一个更好的$ C $铬。在任何情况下,那些伪code线全部pretty多有一个一对一的映射与C语句,所以应该是比较容易得到的东西去。

That's the algorithm you can use, I won't provide it as C code since you'll become a better coder if you do that yourself. In any case, those pseudo-code lines all pretty much have a one-to-one mapping with C statements so it should be relatively easy to get something going.

这篇关于显示precedes数输入。 (C编程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆