// 第1题
#include
#include
void main()
{
float a,b,c,s,area;
printf("请输入三个数:\n");
scanf("%f%f%f",&a,&b,&c);
if(a+b>c&&a-b{
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("面积:%f", area);
}
}
运行结果:
// 第2题
#include
#include
void main()
{
int a,b;
printf("请输入两个数:\n");
scanf("散亮毁%d %d",&a,&b);
printf("这两个数的和: %d\n", (a +b));
printf("这两个数的差: %d\n", (a -b));
printf("这两个数的积: %d\n", (a *b));
printf("这两个数的商: %lf\n", ((double)a / (double)b));
}
运行结果:
// 第三题
#include
// 是否是素数
bool prime(int x)
{
if(x < 2)
{
return false;
}
for (int i=2;i*i<=x;i++)
{
if(x % i == 0)
{
return false;
}
}
return true;
}
void main()
{
for (int i = 100; i <= 230; i++ )
{
if (prime(i))
{
printf("%d ", i);
}
}
}
结果:
#include
void main()
{
int a = 0;
printf("请输入一个数:\n");
scanf("%d", &a);
if (a >= 90)
{
printf("excellent\n");
}
else if (a >= 80)
{
printf("good\n");
}
else if (a >= 70)
{
printf("general\n");
}
else if (a >= 60)
{
printf("pass\n");
}
else
{
printf("no pass\n");
}
}
结果:
// 第五题
#include
void main()
{
printf("请输入三个数:\n");
int a[3];
for (int i = 0; i < 3; i++)
{
scanf("%d", &a[i]);
}
for (int i = 0; i < 3; i++)
{
for (int j = 0;j < 3-i-1; j++)
{
if (a[j] > a[j+1])
{
冲备 int tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
}
}
printf("排序后:");
for (int i = 0; i < 3; i++)
{
printf("%d ", a[i]);
}
}
// 第六题
#include
void main()
{
for (int i = 100; i <= 200; i++)
{
if (2 == i %3 && 3 == i % 5 && 2 == i %7)
键局{
printf("%d ", i);
}
}
}
1.
#include
#include
void main()
{
double 皮手a, b, c, s, area;
printf("三角形三边长(a, 运毕b, c):");
scanf("%lf, %lf, %lf", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s -a) * (s - b) * (s - c));
printf("三角形面积:%lf\n", area);
}
2.
#include
void main()
{
double a, b;
double add, sub, pro, div;
printf("输入两个数(以空格分隔):");
scanf("%lf%lf", &a, &b);
add = a + b;
sub = a - b;
pro = a * b;
div = a / b;
printf("%lf + %lf = %lf\n", a, b, add);
printf("%lf - %lf = %lf\n", a, b, sub);
printf("%lf * %lf = %lf\n", a, b, pro);
printf("%lf / %lf = %lf\n", a, b, div);
}
3.
#include
#include
int isPrime(int n)
{
int i;
int k = (int)sqrt(n);
for(i=2; i<=k; i++)
if(n % i == 0)
return 0;
return 1;
}
void main()
{
int i;
long sum = 0;
for(i=100; i<=230; i++)
if(isPrime(i) == 1)
sum += i;
printf("素数和:%ld\n", sum);
}
4.
#include
void main()
{
int score;
printf("成绩:");
scanf("%d", &score);
if(score < 0 || score > 100)
printf("error");
else if(score >= 90)
printf("excellent");
else 燃悄嫌if(score >= 80)
printf("good");
else if(score >= 70)
printf("general");
else if(score >= 60)
printf("pass");
else
printf("no pass");
}
5.
#include
void main()
{
int a, b, c;
printf("输入三个数(以空格分隔):");
scanf("%d%d%d", &a, &b, &c);
if(a > b)
if(a > c)
if(b > c)
printf("%d %d %d\n", c, b, a);
else
printf("%d %d %d\n", b, c, a);
else
printf("%d %d %d\n", b, a, c);
else
if(b > c)
if(a > c)
printf("%d %d %d\n", c, a, b);
else
printf("%d %d %d\n", a, c, b);
else
printf("%d %d %d\n", a, b, c);
}
6.
#include
void main()
{
int n;
for(n=100; n<=200; n++)
if(n%3==2 && n%5==3 && n%7==2)
printf("%d\n", n);
}