// 练习1.1
#include <string.h>
int main()
{
printf(" ** \n");
printf(" ** \n");
printf("************\n");
printf("************\n");
printf(" * * \n");
printf(" * * \n");
return 0;
}
// 练习1.2
#include <string.h>
int main()
{
printf("Name Age Gender\n");
printf("---------------------\n");
printf("Jack 18 man\n");
return 0;
}
// 练习1.3
#include <string.h>
int main()
{
int a = 40; int c = 212;
int n = (-8 + 22) * a - 10 + c / 2;
printf("%d", n);
return 0;
}
// 练习1.4
#include <string.h>
int main()
{
printf("%d\n", strlen("c:\test\121")); //strlen求字符长度
return 0;
}
// 练习1.5
#include <string.h>
int main()
{
char ARR[8] = {'b','i','t'};
char brr[7] = { "abcde" };
printf("%d\n", strlen(ARR));
printf("%d\n", strlen(brr));
return 0;
}
// 练习1.6
#include <string.h>
int max(int x, int y)
{
if (x > y)
return x;
if (x < y)
return y;
else
return x;
}
int main()
{
int a = 0; int b = 0;
printf("请输入两个数a,b\n");
scanf("%d %d", &a, &b);
int z = max(a, b);
printf("最大值为%d", z);
}
// 练习1.7
#include <string.h>
int f(int x)
{
if (x < 0)
return 1;
if (x > 0)
return -1;
else
return 0;
}
int main()
{
int x; int y;
printf("请一个数x(-10000<x<10000)\n");
scanf("%d",&x);
if ((x <= -10000) || (x >= 10000))
{
printf("输入错误,请重新输入x\n");
scanf("%d", &x);
y = f(x);
printf("%d", y);
}
else
{
y = f(x);
printf("%d", y);
}
}
认识C语言(练习壹)
于 2024-01-08 16:54:37 首次发布