A. C语言 输入一个整数 实行编写菜单命令
#include "stdio.h"
void prt()
{
printf("\n*****************Menu******************\n");
printf("1. Add 1\n");
printf("2. Multiply by 2\n");
printf("3. Subtract 4\n");
printf("4. Quit\n");
printf("***************** **********************\n");
printf("Please choose an operation (1-4):");
}
main()
{
int a,s;
printf("Please enter an integer:");
scanf("%d",&a);
prt();
scanf("%d",&s);
while(s!=4)
{
switch(s)
{
case 1: printf("Now, the integer is: %d",a+1); break;
case 2: printf("Now, the integer is: %d",a*2); break;
case 3: printf("Now, the integer is: 44"); break;
default: printf("Now, the integer is: 44"); break;
}
prt();
scanf("%d",&s);
}
printf("/* program is terminated here and return to the operating system */");
}
B. C语言中怎样定义,才能制作一个以菜单方式运行的程序
这是我以前做过的一个,你可以参考一下。利用k
do
{
//Console.Write("输入0结束,任意键继续");
//k = Console.ReadKey().KeyChar;
Console.Clear();
Console.WriteLine("*******************主菜单*******************");
Console.WriteLine("**************选择你要的服务:**************");
Console.WriteLine("****************1、输入信息*****************");
Console.WriteLine("****************2、浏览信息*****************");
Console.WriteLine("****************3、排序*********************");
Console.WriteLine("****************4、查询*********************");
Console.WriteLine("****************5、结束*********************");
int num = 0;
Console.Write("请输入您的选择:");
num = int.Parse(Console.ReadLine());
switch (num)
{
case 1:
{
Console.Clear();
for (int i = 1; i < m+1; i++)
{
Console.Write("请输入学生{0}的学号(姓名):",i);
iArray[i, 0] = Convert.ToString(Console.ReadLine());
for (int j = 1; j < n+1; j++)
{
//Console.WriteLine();
Console.Write("{0}的成绩:",iArray[0,j]);
iArray[i, j] = Convert.ToString(Console.ReadLine());
}
}
} break;
case 2:
{
Console.Clear();
for (int j = 0; j < n + 1; j++)
Console.Write("{0}\t",iArray[0,j]);
for (int i = 1; i < m + 1; i++)
{ Console.WriteLine();
for (int j = 0; j < n + 1; j++)
Console.Write("{0}\t", iArray[i, j]);
}
Console.WriteLine("\n按任意键回主菜单");
Console.ReadLine();
} break;
case 3:
{
Console.Clear();
int num3=0;
string temp,temp1;
int k3 = 1;
do
{
Console.Clear();
Console.WriteLine("选择排序的科目:");
for (int j = 1; j < n + 1; j++)
{
Console.WriteLine("{0}、按{1}", j, iArray[0, j]);
}
Console.WriteLine("{0}、返回主菜单", n + 1);
if (!int.TryParse(Console.ReadLine(), out num3))
return;
for (int m1 = 1; m1 < n + 1; m1++)
if (num3 == m1)
{
for (int i = 1; i < m; i++)
for (int n1 = i + 1; n1 < m + 1; n1++)
if (string.Compare(iArray[i, num3], iArray[n1, num3]) < 0)
{
temp = iArray[i, num3];
temp1=iArray[i,0];
iArray[i, num3] = iArray[n1, num3];
iArray[i,0]=iArray[n1,0];
iArray[n1, num3] = temp;
iArray[n1, 0] = temp1;
}
Console.Clear();
Console.Write("{0}\t", iArray[0, 0]);
Console.Write("{0}\t", iArray[0, num3]);
for (int i = 1; i < m + 1; i++)
{
Console.WriteLine();
Console.Write("{0}\t", iArray[i, 0]);
Console.Write("{0}",iArray[i,num3]);
}
Console.WriteLine("\n{0}最高分为{1},最低分为{2}",iArray[0,num3],iArray[1,num3],iArray[m,num3]);
Console.ReadLine();
}
else if (num3 == n + 1)
k3 = 0;
} while (k3 != 0);
} break;
case 4:
Console.Clear();
Console.Write("请输入要查找的学号(姓名):");
string x;
x = Console.ReadLine();
int pos = -1;
for (int i = 1; i < m+1; i++)
if (string.Equals(x,iArray[i, 0]))
{
pos = i;
Console.WriteLine("{0}在数组中位置为{1}", x, pos);
for (int j = 0; j < n + 1; j++)
Console.Write("{0}\t", iArray[0, j]);
Console.WriteLine();
for (int j = 0; j < n + 1; j++)
Console.Write("{0}\t", iArray[pos, j]);
}
if (pos == -1)
Console.WriteLine("{0}不存在于数组中", x);
Console.ReadLine();
break;
case 5:
k = 0;
break;
}
}
while (k!=0);
C. 用C语言创建文本菜单的window函数有哪些用法
C语编出来的不能直接在windows环境运行,必须在DOS下才能用~
菜单-所有程序-附件-命令提示符
D. C语言实现命令行窗口
1、函数名: window
功 能: 定义活动文本模式窗口
用 法: void window(int left, int top, int right, int bottom);
2、例程:
#include<conio.h>
intmain(void){
window(10,10,40,11);
textcolor(BLACK);
textbackground(WHITE);
cprintf("Thisisatest ");
return0;
}
E. C语言中如何通过带参数的命令行实现类似菜单选择功能
int main(int argc, char* argv[])
{
}
argv是个二维数组,自己对argv里的参数进行判断,tc不严格,最好用VC++
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
F. 怎么用C语言编写菜单
#include "stdio.h"
#include "stdlib.h"
#include "dos.h"
#include "windows.h"
char choice1;
void main()
{
void menue1();
printf("欢迎进入Ben的作业查询系统!");
menue1();
}
void menue1()
{
void choicemenue1();
printf("\n请按照以下列表选择您想要查看的章节:");
printf("\n编号\t章节\n 1\t第一章\n 2\t第二章\n");
printf("请输入编号进行选择:");
choicemenue1();
}
void choicemenue1()
{
choice1=getch();
switch(choice1)
{
void menuechapter1();
void menuechapter2();
void menue1();
case '1':menuechapter1();break;
case '2':menuechapter2();break;
default:printf("\n输入错误!请重新选择!\n"),menue1();
}}
void menuechapter1()
{
char choiceex;
printf("\n您选择的是第%c章",choice1);
printf("\n现在请选择本章节的题目。");
printf("\n请按照以下列表选择题目:");
printf("\n编号\t题目编号\n1\t第1题\n2\t第2题\n");
printf("请选择:");
switch(choiceex=getch())
{
void c1_1();
void c1_2();
case '1':c1_1();break;
case '2':c1_2();break;
default:
printf("\n你个白痴!这也能选错!不让你重选了!");
printf("\n按任意键以退出!");
getch();
exit(0);
}
}
void menuechapter2()
{
char choiceex;
printf("\n您选择的是第%c章",choice1);
printf("\n现在请选择本章节的题目。");
printf("\n请按照以下列表选择题目:");
printf("\n编号\t题目编号\n1\t第1题\n2\t第2题\n");
printf("\n请选择:");
switch(choiceex=getch())
{
void c2_1();
void c2_2();
case '1':c2_1();break;
case '2':c2_2();break;
default:
printf("\n你个白痴!这也能选错!不让你重选了!");
printf("\n按任意键以退出!");
getch();
exit(0);
}
}
void c1_1()
{
char howtorun;
printf("现在请选择考察方式:");
printf("\n编号\t考察方式\n 1\t运行程序\n 2\t查看源代码\n 3\t返回主菜单\n 4\t退出程序\n");
printf("请选择:");
switch(howtorun=getch())
{
void runc1_1();
void menue1();
case '1':runc1_1();break;
case '2':printf("\n"),system("type \\caidan\\chapter1\\c1_1.c"),printf("\n"),getch();break;
case '3':menue1();break;
case '4':exit(0);break;
default:
printf("程序即将结束!哈哈哈……");
printf("按任意键以结束程序!");
getch();
exit(0);
}}
void c1_2()
{
printf("c1_2 is OK!");
}void c2_1()
{
printf("c2_1 is OK!");
}void c2_2()
{
printf("c2_2 is OK!");
}
void runc1_1()
{
int a,b,max;
printf("\nPlease input two integer numbers:");
printf("a=?,b=?\n");
scanf("%d,%d",&a,&b);
max=a>b?a:b;
printf("The max number is %d",max);
}
大概就是这样做的。。
G. 怎样用C语言编写菜单
对于窗口组件菜单,需要根据不同平台,通过图形编程接口,进行菜单的编制。
例程:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
voidmain()
{
charstr;
inti,k,choice=1;
intgd=DETECT,gm;
initgraph(&gd,&gm,"");
setbkcolor(2);
settextstyle(3,0,3);
outtextxy(140,120,"A.TheMockClock.");
outtextxy(140,150,"B.TheDigitalClock.");
outtextxy(140,180,"C.Exit.");
setlinestyle(0,0,3);
rectangle(170,115,370,145);
/*按上下键选择所需选项*/
for(i=1;i<=100;i++)
{
str=getch();
if(str==72)
{
--choice;
if(choice==0)choice=3;
}
if(str==80)
{
++choice;
if(choice==4)choice=1;
}
if(str==13)break;/*按回车键确认*/
/*画图做菜单*/
cleardevice();
switch(choice)
{case1:setlinestyle(0,0,3);
rectangle(170,115,400,145);
settextstyle(3,0,3);
outtextxy(140,120,"A.TheMockClock.");
settextstyle(3,0,3);
outtextxy(140,150,"B.TheDigitalClock.");
outtextxy(140,180,"C.Exit.");
break;
case2:setlinestyle(0,0,3);
rectangle(170,145,400,175);
settextstyle(3,0,3);
outtextxy(140,120,"A.TheMockClock.");
settextstyle(3,0,3);
outtextxy(140,150,"B.TheDigitalClock.");
settextstyle(3,0,3);
outtextxy(140,180,"C.Exit.");
break;
case3:settextstyle(3,0,3);
outtextxy(140,120,"A.TheMockClock.");
outtextxy(140,150,"B.TheDigitalClock.");
settextstyle(3,0,3);
outtextxy(140,180,"C.Exit.");
setlinestyle(0,0,3);
rectangle(170,175,400,205);
break;
}
}
if(i>=100)exit(0);/*如果按键超过100次退出*/
switch(choice)/*这里引用函数,实现所要的功能*/
{
case1:cleardevice();
setbkcolor(4);
settextstyle(3,0,4);
outtextxy(160,120,"No.1havenotbuilt.");break;
case2:cleardevice();
setbkcolor(4);
settextstyle(3,0,4);
outtextxy(160,150,"No.2havenotbuilt.");
break;
case3:exit(0);
}
getch();
closegraph();
}
对于命令行菜单,直接通过不断刷新输出来模拟菜单行为。
例程:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
intn,t,k;
intm;
chars1[20],s2[20],c;
char**l;
char*num[]={"one","two","three","four","five","six","seven","eight","nine","ten"};
voidmenu()
{
printf(" ******************************************************* ");
printf(" **1.查找字符串S1中S2出现的次数** ");
printf(" **2.统计字符串中大小写字母,数字出现的次数** ");
printf(" **3.将数字翻译成英语** ");
printf(" **4.结束** ");
printf(" ******************************************************* ");
printf(" 您的输入:");
fflush(stdin);
scanf("%d",&n);
}
voidcheck()
{
chara[20],b[20];
intj=0,k,m,l=0;
intt=0,n=0;
printf("请输入主字符串: ");
scanf("%s",a);
k=strlen(a);
printf("请输入子字符串: ");
scanf("%s",b);
m=strlen(b);
for(n=0;n<k;n++)
if(a[n]==b[0])
{
j++;/*记录相同的字符数*/
do
{
if(a[++n]==b[++t])
{
j++;
if(j==m)
{
l++;/*子字符串相同数*/
j=0;/*判断后相同字符数归零*/
t=-1;/*判断中if中++t;t将会归零*/
}
}
else
{
j=0;
t=0;
break;/*如果不同跳出while循环让for使n+1继续判断*/
}
}while(a[n]!='