if else if 语句
#include<stdio.h>
int main(){
printf("请输入4位数及以下的正整数:");
int x;
int n = 1;
scanf_s("%d", &x);
if (x >999){
n = 4;
}
else if (x>99){
n = 3;
}
else if (x < 99){
n = 2;
}
printf("%d", n);
return 0;
}
while循环语句
#include<stdio.h>
int main(){
int x;
int n = 0;
scanf_s("%d", &x);
n++;
x /= 10; //(n=0时输出为1)
while (x>0) //( while{循环体}) (x>0为条件)
{
n++;
x /= 10;
}
printf("%d", n);
return 0;
}
do while语句
#include<stdio.h>
int main(){
int x;
int n = 0;
scanf_s("%d", &x);
do{
x /= 10;
n++;
} while (x > 0);
printf("%d", n);
return 0;
}