求解c语言关于勾股数的问题,过几天就要交了,请各位帮帮忙~~

)满足x2+y2=z2的正整数x,y,z称为一组勾股数,又称为毕达哥拉斯三元数组。用循环方法编程求出指定区间[a,b]范围内的所有勾股数组

第1个回答  2012-06-15
单链表问题。
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdio.h>

struct commodity
{
char code[11]; /* 商品编号 假定是10位编号*/
char name[20]; /* 商品名称 */
int total; /* 商品库存量 */
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();
}
}
第2个回答  推荐于2018-04-04
#include<stdio.h>

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 12 13
9 12 15
8 15 17
12 16 20
15 20 25
7 24 25
10 24 26
20 21 29
18 24 30
16 30 34
21 28 35
12 35 37
15 36 39
24 32 40
9 40 41
27 36 45
30 40 50
14 48 50
24 45 51
20 48 52
28 45 53
33 44 55
40 42 58
36 48 60
11 60 61
39 52 65
33 56 65
25 60 65
16 63 65
32 60 68
42 56 70
48 55 73
24 70 74
45 60 75
21 72 75
30 72 78
48 64 80
18 80 82
51 68 85
40 75 85
36 77 85
13 84 85
60 63 87
39 80 89
54 72 90
35 84 91
57 76 95
65 72 97
60 80 100
28 96 100
Press any key to continue追问

谢谢!!

追答

呵呵,能帮上忙就行

追问

非常感谢啊,请问能帮我解决这个问题吗。
商品库存管理
使用单链表建立一个简易商品库存表,要求:
(1)每个结点包含商品编号、名称、库存量等,建立n个结点(结点数据域的值由键盘输入)构成的单链表。
(2)统计商品的库存总量。
(3)在指定商品名称的结点之后插入一个新的结点,若表中无指定名称的结点,则将新结点插入到表头。

追答

要用到链表啊,我不擅长这个,有些不好意思,百度上有很多高手,你问他们吧,我现在还是大一学生,刚刚学了些C语言,还没有学数据结构,我现在编程序,都只是编一些简单的程序

追问

我也是~链表压根老师就没交,但是还逼着我们做课程设计,苦啊~还是很谢谢你啊。

追答

我的也是刚刚学老师就叫我们编什么通讯录系统,背单词系统,根本就不会,交作业的时候都是网上搜的答案

本回答被提问者和网友采纳