當前位置:首頁 » 編程語言 » 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);{

熱點內容
c語言字元串初始化 發布:2025-05-17 20:18:43 瀏覽:35
安卓融e聯推送需要什麼許可權 發布:2025-05-17 20:18:39 瀏覽:268
我的世界無限武魂伺服器 發布:2025-05-17 20:17:09 瀏覽:371
安卓手游腳本語言 發布:2025-05-17 19:53:07 瀏覽:21
找圈演算法 發布:2025-05-17 19:49:19 瀏覽:410
資料庫的存取方法 發布:2025-05-17 19:48:36 瀏覽:125
androidapp測試 發布:2025-05-17 19:48:19 瀏覽:389
如何修改iphone密碼修改 發布:2025-05-17 19:47:31 瀏覽:509
發現了致富密碼是什麼意思 發布:2025-05-17 19:45:42 瀏覽:416
耐存儲的紙 發布:2025-05-17 19:43:35 瀏覽:931