❶ 用c語言如何實現,統計從鍵盤輸入數字的個數
依次接收字元,直到輸入回車為止,判斷是否是數字,如果是則數字個數遞增。
#include<stdio.h>
intmain()
{
intx=0,z=0;
charch;
ch=getchar();//接收字元
while(ch!=' ')
{
if(ch>=48&&ch<=57)//依據字元ASCII值判斷是否是數字
x++;//是數字,數字個數遞增
else
z++;//否則,其他字元個數遞增
ch=getchar();
}
printf("數字字元有:%d個,其它字元有:%d個",x,z);
return0;
}
❷ c語言中,如何顯示我輸入了多少個數
int
a=0;
int
i
=0;
while(a!=-1)
{
scanf("%d",&a);
i++;
}
printf("%d",i-1);
當輸入-1時結束就行了,就會顯示你輸入過多少個數字
如果是輸入進數組就把a改成a[你輸入的容量].
while裡面改成scanf("%d",&a[i]);
❸ c語言統計大小寫字母 數字個數
#include <stdio.h>
#include <stdlib.h>
#define N 100
void func3()
{
char str[N];
int i,lower=0,upper=0,digit=0,space=0;
long others=0;
printf("Input a string:");
gets(str);
for(i=0;str[i]!='