華南師范大學c語言考研真題
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年計算機(電子書)(獨家提供)
鏈接:

若資源有問題歡迎追問~
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校:華東師范華師范南京師范吉林北京郵電北京交通等希望答能幫助
