21.时间转换
方法一:
#include <stdio.h>
int main()
{
int seconds;
int h = 0;
int min = 0;
int s = 0;
while (scanf("%d", &seconds) != EOF)
{
h=seconds/60/60;
min = (seconds-h*3600)/60;
s = seconds - (h*3600)-(min*60);
printf("%d %d %d",h,min,s);
}
return 0;
}
方法二:
#include<stdio.h>
int main ()
{
int a;
while(~scanf("%d",&a))
{
printf("%d %d %d",a/3600,(a%3600)/60,a%60);
}
return 0;
}
22.计算总成绩和平均分
#include <stdio.h>
int main()
{
float a, b, c, sum, average;
scanf("%f %f %f", &a, &b, &c);
sum = a+b+c;
average = sum/3;
printf("%.2f %.2f",sum, average);
return 0;
}
23.计算体重指数
#include<stdio.h>
int main()
{
float a,b;
scanf("%f %f",&a,&b);
b=b/100;
printf("%.2f",a/(b*b));
return 0;
}
24.计算三角形的周长和面积
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,p;
scanf("%f %f %f",&a,&b,&c);
p=(a+b+c)/2;
printf("circumference=%.2f area=%.2f",a+b+c,sqrt(p*(p-a)*(p-b)*(p-c)));
return 0;
}
25.大小写转换
将大写字母变成小写字母,只需要将它们的ASCII加32即可,然后输出。
#include <stdio.h>
int main()
{
char a = 0;
while (~scanf("%c",&a))
{
printf("%c\n", a+32);
getchar();//吸收掉\n
}
return 0;
}