问题描述:
小数可以看成是一个点和两个数组成的,因此可以定义成一个小数的结构体,现在请用结构体的知识来计算两个小数相加。
注意:不考虑进位,输入的值都是小数,小数位只有一位。
代码:#include <stdio.h>
#include <stdlib.h>
struct xiaoshu
{
int head;
int tail;
char point;
}a,b;
int main()
{
struct xiaoshu a,b;
void add(struct xiaoshu,struct xiaoshu);
scanf("%d%c%d",&a.head,&a.point,&a.tail);
scanf("%d%c%d",&b.head,&b.point,&b.tail);
add(a,b);
return 0;
}
void add(struct xiaoshu a,struct xiaoshu b)
{
printf("%d",a.head+b.head);
printf(".");
printf("%d",a.tail+b.tail);
}