求解c语言关于勾股数的问题,过几天就要交了,请各位帮帮忙~~
答案:2 悬赏:60
解决时间 2021-03-26 13:21
- 提问者网友:杀手的诗
- 2021-03-25 13:23
求解c语言关于勾股数的问题,过几天就要交了,请各位帮帮忙~~
最佳答案
- 二级知识专家网友:長槍戰八方
- 2021-03-25 14:37
#include
void main()
{
int a,b,c;
int m,n;
printf("请输入你要的范围\n");
scanf("%d%d",&m,&n);
for(c = m; c <= n; c++)
for(b = m; b <= c; b++)
for(a = m; a <= b; a++)
{
if(a*a + b * b == c * c)
printf("%-4d%-4d%-4d\n",a, b, c);
}
}
运行结果
请输入你要的范围
1 100
3 4 5
6 8 10
5 1213
9 1215
8 1517
121620
152025
7 2425
102426
202129
182430
163034
212835
123537
153639
243240
9 4041
273645
304050
144850
244551
204852
284553
334455
404258
364860
116061
395265
335665
256065
166365
326068
425670
485573
247074
456075
217275
307278
486480
188082
516885
407585
367785
138485
606387
398089
547290
358491
577695
657297
6080100
2896100
Press any key to continue追答
追问:谢谢!!
追答:呵呵,能帮上忙就行
追问:非常感谢啊,请问能帮我解决这个问题吗。
商品库存管理
使用单链表建立一个简易商品库存表,要求:
(1)每个结点包含商品编号、名称、库存量等,建立n个结点(结点数据域的值由键盘输入)构成的单链表。
(2)统计商品的库存总量。
(3)在指定商品名称的结点之后插入一个新的结点,若表中无指定名称的结点,则将新结点插入到表头。
追答:要用到链表啊,我不擅长这个,有些不好意思,百度上有很多高手,你问他们吧,我现在还是大一学生,刚刚学了些C语言,还没有学数据结构,我现在编程序,都只是编一些简单的程序
追问:我也是~链表压根老师就没交,但是还逼着我们做课程设计,苦啊~还是很谢谢你啊。
追答:我的也是刚刚学老师就叫我们编什么通讯录系统,背单词系统,根本就不会,交作业的时候都是网上搜的答案
void main()
{
int a,b,c;
int m,n;
printf("请输入你要的范围\n");
scanf("%d%d",&m,&n);
for(c = m; c <= n; c++)
for(b = m; b <= c; b++)
for(a = m; a <= b; a++)
{
if(a*a + b * b == c * c)
printf("%-4d%-4d%-4d\n",a, b, c);
}
}
运行结果
请输入你要的范围
1 100
3 4 5
6 8 10
5 1213
9 1215
8 1517
121620
152025
7 2425
102426
202129
182430
163034
212835
123537
153639
243240
9 4041
273645
304050
144850
244551
204852
284553
334455
404258
364860
116061
395265
335665
256065
166365
326068
425670
485573
247074
456075
217275
307278
486480
188082
516885
407585
367785
138485
606387
398089
547290
358491
577695
657297
6080100
2896100
Press any key to continue追答
追问:谢谢!!
追答:呵呵,能帮上忙就行
追问:非常感谢啊,请问能帮我解决这个问题吗。
商品库存管理
使用单链表建立一个简易商品库存表,要求:
(1)每个结点包含商品编号、名称、库存量等,建立n个结点(结点数据域的值由键盘输入)构成的单链表。
(2)统计商品的库存总量。
(3)在指定商品名称的结点之后插入一个新的结点,若表中无指定名称的结点,则将新结点插入到表头。
追答:要用到链表啊,我不擅长这个,有些不好意思,百度上有很多高手,你问他们吧,我现在还是大一学生,刚刚学了些C语言,还没有学数据结构,我现在编程序,都只是编一些简单的程序
追问:我也是~链表压根老师就没交,但是还逼着我们做课程设计,苦啊~还是很谢谢你啊。
追答:我的也是刚刚学老师就叫我们编什么通讯录系统,背单词系统,根本就不会,交作业的时候都是网上搜的答案
全部回答
- 1楼网友:青灯有味
- 2021-03-25 16:01
单链表问题。
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdio.h>
struct commodity
{
char code[11];
charname[20];
inttotal;
struct commodity*next;
};
int total(struct commodity *head)
{
int s=0;
while(head!=NULL)
{
s+=head->total;
head=head->next;
}
return s;
}
struct commodity *insert(struct commodity *head)
{
struct commodity *p,*q;
char sname[20];
int mark=0;
printf("input search commodity name:");
scanf("%s",sname);
p=head;
while(p!=NULL)
{
if(strcmp(sname,p->name)==0)
{
q=p;
mark=1;
break;
}
p=p->next;
}
p=( struct commodity *) malloc(sizeof( struct commodity));
if(mark==0)
{
printf("no search commodity name.\n");
q=head;
head=p;
p->next=q;
}
else
{
p->next=q->next;
q->next=p;
}
printf("\nnew commodity name:");
scanf("%s",p->name);
printf("\nnew commodity code:");
scanf("%s",p->code);
printf("\nnew commodity total:");
scanf("%d",&p->total);
return head;
}
main()
{
char c;
struct commodity *head=NULL;
while(1)
{
system("cls");
printf("\t\t 1 : 统计库存总量\n");
printf("\t\t 2 : 在指定商品名后添加新的商品信息\n");
printf("\t\t 3 : 退出\n");
scanf("%c",&c);
if(c=='3')
{
exit(0);
}
switch(c)
{
case '1':
printf("\ncommodity totality=%d\n",total(head));
break;
case '2':
head=insert(head);
break;
default:
printf("\n\n输入的命令不对,请重新输入!!\n");
break;
}
getchar();
printf("\n\n请按任意键继续!\n");
getch();
}
}
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdio.h>
struct commodity
{
char code[11];
charname[20];
inttotal;
struct commodity*next;
};
int total(struct commodity *head)
{
int s=0;
while(head!=NULL)
{
s+=head->total;
head=head->next;
}
return s;
}
struct commodity *insert(struct commodity *head)
{
struct commodity *p,*q;
char sname[20];
int mark=0;
printf("input search commodity name:");
scanf("%s",sname);
p=head;
while(p!=NULL)
{
if(strcmp(sname,p->name)==0)
{
q=p;
mark=1;
break;
}
p=p->next;
}
p=( struct commodity *) malloc(sizeof( struct commodity));
if(mark==0)
{
printf("no search commodity name.\n");
q=head;
head=p;
p->next=q;
}
else
{
p->next=q->next;
q->next=p;
}
printf("\nnew commodity name:");
scanf("%s",p->name);
printf("\nnew commodity code:");
scanf("%s",p->code);
printf("\nnew commodity total:");
scanf("%d",&p->total);
return head;
}
main()
{
char c;
struct commodity *head=NULL;
while(1)
{
system("cls");
printf("\t\t 1 : 统计库存总量\n");
printf("\t\t 2 : 在指定商品名后添加新的商品信息\n");
printf("\t\t 3 : 退出\n");
scanf("%c",&c);
if(c=='3')
{
exit(0);
}
switch(c)
{
case '1':
printf("\ncommodity totality=%d\n",total(head));
break;
case '2':
head=insert(head);
break;
default:
printf("\n\n输入的命令不对,请重新输入!!\n");
break;
}
getchar();
printf("\n\n请按任意键继续!\n");
getch();
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