#include <stdio.h>
void main()
{
int a;
int temp1,temp2,temp3,temp4;
printf("请输入一个四位数:");
scanf("%d",&a);
temp1 = a/1000;//千位数
if (temp1 == 0) {
printf("不是一个四位数");
}
else{
printf("%d ",temp1);}
temp2 =(a-temp1*1000)/100;//百位数
printf("%d ",temp2);
temp3 = (a-temp1*1000-temp2*100)/10 ;//十位数
printf("%d ",temp3);
temp4 = a%10 ;//个位数
printf("%d\n ",temp4);
}
#include <stdio.h>
#include <string.h>
void tongji( char str0[100] ,int b[4])
{
int i,n;
n = strlen(str0);
for(i = 0;i < n+1;i++)
{
if(str0[i]>=65&&str0[i]<=90||str0[i]>=97&&str0[i]<=122)
b[0]++;
else if(str0[i]>=48&&str0[i]<=57)
b[1]++;
else if(str0[i]==32)
b[2]++;
else b[3]++;
}
printf("数字个数:%d\n",b[0]);
printf("字母个数:%d\n",b[1]);
printf("空格个数:%d\n",b[2]);
printf("其余个数:%d\n",b[3]);
}
void main()
{
char str[100];
int b[4]={0};
gets(str);
tongji(str ,b);
}