当前位置:首页 » 大学本科 » 华南师范大学c语言考研真题

华南师范大学c语言考研真题

发布时间: 2021-11-18 03:30:42

A. c语言。考研题。不会做。谢谢大家的帮忙了。

// 链表式的多项式相加
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// 多项式中的一项
typedef struct Node
{
/////////数据部分
float _ratio; // 系数
unsigned _index; // 指数

/////////链表结构部分
struct Node * _next;
} Node;

// 插入到多项式中, 并保持按指数降序排列.
Node * SortInsert ( Node * poly, Node *new_node )
{
if ( new_node != NULL )
{
if ( poly != NULL )
{
// 因为第一项没有prev,所以需要特殊处理
// 指数大于第一项,放在最前面
if ( new_node->_index > poly->_index )
{
new_node->_next = poly;
return new_node;
}
else if ( new_node->_index == poly->_index ) // 指数与第一项相同
{
Node * cur = poly;
cur->_ratio += new_node->_ratio;
free ( new_node );
// 如果系数变为0, 把老节点也删除
if ( abs ( cur->_ratio ) < 0.0000001f ) // 浮点数不应该直接比较, 只能算误差
{
poly = poly->_next;
free ( cur );
}
return poly;
}
else
{
// 找一个指数相同,或前面比自身大&&后面比自身小的位置, 例如: 2 要找到一个 2, 或者3->1
Node * prev = poly; // 记录匹配的前一个节点,用于在cur前面插入节点
Node * cur = prev->_next; // 节点是否匹配的测试节点
for ( ; cur != NULL; prev = cur, cur = cur->_next ) // 维护好prev, cur在遍历过程中的关系
{
if ( cur->_index == new_node->_index ) // 找到前面例子中的2了, 加起来就好了
{
cur->_ratio += new_node->_ratio;
free ( new_node );
// 如果系数变为0, 把老节点也删除
if ( abs ( cur->_ratio ) < 0.0000001f ) // 浮点数不应该直接比较, 只能算误差
{
prev->_next = cur->_next;
free ( cur );
}
return poly; // 找到就不找了, 所以是第一次
}
if ( cur->_index < new_node->_index ) // 找到前面例子中的3->1中的1了
{
new_node->_next = cur; // 类似于: 2->1; ...->3->1
prev->_next = new_node; // 类似于: ...->3->2(->1)
return poly;
}
}
// 到了这里说明任意节点指数都比新指数大, 同时prev也指向了最后一个元素. 所以直接插入到最后
new_node->_next = NULL; // 类似于: 2-> NULL
prev->_next = new_node; // 类似于: ...->3->2->NULL
return poly;
}
}
return new_node; // 多项式无效,返回只有一个节点的多项式
}
return poly; // 新节点无效,不插入

Node * prev = new_node;
Node * cur = poly;
if ( new_node == NULL )
return poly;
new_node->_next = poly;

}

// 释放多项式
void free_poly ( Node * poly )
{
while ( poly != NULL )
{
Node * tmp = poly;
poly = poly->_next;

free ( tmp );
}
}

// 输入多项式
Node * input_poly() // 这里简单的处理输入, 不考虑输入过程可能产生的异常(比如输入了字母)
{
unsigned i = 0, n = 0;
Node * poly = NULL;
printf ( "请先输入多项式项数: " );
scanf ( "%u", &n );

for ( i = 1; i <= n; ++i )
{
Node * item = ( Node * ) malloc ( sizeof ( Node ) );
if ( NULL == item )
{
free_poly ( poly );
printf ( "内存不足\n" );
return NULL;
}
printf ( "请输入第%d项的系数和指数(例如: 1.2,2)", i );
scanf ( "%f,%d", &item->_ratio, &item->_index );

poly = SortInsert ( poly, item );
}
return poly;
}

// 输出项
void display_node ( Node * item )
{
printf ( "%fX^%u", item->_ratio, item->_index );
}

// 输出多项式
void display ( Node * poly )
{
Node * tmp = NULL;
if ( poly == NULL )
return ;
display_node ( poly );
for ( tmp = poly->_next; tmp != NULL; tmp = tmp->_next )
{
printf ( " + " );
display_node ( tmp );
}
printf ( "\n" );
}

int main()
{
Node * A = NULL;
Node * B = NULL;

// 输入A
A = input_poly();
printf("您输入的多项式A为:");
display(A);
// 输入B
B = input_poly();
printf("您输入的多项式B为:");
display(B);
// 相加
{
// 注意到SortInsert中,在指数相等时会合并项,
// 所以只需要把其中一个多项式中的所有项SortInsert到另外一个多项式中就完成了
// 该方法破坏了A和B!!!, 但是题目没有禁止
Node * tmp = NULL;
while ( B != NULL ) // 只要多项式B还有项
{
// 从头分离项
tmp = B;
B = B->_next;

// 插入到另外一个多项式中
SortInsert ( A, tmp );
}
}
// 输出
display ( A );

free_poly( A );

return 0;
}

/* 测试io:
请先输入多项式项数: 4
请输入第1项的系数和指数(例如: 1.2,2)400,4
请输入第2项的系数和指数(例如: 1.2,2)100,1
请输入第3项的系数和指数(例如: 1.2,2)200,2
请输入第4项的系数和指数(例如: 1.2,2)300,3
您输入的多项式A为:400.000000X^4 + 300.000000X^3 + 200.000000X^2 + 100.000000X^1
请先输入多项式项数: 2
请输入第1项的系数和指数(例如: 1.2,2)20,2
请输入第2项的系数和指数(例如: 1.2,2)30,3
您输入的多项式B为:30.000000X^3 + 20.000000X^2
400.000000X^4 + 330.000000X^3 + 220.000000X^2 + 100.000000X^1

*/

