C语言求最大公约数问题

怎么输入多行数据,回车后输出多行结果
输入说明
多组数据,每组数据由同一行的两个正整数a和b构成(0<=a,b<10000),a和b之间用空格分隔,当a和b都为0时表示输入结束
输出说明
对每组数据输出其最大公约数后换行
输入样例
2 4
12 6
3 5
0 0
输出样例
2
6
1

 #include<stdio.h>

int gcd(int a,int b)
{
    if(a==0&&b!=0)
        return b;
    else if(a!=0&&b==0)
        return a;
    else if(a==1||b==1)
        return 1;
    else
        {
            int t;
            while(b!=0)
            {
                t=a%b;
                a=b;
                b=t;
            }
            return a;
        }
}

int main()
{
    int a,b;
    while(1)
    {
        scanf("%d %d",&a,&b);
        if(a==0&&b==0)
            break;
        printf("%d\n",gcd(a,b));
    }
    return 0;
}

如果问题得到解决,请点我回答左上角的采纳和向上的箭头,谢谢

#include<stdio.h>
#include<stdlib.h>

typedef struct node
{
    int x;
    node * next;
} * List;

int gcd(int a,int b)
{
    if(a==0&&b!=0)
        return b;
    else if(a!=0&&b==0)
        return a;
    else if(a==1||b==1)
        return 1;
    else
        {
            int t;
            while(b!=0)
            {
                t=a%b;
                a=b;
                b=t;
            }
            return a;
        }
}

int main()
{
    int a,b;
    List list = NULL;
    node * p = NULL;
    while(1)
    {
        scanf("%d %d",&a,&b);
        if(a==0&&b==0)
            break;
        if (!list)
        {
            list = p = (node *)malloc(sizeof(node));
            p->x = gcd(a,b);
            p->next = NULL;
        }
        else
        {
            p->next = (node *)malloc(sizeof(node));
            p = p->next;
            p->x = gcd(a,b);
            p->next = NULL;         
        }
    }
    p = list;
    while (p)
    {
        printf("%d\n",p->x);
        p = p->next;
    }
    return 0;
}