请问改如何简化代码
我是个新手,写了个程序,程序才写了1/3,就觉得很麻烦,很多语句都是重复在用的。请问有什么方法能简化?我在Qbasic里能用call 子程序,但是在c里好像print_***里面就不能在含有另外的print_***了,那用什么语句能写子程序呢?这是我的程序,我不是要最后算出什么值。而是要在几种情况下画出些不同框
#include <stdio.h>
int main (void)
{
int numbera,numberb,sum;
int number1=0,number2=0,number3=0;
int unit,space;
printf ("a\n");
scanf ("%d",&numbera);
printf ("b\n");
scanf ("%d",&numberb);
sum=numbera+numberb;
for (space=1;space<=2*numbera;space++) //line1
{
printf(" ");
}
printf("+");
for(unit=0;unit<=18;unit++)
{
printf("-");
}
printf("+\n");
for (space=1;space<=2*numbera;space++) //line2
{
printf(" ");
}
printf("|");
for(unit=0;unit<9;unit++)
{
printf("%d ",number1);
number1=number1+1;
}
printf("9|\n");
if(sum<10) //sum big or small than 10
{
printf("+"); //line3
for(unit=1;unit<=2*numbera-1;unit++)
{
printf("-");
}
printf("+");
for(unit=0;unit<=18-numbera*2;unit++)
{
printf("-");
}
printf("+");
for(unit=1;unit<=2*numbera-1;unit++)
{
printf("-");
}
printf("+\n");
printf("|"); //line4
for(unit=0;unit<9;unit++)
{
printf("%d ",number2);
number2=number2+1;
}
printf("9|\n");
printf("+"); //line5
for(unit=0;unit<=18;unit++)
{
printf("-");
}
printf("+\n");
for (space=1;space<=1+sum*2;space++) //line6
{
printf(" ");
}
printf("^\n");
}
else
{
printf("+"); //line3
for(unit=1;unit<=2*numbera-1;unit++)
{
printf("-");
}
printf("+");
for(unit=0;unit<=18-numbera*2;unit++)
{
printf("-");
}
printf("+");
for(unit=1;unit<=2*numbera-1;unit++)
{
printf("-");
}
printf("+");
for(unit=0;unit<=18-numbera*2;unit++)
{
printf("-");
}
printf("+\n");
printf("|"); //line4
for(unit=0;unit<9;unit++)
{
printf("%d ",number2);
number2=number2+1;
}
printf("9|");
for(unit=0;unit<9;unit++)
{
printf("%d ",number3);
number3=number3+1;
}
printf("9|\n");
printf("+"); //line5
for(unit=0;unit<=18;unit++)
{
printf("-");
}
printf("+");
for(unit=0;unit<=18;unit++)
{
printf("-");
}
printf("+\n");
for (space=1;space<=1+sum*2;space++) //line6
{
printf(" ");
}
printf("^\n");
}
return (0);
}