输出一个整数的每一位:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
int main()
{
int a=0;
int a1,a2,a3,a4,a5;
printf("请输入一个小于五位的数:",a);
scanf("%d",&a);
printf("你输入的数字是:%d\n",a);
a1=a%10;
a2=((a%100)-(a%10))/10;
a3=((a%1000)-(a%100))/100;
a4=((a%10000)-(a%1000))/1000;
a5=((a%100000)-(a%10000))/10000;
printf("个位数是:%d\n",a1);
printf("十位数是:%d\n",a2);
printf("百位数是:%d\n",a3);
printf("千位数是:%d\n",a4);
printf("万位数是:%d\n",a5);
return 0;
}
出现多少次9:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
int main()
{
int i;
int count=0;
char a[100]={0};
for(i=0;i<100;i++)
{
a[i]=i+1;
if ((a[i]%10==9)||((a[i]-(a[i]%10))/10==9))
{
count++;
printf("%d\n",a[i]);
}
}
printf("一共出现了%d次9",count);
return 0;
}