1.
#include<stdio.h>
int main(){
for (int i = 0; i < 3; i++)
{
for (int j = 2; j >i; j--)
printf(" ");
for (int t = 2*i + 1; t > 0; t--)
printf("*");
printf("\n");
}
for(int a=0;a<2;a++)
{
for (int b = 0; b < a+1; b++)
printf(" ");
for (int c = 2; c > 2*a-1; c--)
printf("*");
printf("\n");
}
return 0;
}
2.
大小写字母转换
#include<stdio.h>
int main() {
char a;
scanf_s("%c",&a);
a = a - 32;
printf("%c", a);
return 0;
}
3.
#include<stdio.h>
int main() {
float a,g;
int b, c, d;
scanf_s("%f",&a);
b = a / 100;
c = (a - 100*b)/10;
d = (a -10*c-100*b);
g = (a - 10 * c -100 * b - d) * 10;
a = (float)b / 1000 + (float)c / 100 + (float)d / 10 + (int)g;
printf("%g",a);
return 0;
}
标答:太简洁了
#include <cstdio>
using namespace std;
char a, b, c, d; int main()
{ scanf("%c%c%c.%c", &a, &b, &c, &d); printf("%c.%c%c%c", d, c, b, a); return 0; }
4.
#include<stdio.h>
int main() {
float a;
int n;
scanf_s("%f", &a);
scanf_s("%d", &n);
printf("%.3f\n",a/n);
printf("%d", n*2);
return 0;
}
5.
#include<stdio.h>
#include <math.h>
int main() {
float a,b,c,p,s;
scanf_s("%f%f%f", &a,&b,&c);
p = (a + b + c) / 2;
s = sqrt(p*(p-a)*(p-b)*(p-c));
printf("%.1f", s);
return 0;
}
数据部分不通过,检查答案发现是float精度不够的问题
#include<stdio.h>
#include <math.h>
int main() {
double a,b,c,p,s;
scanf_s("%f%f%f", &a,&b,&c);
p = (a + b + c) / 2;
s = sqrt(p*(p-a)*(p-b)*(p-c));
printf("%.1f", s);
return 0;
}
6.
#include<stdio.h>
int main() {
int h, r,i=1;
scanf_s("%d%d", &h,&r);
double t = 3.14 * r * r * h;
for (; t/1000*i < 20; ) {
i++;
}
printf("%d",i );
return 0;
}
7.
#include<stdio.h>
int main() {
int a,b,c,d,e,f;
scanf_s("%d%d%d%d", &a,&b,&c,&d);
if (b > 0) {
e = c - a - 1;
f = 60 - b + d;
}
else
{
e = c - a;
f = d;
}
printf("%d %d",e,f );
return 0;
}
8.
#include<stdio.h>
int main() {
double a,b,c;
scanf_s("%lf%lf", &a,&b);
c = a + b / 10;
printf("%d",(int)(c/1.9) );
return 0;
}
9.
#include<stdio.h>
int main() {
double a,b,c,e;
scanf_s("%lf%lf%lf", &a,&b,&c);
e = 0.2 * a + 0.3 * b + 0.5 * c;
printf("%g",e);
return 0;
}