新手入门,请多指教
⭐ 建议直接复制,换行改为 转义符 “ \n ”
#include
int main(){
printf(" Hello C-world!\n");//请注意,H字符的左边有一个空格。
printf("****\n*\n*\n****\n");
return 0;
}
#include
int main()
{
double x;
scanf("%lf", &x);
if (x <= 100)
printf("%.2lf", 0.51*x);
else
printf("%.2lf", 0.65*x);
}
#include
int main()
{
int x, y, z, t;
scanf("%d%d%d", &x, &y, &z);
if (x > y)
{
t = x; x = y; y = t;
} /*交换x,y的值*/
if (x > z)
{
t = z; z = x; x = t;
} /*交换x,z的值,请在此处填写多行代码*/
if (y > z)
{
t = z;
z = y;
y = t;
}
printf("small to big: %d %d %d\n", x, y, z);
}
⭐ 找规律:空格逐行递减 1,星号逐行递加 2 (变量:行号)
#include
int main()
{
int n,i,j;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
for (j = 0; j <= 13 - i; j++)
printf(" ");
for (j = 0; j < i * 2 - 1;j++)
printf("*");
printf("\n");
}
}
⭐ 排列:从 n 个数选 2 个数, A(n,2) = n * (n-1)
#include
int main()
{
int n,i;
int ans= 1;
scanf("%d", &n);
for (i = 0; i <= 1; i++)
ans*= (n-i);
printf("%d", res);
return 0;
}
⭐ 模拟 -> 找规律 -> 斐波那契(当前项 = 前两项的和)
⭐ f(n) = f(n-1) + f(n-2),n > 2
#include
int main()
{
int n,i;
scanf("%d", &n);
int a[31];
a[1] = 1;
a[2] = 2;
for (i = 3; i <= n; i++)
{
a[i] = a[i - 1] + a[i - 2];
}
printf("result=%d", a[n]);
return 0;
}
⭐ 考点:常用数学函数的使用(注意引用头文件)(注意类型转换的精度损失)
abs:整型绝对值
fabs:浮点数绝对值
pow:幂函数
sqrt:开方(根号)
#include
#include
#include //注意:导入这份头文件才能使用 fabs 函数(绝对值)
int main(){
double x0, y0, A, B, C;
scanf("%lf%lf", &x0, &y0);//输入点P的坐标
scanf("%lf%lf%lf", &A, &B, &C);//输入直线L的A、B和C
//printf("%lf", abs(A*x0 + B*y0 + C) / sqrt(pow(A, 2.0) + pow(B, 2.0)));//输出距离
printf("%lf", fabs(A*x0 + B*y0 + C) / sqrt(pow(A, 2.0) + pow(B, 2.0)));
return 0;
}
⭐ 根据题意直接实现
#include
#include
#include
int main(){
int flag = 0;//flag=1,circular;flag=0,no circular
double x, y, r;
double A, B, D, E, F;
scanf("%lf%lf%lf%lf%lf", &A, &B, &D, &E, &F); //输入方程的5个参数
if (A != B || (A == 0 && B == 0))//非圆
{
flag = 0;
}
else{
double d = D / A;
double e = E / A;
double f = F / A;
if (d*d + e*e - 4 * f > 0){
flag = 1;
x = -d / 2;
y = -e / 2;
r = sqrt(d*d + e*e - 4 * f)/2;
}
}
if (flag){
printf("Center of a circle is(%.2lf,%.2lf)\n",x,y);//圆心坐标
printf("Radius of the circle is %.2lf\n", r);//直径
}
else{
printf("No circle");
}
return 0;
}
我的吃饱了,你的柴砍好了吗?