这个C语言程序里加一个ESC退出程序
#include<stdio.h>#include<stdlib.h>voidweishu();voidmain(){weishu();}voidweishu(){int...
#include <stdio.h>
#include <stdlib.h>
void weishu();
void main()
{
weishu();
}
void weishu()
{
int choice,number;
int key, modifiers;
printf("1.输入一位数 2.输入二位数 3.输入三位数 4.输入四位数 5.输入五位数(退出请按esc)\n");
scanf("%d",&choice);
printf("请输入数字(请输入位数与选择保持一致): ");
scanf("%d",&number);
switch(choice)
{
case 5:
printf("\t%d ",number / 10000);
number = number % 10000;
case 4:printf("\t%d ",number / 1000);
number = number % 1000;
case 3:printf("\t%d ",number / 100);
number = number % 100;
case 2:printf("\t%d ",number / 10);
number = number % 10;
case 1:printf("\t%d ",number);
printf("\n");
weishu();
default:
weishu();
}
} 展开
#include <stdlib.h>
void weishu();
void main()
{
weishu();
}
void weishu()
{
int choice,number;
int key, modifiers;
printf("1.输入一位数 2.输入二位数 3.输入三位数 4.输入四位数 5.输入五位数(退出请按esc)\n");
scanf("%d",&choice);
printf("请输入数字(请输入位数与选择保持一致): ");
scanf("%d",&number);
switch(choice)
{
case 5:
printf("\t%d ",number / 10000);
number = number % 10000;
case 4:printf("\t%d ",number / 1000);
number = number % 1000;
case 3:printf("\t%d ",number / 100);
number = number % 100;
case 2:printf("\t%d ",number / 10);
number = number % 10;
case 1:printf("\t%d ",number);
printf("\n");
weishu();
default:
weishu();
}
} 展开
推荐于2018-04-05
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void weishu();
#define Key_Esc 0x1b //Esc键值
void main()
{
weishu();
}
void weishu()
{
while(1)
{
int choice=0,number=0,key=0;
printf("1.输入一位数 2.输入二位数 3.输入三位数 4.输入四位数 5.输入五位数(退出请按Esc键)\n");
while(1)
{
key =getch();
if(key!=0)
break;
}
if(key==Key_Esc) break;
choice=key-0x30; //字符转化为数字
printf("请输入数字(请输入位数与选择保持一致): ");
scanf("%d",&number);
switch(choice)
{
case 5:
printf("\t%d ",number / 10000);
number = number % 10000;
case 4:printf("\t%d ",number / 1000);
number = number % 1000;
case 3:printf("\t%d ",number / 100);
number = number % 100;
case 2:printf("\t%d ",number / 10);
number = number % 10;
case 1:printf("\t%d ",number);
printf("\n");
default:
continue;
}
}
}
#include <stdlib.h>
#include <conio.h>
void weishu();
#define Key_Esc 0x1b //Esc键值
void main()
{
weishu();
}
void weishu()
{
while(1)
{
int choice=0,number=0,key=0;
printf("1.输入一位数 2.输入二位数 3.输入三位数 4.输入四位数 5.输入五位数(退出请按Esc键)\n");
while(1)
{
key =getch();
if(key!=0)
break;
}
if(key==Key_Esc) break;
choice=key-0x30; //字符转化为数字
printf("请输入数字(请输入位数与选择保持一致): ");
scanf("%d",&number);
switch(choice)
{
case 5:
printf("\t%d ",number / 10000);
number = number % 10000;
case 4:printf("\t%d ",number / 1000);
number = number % 1000;
case 3:printf("\t%d ",number / 100);
number = number % 100;
case 2:printf("\t%d ",number / 10);
number = number % 10;
case 1:printf("\t%d ",number);
printf("\n");
default:
continue;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询