需要帮助:打印范围内的数字。 [英] help needed: Prints numbers in a range.

查看:72
本文介绍了需要帮助:打印范围内的数字。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这个程序的帮助。我已经绞尽脑汁待了一个星期。



我需要一个程序,用户输入两个数字,程序打印从第一个数字到最后一个数字的所有偶数。

I need help with this program. I''ve racked my brain for a week on it.

I need a program in that a user enters two numbers, and the program prints all the even numbers from the first number to the last.

推荐答案

这可以使用仅调用标准C库函数的C程序来完成。然后这个源将是OS独立的。



要在Unix命令行传递范围的shell上执行此操作,请阅读shell编程(特别是传递命令行参数,条件)和算术表达式)。对于Linux bash shell,请参阅 Bourne-Again SHell手册 [ ^ ]。



实施可能看起来像这样:

This can be done using a C program calling standard C library functions only. Then this source would be OS independant.

To do this with Unix shells passing the range on the command line, read about shell programming (especially passing command line parameters, conditions, and arithmetric expressions). For the Linux bash shell see the Bourne-Again SHell Manual[^].

An implementation might look like this:
#!/bin/bash
#

if  [ x"


2 == X ]; 然后
echo 用法:PrintRange<开始><结束>
退出
fi

i =
2" == x ]; then echo "Usage: PrintRange <start> <end>" exit fi let i=


1
if ((i& 1 )); 然后
i + = 1
fi
while ((i< =
1 if ((i & 1)); then let i+=1 fi while ((i <=


这篇关于需要帮助:打印范围内的数字。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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