c语言 帮帮我吧,不然要被老师骂了

来源:百度知道 编辑:UC知道 时间:2024/05/30 10:25:59
定义一个结构体数组存储若干个分数,计算并输出它们的乘积([1] 采用直接初始化方法设置分数(3~5个分数即可)
[2] 计算之后的输出形式为:
These fractions are: 1/2,1/3,4/5
Their product is 4/30)

#include<stdio.h>

struct tt
{
int x,y; // 分子分母
};

tt t[5];

int main(void)
{
int n; //分数个数
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d/%d",&t[i].x,&t[i].y);
int xx,yy;
xx=yy=1;
for(i=0;i<n;i++)
xx*=t[i].x,yy*=t[i].y;
printf("%d",xx);
printf("/");
printf("%d\n",yy);

return 0;
}

输入
3
1/2 1/3 4/5
输出4/30

#include<stdio.h>
#include <malloc.h>
typedef struct student{
int sno;
char name[20];
char gender[5];
int score;
}student;

typedef struct stu{
student student1; //这里不能都是student
struct stu *next;
}stu;
stu *head;

void createlist(int n){
stu *p,*t;
int i;
head=(stu*)malloc(sizeof(stu)); //复习一下malloc的用法
head->next=NULL;
p