C语言实例教程:四则运算
文章类别:
C语言程序设计 | 发表日期:2010-11-8 9:00:14
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
Add()
{int a,b,c;
char d;
loop: textmode(2);
window(1,5,80,20);
textbackground(BLUE);
textcolor(WHITE);
clrscr();
gotoxy(25,7);
cprintf("***Querstion 1*** :");
gotoxy(23,10);
randomize();
a=random(100);
b=random(100);
printf("%d+%d=",a,b);
scanf("%d",&c);
getchar();
if(c==a+b)
printf(" Right!");
else
printf(" Wrong!");
printf("Shifoujixu? y/n");
scanf("%c",&d);
if(d=='y'||d=='Y')
goto loop;
else
main();
};
Sub()
{
int a,b,c;
char d;
loop: textmode(2);
window(1,5,80,20);
textbackground(BLUE);
textcolor(WHITE);
clrscr();
gotoxy(25,7);
cprintf("***Querstion 1*** :");
gotoxy(23,10);
randomize();
a=random(100);
b=random(100);
printf("%d-%d=",a,b);
scanf("%d",&c);
getchar();
if(c==a-b)
printf(" Right!");
else
printf(" Wrong!");
printf("Shifoujixu? y/n");
scanf("%c",&d);
if(d=='y'||d=='Y')
goto loop;
else
main();
};
Mul()
{int a,b,c;
char d;
loop: textmode(2);
window(1,5,80,20);
textbackground(BLUE);
textcolor(WHITE);
clrscr();
gotoxy(25,7);
cprintf("***Querstion 1*** :");
gotoxy(23,10);
randomize();
a=random(100);
b=random(100);
printf("%d*%d=",a,b);
scanf("%d",&c);
getchar();
if(c==a*b)
printf(" Right!");
else
printf(" Wrong!");
printf("Shifoujixu? y/n");
scanf("%c",&d);
if(d=='y'||d=='Y')
goto loop;
else
main();
};
Div1()
{int a,b,c;
char d;
loop: textmode(2);
window(1,5,80,20);
textbackground(BLUE);
textcolor(WHITE);
clrscr();
gotoxy(25,7);
cprintf("***Querstion 1*** :");
gotoxy(23,10);
randomize();
a=random(100);
b=random(100);
printf("%d/%d=",a,b);
scanf("%d",&c);
getchar();
if(c==a/b)
printf(" Right!");
else
printf(" Wrong!");
printf("Shifoujixu? y/n");
scanf("%c",&d);
if(d=='y'||d=='Y')
goto loop;
else
main();
};
main()
{char ch;
clrscr();
textmode(2);
window(1,5,80,20);
textbackground(BLUE);
textcolor(WHITE);
clrscr();
gotoxy(10,5);
cprintf(" === yapojijiang ===");
gotoxy(19,8);
cprintf("1. Add Test 2. Sub Test");
gotoxy(19,10);
cprintf("3. Mul Test 4. Div Test");
gotoxy(28,12);
cprintf("5. Exit");
gotoxy(25,15);
cprintf("Please chose 1-5:");
ch=getchar();
switch(ch)
{case'1':Add();break;
case'2':Sub();break;
case'3':Mul();break;
case'4':Div1();break;
case'5':exit(0);
}
}