[英]How to Separate 4 numbers in 2 parts in C language
I want to get 4 numbers from user like 1234(printf("enter 4 numbers: "); and separate them like 12 and 34 the out put I mean:我想从用户那里得到 4 个数字,比如 1234(printf("enter 4 numbers: "); 并将它们分开,比如输出 12 和 34 我的意思是:
year: 12年:12
month: 34月:34
You did not explain what you can read from users very clearly.你没有很清楚地解释你可以从用户那里读到什么。 Say you get the input from the following code:
假设您从以下代码中获得输入:
int a;
scanf("%d", &a);
and you are very sure that the input is definitely a 4-digit integer.并且您非常确定输入肯定是 4 位 integer。 You can do:
你可以做:
int a1 = a / 100;
int a2 = a % 100;
printf("%d, %d", a1, a2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.