目錄
如何使用C語言列印數字範圍?
Aug 29, 2023 am 08:05 AM
列印數字範圍
使用c語言
問題
對於給定的數字,嘗試找到該數字存在的範圍。
解決方案
這裡,我們正在學習如何找到一個數字的範圍。
我們套用於找到範圍的邏輯是−
lower= (n/10) * 10; /*the arithmetic operators work from left to right*/ upper = lower+10;
登入後複製
Explanation
#讓數字n=45
下限=(42/10)*10 / / 除法返回商
=4*10 =40
上限=40 10=50
範圍− 下限-上限− 40-50
Example
以下是用於列印數字範圍的C程式−
#include<stdio.h> main(){ int n,lower,upper; printf("Enter a number:"); 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(); }
登入後複製
輸出
#當上述程式被執行時,它會產生以下結果−
Enter a number:25 Range is 20 – 30
登入後複製
這是另一個用於列印數字範圍的C程式。
#include<stdio.h> main(){ int number,start,end; printf("Enter a number:"); 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(); }
登入後複製
輸出
當上述程式被執行時,它會產生以下結果 −
Enter a number:457 Range is 450 – 460
登入後複製
以上是如何使用C語言列印數字範圍?的詳細內容。更多資訊請關注PHP中文網其他相關文章!
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗?
3 週前
By 王林

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗?
3 週前
By 王林

熱門文章標籤

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)