#include"stdioh"
int main()
{
do{
int num;
printf("主菜单项:\n1-预览添加\n2-查找修改\n3-删除\n0-退出系统\n");
printf("请选择 *** 作:");
scanf("%d",&num);
switch (m)
{
case 1:
printf("信息预览添加\n");
break;
case 2:
printf("信息查找修改\n");
break;
case 3:
printf("信 息 删 除\n");
break;
case 0:
printf("退 出 系 统\n");
exit(0);
default:
break;
}
}while(num!=0);
return 0;
}
#include <stdioh>
#include <stringh>
typedef struct Tpeople
{
int party;
char name[22];
int footFlag;
}Tpeople,PTpeople;
void initPeople(Tpeople people[5]);
int is_li_sun(Tpeople people[5]);
int is_zhao_qian_sun(Tpeople people[5]);
int is_football(Tpeople people[5]);
int is_zhao_zhou_movie(Tpeople people[5]);char movie = "Movie";
char football = "Football";
char restrant = "Restrant";void main()
{
int i , j , k , l , m;
int count = 0;
Tpeople people[5]; // 赵钱孙李周 == 0 1 2 3 4 看**、踢足球和去餐馆 == 0 1 2
int Tbool;
initPeople(people); for(i = 0 ; i != 3; ++i )
{
if(people[0]party == 1)
people[0]footFlag = 1;
else
people[0]footFlag = 0;
for( j = 0; j != 3; ++j)
{
if(people[1]party == 1)
people[1]footFlag = 1;
else
people[1]footFlag = 0;
for( k = 0; k != 3; ++k)
{
if(people[2]party == 1)
people[2]footFlag = 1;
else
people[2]footFlag = 0;
for( l = 0; l != 3; ++l)
{
if(people[3]party == 1)
people[3]footFlag = 1;
else
people[3]footFlag = 0;
for( m = 0; m != 3; ++m)
{
if(people[4]party == 1)
people[4]footFlag = 1;
else
people[4]footFlag = 0;
Tbool = is_li_sun(people)&&is_zhao_qian_sun(people)&&is_football(people)&&is_zhao_zhou_movie(people);
if(Tbool)
{
count = 0;
for(; count != 5; ++count)
{
switch (people[count]party)
{
case 0:
strcpy(people[count]name, "movie");
break;
case 1:
strcpy(people[count]name,"football");
break;
case 2:
strcpy(people[count]name,"restrant");
break;
default:
break;
}
}
printf("Zhao: %s Qian: %s Sun: %s Li: %s Zhou: %s \n",people[0]name,people[1]name,people[2]name,people[3]name,people[4]name);
printf("Zhao: %d Qian: %d Sun: %d Li: %d Zhou: %d \n",people[0]party,people[1]party,people[2]party,people[3]party,people[4]party);
printf("\n");
}
people[4]party++;
}
people[4]party = 0;
people[3]party++; }
people[3]party = 0;
people[2]party++; }
people[2]party = 0;
people[1]party++; }
people[1]party = 0;
people[0]party++; }
}void initPeople(Tpeople people[5])
{
int i = 0;
for (;i !=5 ; ++i)
{
people[i]party = 0;
people[i]footFlag = 0;
}
}int is_li_sun(Tpeople people[5])
{
if(people[2]party == people[3]party)
return 0;
return 1;
}int is_zhao_qian_sun(Tpeople people[5])
{
if( (people[0]party != people[1]party) && (people[1]party != people[2]party) && (people[0]party != people[2]party))
return 1;
return 0;
}int is_football(Tpeople people[5])
{
int i,count = 0;
for(i = 0; i != 5; ++i)
if(people[i]footFlag == 1)
count++;
if(count == 2)
return 1;
return 0;
}int is_zhao_zhou_movie(Tpeople people[5])
{
if(((people[0]party == 0) && (people[4]party == 0)) || ((people[0]party != 0) && (people[4]party != 0)))
return 1;
return 0;
}
#include
#include
#define M 15
void getx(int s);
void putx(int s[]);
int sum(int x,int s[]);
main()
{
int x[M]={0},i;
getx(x);
putx(x);
for(i=0;i<15;i++)printf("%d ",x[i]);
printf("\n");
for(i=0;i<15;i++)
printf("%d ",sum(i,x));
system("PAUSE");
}
void getx(int s)
{
int i=0;
for(;i<M;i++)
s++=rand()%50;
}
void putx(int s[])
{
int i=0;
for(;i<M;i++)
printf("%d\t",s++);
printf("\n");
}
int sum(int y,int s[])
{ int i,t=0;
for(i=0;i<4;i++)
t=t+s[(y+i)%15];
return(t);
}
#include <stdioh>
int calc(int n)
{
if (0 == n || 1 == n)
{
return 1;
}
return n calc(n -1);
}
void main()
{
int n = 0;
printf("请输入n的值:\n");
scanf("%d", &n);
double s = 0;
for (int i = 1; i <= n; i++)
{
//这里要注意下,需要转成浮点型相除,否则结果永远是0
s = 10/calc(n);
}
printf("s = %lf\n", s);
}
运行结果:
第6题目(我本来是日文的,所以有乱码自己改吧)
#include <stdioh>
int main(void)
{
int n;
int i=0;
int max=0;
int min=101;
int z=0;
int p=2;
while(1!=p)
{++i;
printf("成绩输入:\n");
scanf("%d",&n);
if(n<50) printf("D\n");
else
{
if(n<65) printf("C ");
else if(n<80) printf("B ");
else if(n<=100) printf("A ");
printf("崌奿\n");
}
printf("继续2,结束1\n""(1or 2)");
scanf("%d",&p);
}
return(0);
}
闰年(自己稍微改下输出)
#include <stdioh>
#include <stdlibh>
int main()
{
int year;
scanf("%d",&year);
if(year %400==0 || (year%4==0 && year%100))
printf("%d is leap year\n",year);
else
printf("%d is not leap year\n",year);
return 0;
}
三角形(找的我累死了,全是作业题目,还好都在)
#include<stdioh>
void main()
{
float a,b,c;
printf("输入三个数字:");
scanf("%f,%f,%f",&a,&b,&c);
if(a<b+c&&b<a+c&&c<a+b&&a>0&&b>0&&c>0)
{
if(a==b&&b==c)
printf("等边三角形\n");
else if(b==c||a==b||a==c)
printf("等腰三角形\n");
else if(aa+bb==cc||aa+cc==bb||bb+cc==aa)
printf("直角三角形\n");
else
printf("一般三角形\n");
}
else
{
if(a<=0||b<=0||c<=0)
printf("输入数字不合法\n");
else if(a>=b+c||b>=a+c||c>=a+b)
printf("两边之合大于第三边\n");
}
}
第2题
#include <stdioh>
int main(void)
{
int x,y;
scanf("%d",x);
if(x<1)
y=x;
else if(x<10)
y=x;
else
y=x;
printf("%d",y);
}
一元二次方程
#include<stdioh>
#include<stdlibh>
eq(float a,float b,float c)
{
return (bb-4ac>=0) 1:0;
}
int main()
{
float a,b,c;
scanf("%f%f%f",&a,&b,&c);
if( eq(a,b,c)){
printf("1\n");
y=(bb-4ac);
}
else
printf("没根\n");
return 0;
}
给分吧 累死了
C语言实现以上分段函数,参考代码如下:
#include<stdioh>#include<mathh>
int main(void)
{
double x,y;
scanf("%lf",&x);
if(x<0)
y=fabs(x);
else if(x>=10)
y=8x-1;
else
y=5x-1;
printf("y=%lf",y);
return 0;
}
#include <stdioh>
void sort(int c[], int n)
{
int i, j, buf;
for(i = 0; i < n; i++){
for(j = i + 1; j < n; j++){
if(c[i] > c[j]){
buf = c[i];
c[i] = c[j];
c[j] = buf;
}
}
}
}
void display(int c[], int n)
{
int i;
printf("output: ");
for(i = 0; i < n; i++){
printf("%4d", c[i]);
}
printf("\n\n");
}
int search(int c[], int n, int b)
{
int i;
for(i = 0; i < n; i++){
if(c[i] == b)
return (i+1);
}
return 0;
}
int insert(int c[], int n, int b)
{
int i, j, buf;
if(b > c[n-1]){
c[n] = b;
return 0;
}
for(i = 0; i < n; i++){
if(b < c[i]){
buf = c[i];
c[i] = b;
break;
}
}
for(j = n; j > i+1; j-- ){
c[j]= c[j-1];
}
c[j] = buf;
return 0;
}
int main()
{
int i, b, s, c[100];
printf("input:\n");
for(i = 0; i < 10; i++){
scanf("%d", &c[i]);
}
sort(c, i);
display(c, i);
while(1){
scanf("%d", &b);
if(b < 0 || b > 100){
break;
}else if((s = search(c, i, b))){
printf("site:%d\n", s);
}else{
insert(c, i, b);
display(c, ++i);
}
}
return 0;
}
以上就是关于C语言习题 编写一程序 在屏幕上显示一菜单 并根据用户的选择执行相应的功能全部的内容,包括:C语言习题 编写一程序 在屏幕上显示一菜单 并根据用户的选择执行相应的功能、C语言编写程序、C语言:①题目:编写程序,定义一个含有15个元素的数组,并编写函数分别完成以下 *** 作:等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)