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

熱點內容
911標配的有哪些配置 發布:2024-04-30 03:18:38 瀏覽:158
如何訪問阿里雲伺服器多個數據盤 發布:2024-04-30 03:08:45 瀏覽:186
ldd3源碼 發布:2024-04-30 03:07:14 瀏覽:6
phpecho換行 發布:2024-04-30 02:21:51 瀏覽:903
高中ftp 發布:2024-04-30 01:51:48 瀏覽:873
林秋楠手機的密碼是多少 發布:2024-04-30 01:46:31 瀏覽:276
python靜態類方法 發布:2024-04-30 01:30:28 瀏覽:462
zblogphpasp 發布:2024-04-30 01:27:35 瀏覽:137
宏程序自動編程軟體 發布:2024-04-30 01:15:01 瀏覽:417
vs添加編譯選項 發布:2024-04-30 01:06:10 瀏覽:614