如何使用C语言打印数字范围?
问题
对于给定的数字,尝试找到该数字存在的范围。
解决方案
在这里,我们正在学习如何找到数字范围。
我们用于查找范围的逻辑是-
lower= (n/10) * 10; /*the arithmetic operators work from left to right*/ upper = lower+10;
解释
设n=45
Lower=(42/10)*10//除法返回商
=4*10=40
上限=40+10=50
范围-下-上-40-50
示例
以下是用于打印数字范围的C程序-
#include输出结果main(){ int n,lower,upper; printf("Enteranumber:"); scanf("%d",&n); lower= (n/10) * 10; /*the arithmetic operators work from left to right*/ upper = lower+10; printf("Range is %d - %d",lower,upper); getch(); }
执行以上程序后,将产生以下结果-
Enteranumber:25 Range is 20 – 30
这是另一个用于打印数字范围的C程序。
示例
#include输出结果main(){ int number,start,end; printf("Enteranumber:"); scanf("%d",&number); start= (number/10) * 10; /*the arithmetic operators work from left to right*/ end = start+10; printf("Range is %d - %d",start,end); getch(); }
执行以上程序后,将产生以下结果-
Enteranumber:457 Range is 450 – 460
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短