// 写了一个多小时,累死了。 希望能帮到了。。

B. 有几道考研C语言真题,能帮我看一下么

1.那些数可能无法得到S,也就是无解.如数组{6,7},数是9,那么无论怎么样都不会得到,而且初步看是个NP问题个人看法。
2.程序有错误,结果有问题!
3.除了static的和new出来的变量意外不需要考虑(new出来的东西可能出问题,static的一定出问题)
4.不知道算法是啥,,,,
5.没看明白要干啥
6.我觉得是4个.(f2,f3)算一个参数...而且传进去的是最后一个参数,也就是f3有效果(逗号表达式,最右边的有效)....崩溃了,平时还没见过这么写的....考试可真牛B

C. C语言程序设计考研真题(B卷答案)

2021年计算机(电子书)(独家提供)

链接:

提取码:so6s复制这段内容后打开网络网盘手机APP,操作更方便哦!

若资源有问题欢迎追问~

D. C语言的考研题,过程思路求大神说下。。真的搞不懂

4的答案是A, 5的答案A。总共有5个人,数组从零开始的,刚开始p指向第一结构体,即第一个人,执行q=p+5赋值后,此时q指向第六个人,for循环先输出第一个人的信息,然后p++,指向下一个人,执行5次。

E. C语言程序设计,考研真题,求高手看看怎么编程

(1)还是挺规范的!
(2)诸如if,switch,for,while,do while 等等。。他们是选择结构和循环结构,如“for(表达式)“中的表达式是循环条件,然后是循环的主体,循环体是由语句构成,可以是单个语句,也可以是多条语句组成的复合语句!

F. 关于考研C语言的几道题目,请大神赐教。另外不要嘲笑我问这种简单的问题

第一道题

#include<stdio.h>
struct student{char name[20];
float score1,score2;
float avg;
};
struct student stu[100];
int main()
{
int n;
int i;
float all_avg=0;
scanf("%d",&n); //全班学生数量
for(i=1;i<=n;i++)
{
scanf("%s %f %f",stu[i].name,&stu[i].score1,&stu[i].score2);
stu[i].avg=(stu[i].score1+stu[i].score2)/2;
all_avg+=stu[i].avg;

}
all_avg/=n;
for(i=1;i<=n;i++)
{
if(stu[i].avg<all_avg)
{
printf("name:%s score1:%.1f score2:%.1f avg:%.1f\n",stu[i].name,stu[i].score1,stu[i].score2,stu[i].avg);
}
}

return 0;
}

第二道题

#include<stdio.h>
struct student{char name[20];
float score1,score2,score3;
float avg;
};
struct student stu[11];
int main()
{
int i,j;
struct student temp;

for(i=1;i<=10;i++)
{
scanf("%s %f %f %f",stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
stu[i].avg=(stu[i].score1+stu[i].score2+stu[i].score3)/3;

}

for(i=1;i<10;i++)
for(j=1;j<10;j++)
{
if(stu[j].avg<=stu[j+1].avg)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
for(i=1;i<=5;i++)
{
printf("name:%s score1:%.1f score2:%.1f score3:%.1f avg:%.1f\n",stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].avg);

}

return 0;
}

第三题

#include<stdio.h>
#include<string.h>
struct item{char pno[20];
char pname[20];
float amount;
};
struct item item[100];
int main()
{
int i,j;
struct item temp;
int n;
scanf("%d",&n);

for(i=1;i<=n;i++)
{
scanf("%s %s %f",item[i].pno,item[i].pname,&item[i].amount);

}

for(i=1;i<n;i++)
for(j=1;j<n;j++)
{
if(strcmp(item[j].pname,item[j+1].pname)>0)
{
temp=item[j];
item[j]=item[j+1];
item[j+1]=temp;

}
else if(strcmp(item[j].pname,item[j+1].pname)==0 && item[j].amount>item[j+1].amount)
{
temp=item[j];
item[j]=item[j+1];
item[j+1]=temp;

}
}
for(i=1;i<=n;i++)
{
printf("%s %s %.1f\n",item[i].pno,item[i].pname,&item[i].amount);
}

return 0;
}

G. 考研初试专业课考c语言程序设计的大学

本教育技术专业所解本专业考研专业课包含C校:华东师范华师范南京师范吉林北京邮电北京交通等希望答能帮助

热点内容
四川农业大学申请考核博士 发布:2025-10-20 08:58:11 浏览:981
福田雷沃重工本科生待遇怎么样 发布:2025-10-20 08:53:49 浏览:575
华为要本科生吗 发布:2025-10-20 08:25:41 浏览:550
2008年青岛本科生工资 发布:2025-10-20 08:04:24 浏览:444
东北大学艺术考研 发布:2025-10-20 07:38:35 浏览:299
我的大学生活txt 发布:2025-10-20 07:35:28 浏览:25
人民大学外语系考研 发布:2025-10-20 07:31:12 浏览:894
上海交通大学考研辅导班 发布:2025-10-20 07:24:54 浏览:420
华中农业大学细胞生物学考研群 发布:2025-10-20 07:09:36 浏览:558
南京大学2016考研线 发布:2025-10-20 06:43:12 浏览:930