當前位置:首頁 » 編程語言 » c語言統計整數

c語言統計整數

發布時間: 2022-06-07 08:04:09

A. c語言 輸入一個整數 統計該整數的位數

#include<stdio.h>
main()
{
unsignedlongnum=0;
inti=1,j=0;
printf("請輸入一個數:");
scanf("%d",&num);
while((num/i)>=1)
{
i=i*10;
j++;
}
printf("該數為%d位數 ",j);
}

有什麼看不懂的問我,望採納

B. c語言 統計一個字元串里有多少個整數

#include<stdio.h>

intmain(void)
{
intcnt,n;
for(cnt=0;!scanf("%*[^0-9]")&&!scanf("%*[0-9]");++cnt);
printf("%d ",cnt);
return0;
}

C. C語言:輸入一個字元串,統計有多少個整數並輸出

48即是0x30,ASCII碼中我們看到的0到9的對應的是0x30-0x39.

D. 輸入字元串並統計其中組成的整數個數,C語言

思路:統計字元串中的空格,所以該字元串中有空格,則輸入只能使用gets函數,再依次遍歷該字元串,判斷字元是否是空格,如果是,則空格個數自加1。
參考代碼:

#include<string.h>#include<stdio.h>#include<math.h>int main(){ int sum=0,i; char a[100]; gets(a); for(i=0;a[i]!='\0';i++) if(a[i]==' ') sum++; printf("%d\n",sum); return 0;}/*輸出: af adf asfd4*/

E. . c語言編程:輸入一個正整數,統計該數的各位數字中零的個數,並求各位數字中的最大者。

#include<stdio.h>
intmain()
{
intn,max=-1,s=0;
scanf("%d",&n);
while(n)
{
if(n%10==0)s++;
if(n%10>max)max=n%10;
n/=10;
}
printf("0:%d max=%d ",s,max);
return0;
}

F. c語言十個整數統計正整數的數量,要用函數調用

#include<stdio.h>
void calc(){
int num[10],i,count=0;
for(i=0;i<10;i++){
printf("請輸入第%d個數:",(i+1));
scanf("%d",&num[i]);
if(num[i]>0){
count++;
}
}
printf("正整數有%d個!\n",count);
}
void main(){
calc();
}

G. c語言統計一個整數的位數求糾錯,在線等

while後面多了一個分號 去掉就好了while(number!=0);{

熱點內容
ton在編程 發布:2025-09-11 20:48:35 瀏覽:738
伺服器主地址是什麼情況 發布:2025-09-11 20:46:35 瀏覽:315
php單引號雙引號 發布:2025-09-11 20:33:46 瀏覽:831
c語言細節 發布:2025-09-11 20:29:37 瀏覽:245
雙腳本結構 發布:2025-09-11 20:29:31 瀏覽:880
雲存儲時間 發布:2025-09-11 20:01:58 瀏覽:597
access資料庫if語句 發布:2025-09-11 19:52:34 瀏覽:180
安卓程序的用戶數據在哪裡 發布:2025-09-11 19:41:21 瀏覽:276
安卓的資料庫 發布:2025-09-11 19:29:40 瀏覽:985
python語言是一門編程語言 發布:2025-09-11 19:27:09 瀏覽:569