//1:
#include <stdio.h>
int main()
{
int input=0;
printf("你性别是什么?请选择1/0\n");
scanf("%d", &input);
if (input ==1)
{
printf("男\n");
}
else
{
printf("女\n");
}
return 0;
}
//2:
#include <string.h>
int main()
{
int money = 0;
printf("任务:开始存钱,每天存10元\n");
printf("请输入你的本金\n");
scanf("%d", &money);
while (money<1000)
{
printf("请继续努力存钱\n");
money = money + 10;
}
if (money >= 1000)
{
printf("恭喜你,目标达成!\n");
}
else
{
printf("请继续努力,不要放弃!\n");
}
return 0;
}
//3:
#include <string.h>
int Add(int x, int y)
{
int z = 0;
z = 2 * x + y;
return z;
}
int main()
{
printf("请输入两个数\n");
int n1 = 0; int n2 = 0;
scanf("%d %d" , &n1, &n2);
int sum = Add(n1, n2);
printf("结果为%d", sum);
return 0;
}
//4:
#include <string.h>
int main()
{
int A[] = { 1,2,3,4,5,6 };
int i = 0; int j = 0;
printf("请选择for或while循环:1/0\n");
scanf("%d", &j);
if (j == 1)
{
printf("for循环:");
for (i = 0; i < 6; i++)
{
printf("%d ", A[i]);
}
}
else
{
printf("while循环:");
while (i < 6)
{
printf("%d ", A[i]);
i++;
}
}
}
认识C语言1.2
于 2024-01-08 14:12:16 首次发布