1. 编程实现:用户输入身份证号,输出您的生日是***年***月***日c语言
时间: 2023-04-07 14:03:16 浏览: 114
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char id[19];
printf("请输入您的身份证号:");
scanf("%s", id);
char year[5], month[3], day[3];
strncpy(year, id+6, 4);
year[4] = '\0';
strncpy(month, id+10, 2);
month[2] = '\0';
strncpy(day, id+12, 2);
day[2] = '\0';
printf("您的生日是%s年%s月%s日\n", year, month, day);
return 0;
}
相关问题
用c语言输出 * *** *****
可以使用以下代码来输出所需图案:
```
#include <stdio.h>
int main() {
printf("*\n");
printf("***\n");
printf("*****\n");
return 0;
}
```
或者使用以下代码来输出:
```
#include <stdio.h>
int main() {
int a, b;
a = 1;
while (a <= 5) {
b = 1;
while (b <= a) {
printf("*");
b++;
}
printf("\n");
a++;
}
return 0;
}
```
其中第二段代码是引用中的代码,可以输出更多行的图案。
C语言编程输出如下图形。* *** ***** *******
以下是两种C语言编程输出如下图形的例子:
1.方法1:直接打印
```c
#include <stdio.h>
#include <stdlib.h>
int main() {
printf(" *\n");
printf(" ***\n");
printf(" *****\n");
printf(" *******\n");
system("pause");
return 0;
}
```
输出:
```
*
***
*****
*******
```
2.方法2:while嵌套循环-while循环里面再嵌套一个while循环
```c
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
int main() {
int a, b; //定义两个变量-a用来控制内循环;b用来控制外循环
char x = '*';
a = 1;
while (a <= 4) //外循环-大环境-while控制行数
{
b = 1;
while (b <= 2 * a - 1) //内循环(五脏六腑)-while控制输出*的个数-每五个为一行
{
printf("%c", x);
b++;
}
printf("\n");
a++;
}
system("pause");
return 0;
}
```
输出:
```
*
***
*****
*******
```