#include"stdio.h"
#include"string.h"
void main()
{
float a,b;
char c[10],d[10];
printf("请输入原本单位:");
scanf("%s",c);
printf("请输入数字:");
scanf("%f",&a);
if(strcmp(c,"pound")==0)
{
b=0.45*a;
strcpy(d,"kg");
printf("%.3f%s",b,d);
}
else if(strcmp(c,"kcal")==0)
{
b=4*a;
strcpy(d,"kj");
printf("%.3f%s",b,d);
}
else
{
printf("wrong");
}
getch();
}
亲测有效#单位换算##C语言#
#include"string.h"
void main()
{
float a,b;
char c[10],d[10];
printf("请输入原本单位:");
scanf("%s",c);
printf("请输入数字:");
scanf("%f",&a);
if(strcmp(c,"pound")==0)
{
b=0.45*a;
strcpy(d,"kg");
printf("%.3f%s",b,d);
}
else if(strcmp(c,"kcal")==0)
{
b=4*a;
strcpy(d,"kj");
printf("%.3f%s",b,d);
}
else
{
printf("wrong");
}
getch();
}
亲测有效#单位换算##C语言#