導航:首頁 > 源碼編譯 > c語言演算法基礎課本答案

c語言演算法基礎課本答案

發布時間:2022-07-11 09:33:50

⑴ c語言程序設計基礎第二版答案 人民郵電出版社

語言視頻教程 譚浩強編,曾怡教授講解
C語言程序設計視頻教程(曾怡)
地區:大陸
語言:普通話
簡介:
C程序設計視頻教程(曾怡):本套視頻教程由曾怡副教授講解,使用教材為:《C程序設計》 譚浩強 清華大學出版社出版。是難得的C語言學習視頻教程。全程共30講,每講45分鍾左右,CSF視頻格式。講課內容如下:

第一講 第一章 C語言概述
第二講 第二章 程序的靈魂—演算法
第三講 第三章 數據類型、運算符與表達式
第四講 第三章 數據類型、運算符與表達式
第五講 第三章 數據類型、運算符與表達式
第六講 第三章 數據類型、運算符與表達式
第四章 最簡單的C程序設計—順序程序設計
第七講 第四章 最簡單的C程序設計—順序程序設計
第八講 第四章 最簡單的C程序設計—順序程序設計
第九講 第五章 選擇結構的程序設計
第十講 第五章 選擇結構的程序設計
第十一講 第五章 選擇結構的程序設計
第十二講 第六章 循環結構程序設計
第十三講 第六章 循環結構程序設計
第十四講 第六章 循環結構程序設計
第十五講 第六章 循環結構程序設計
第七章 數組
第十六講 第七章 數組
第十七講 第七章 數組
第十八講 第七章 數組
第十九講 第七章 數組
第二十講 第七章 數組
第八章 函數
第二十一講 第八章 函數
第二十二講 第八章 函數
第二十三講 第八章 函數
第二十四講 第十章 指針
第二十五講 第十章 指針
第二十六講 第十章 指針
第二十七講 第十章 指針
第十一章 結構體
第二十八講 第十一章 結構體
復習總結第一講
復習總結第二講

⑵ c語言程序設計基礎習題答案

1、
10,12,ai=2E
2、
#include
main(){
int
n,sum=0;
scanf
("%d",&n);
while(n!=0){
sum=sum+n%10;
n=n/10;
}
printf("sum=%d",sum);}
3、
#include
int
main(){
int
up
=
0,low
=
0;
char
array[100]
=
{0};
gets(array);
for(int
i
=
0;i='a'&&array[i]='A'&&array[i]<='Z'){
low++;
}
}
printf("大寫字母個數:%d,小寫字母個數:%d",up,low);
return
0;}
4、
#include
int
main(){
float
score[10]={0};
float
sum
=
0;
int
pass
=
0;
float
ave
=
0;
for(int
i
=
0;i=60){
pass++;
}
}
ave=sum/10.0;
printf("平均分%g\n",sum/10.0);
printf("及格人數%d\n",pass);
printf("高於平均分的分數:\n");
for(int
i
=0;i=ave){
printf("%g\n",score[i]);
}
}
return
0;}

⑶ 給出一些基本的演算法問題並給出答案

C語言演算法基礎
演算法(Algorithm):計算機解題的基本思想方法和步驟。演算法的描述:是對要解決一個問題或要完成一項任務所採取的方法和步驟的描述,包括需要什麼數據(輸入什麼數據、輸出什麼結果)、採用什麼結構、使用什麼語句以及如何安排這些語句等。通常使用自然語言、結構化流程圖、偽代碼等來描述演算法。
一、計數、求和、求階乘等簡單演算法
此類問題都要使用循環,要注意根據問題確定循環變數的初值、終值或結束條件,更要注意用來表示計數、和、階乘的變數的初值。
例:用隨機函數產生100個[0,99]范圍內的隨機整數,統計個位上的數字分別為1,2,3,4,5,6,7,8,9,0的數的個數並列印出來。
本題使用數組來處理,用數組a[100]存放產生的確100個隨機整數,數組x[10]來存放個位上的數字分別為1,2,3,4,5,6,7,8,9,0的數的個數。即個位是1的個數存放在x[1]中,個位是2的個數存放在x[2]中,……個位是0的個數存放在x[10]。
void main()
{ int a[101],x[11],i,p;
for(i=0;i<=11;i++)
x[i]=0;
for(i=1;i<=100;i++)
{ a[i]=rand() % 100;
printf("%4d",a[i]);
if(i%10==0)printf("\n");
}
for(i=1;i<=100;i++)
{ p=a[i]%10;
if(p==0) p=10;
x[p]=x[p]+1;
}
for(i=1;i<=10;i++)
{ p=i;
if(i==10) p=0;
printf("%d,%d\n",p,x[i]);
}
printf("\n");
}
二、求兩個整數的最大公約數、最小公倍數
分析:求最大公約數的演算法思想:(最小公倍數=兩個整數之積/最大公約數)
(1) 對於已知兩數m,n,使得m>n;
(2) m除以n得余數r;
(3) 若r=0,則n為求得的最大公約數,演算法結束;否則執行(4);
(4) m←n,n←r,再重復執行(2)。
例如: 求 m=14 ,n=6 的最大公約數. m n r
14 6 2
6 2 0
void main()
{ int nm,r,n,m,t;
printf("please input two numbers:\n");
scanf("%d,%d",&m,&n);
nm=n*m;
if (m<n)
{ t=n; n=m; m=t; }
r=m%n;
while (r!=0)
{ m=n; n=r; r=m%n; }
printf("最大公約數:%d\n",n);
printf("最小公倍數:%d\n",nm/n);
}
三、判斷素數
只能被1或本身整除的數稱為素數 基本思想:把m作為被除數,將2—INT( )作為除數,如果都除不盡,m就是素數,否則就不是。(可用以下程序段實現)
void main()
{ int m,i,k;
printf("please input a number:\n");
scanf("%d",&m);
k=sqrt(m);
for(i=2;i<k;i++)
if(m%i==0) break;
if(i>=k)
printf("該數是素數");
else
printf("該數不是素數");
}
將其寫成一函數,若為素數返回1,不是則返回0
int prime( m%)
{int i,k;
k=sqrt(m);
for(i=2;i<k;i++)
if(m%i==0) return 0;
return 1;
}

⑷ 求C語言程序設計課本答案

C語言程序設計
中國農業大學出版社
請問LZ是要這個嗎?

⑸ 求演算法:c語言實現 習題答案

http://cs.ccnu.e.cn/datastruct/dsh.htm

http://jpkc.nwu.e.cn/datastr/

http://www.ahut.e.cn/jpkc/sjjg/kejian.htm

http://gdcp.cn/jpkc/sjjg/

⑹ 哪裡有演算法:C語言實現 (第1-4部分)基礎知識、數據結構、排序及搜索(原書第3版)的練習答案

有難題就發上來,要答案幹嘛?

⑺ 程序設計基礎 C語言習題答案

1、

10,12,a
i=2
E

2、

#include<stdio.h>
main()
{
intn,sum=0;
scanf("%d",&n);
while(n!=0){
sum=sum+n%10;
n=n/10;
}
printf("sum=%d",sum);
}

3、

#include<stdio.h>
intmain()
{
intup=0,low=0;
chararray[100]={0};
gets(array);
for(inti=0;i<100;i++){
if(array[i]>='a'&&array[i]<='z'){
up++;
}elseif(array[i]>='A'&&array[i]<='Z'){
low++;
}
}
printf("大寫字母個數:%d,小寫字母個數:%d",up,low);
return0;
}

4、

#include<stdio.h>
intmain()
{
floatscore[10]={0};
floatsum=0;
intpass=0;
floatave=0;
for(inti=0;i<10;i++){
scanf("%g",&score[i]);
sum+=score[i];
if(score[i]>=60){
pass++;
}
}
ave=sum/10.0;
printf("平均分%g ",sum/10.0);
printf("及格人數%d ",pass);
printf("高於平均分的分數: ");
for(inti=0;i<10;i++){
if(score[i]>=ave){
printf("%g ",score[i]);
}
}
return0;
}

⑻ 看不懂這道C語言演算法題答案

答案選CS初始值賦值為0,用於累加求和進入判斷X>0是否成立,T=X對10取余,首先得到1,即T=1;S=S+T,T的值賦給SX=INT(X/10)即X除以10取整賦給X,第一個即54321/10=5432,此時X=5432再次進入循環判斷,S儲存累加和,直到X<=0時,退出循環最終S放的值即為數字每位數字之和

⑼ 數據結構與演算法基礎課後作業1~6答案,數據結構c語言版(上海大學),求

你把題目貼出來, 一下子就有人幫你解決了

⑽ 急求c語言編程答案

// test.cpp : 定義控制台應用程序的入口點。
//

// test1.cpp : Defines the entry point for the console application.
//
// test.cpp : Defines the entry point for the console application.

# include "stdafx.h"
# include "stdio.h"
# include "stdlib.h"
# include <iostream>
# include <fstream>
# include <iomanip> /*需引用的頭文件*/
using namespace std;

struct node /*定義結點結構體保存結點信息*/
{
struct student /*定義結構體變數student保存學生的信息*/
{
char studentnumber[10]; /*學生學號*/
char studentname[5]; /*學生姓名*/
struct course /*定義結構體變數Course保存課程信息*/
{
float course1; //*********************************
float course2;
float course3; //各門課程的分數和平均分
float averagemark; //*****************************
};struct course allcourse;
};struct student stu;
struct node *next;
};

node *top;

struct node *createlist(char info[2][9],float marksinfo[]) //**************************
{

static struct node *new_node,*current_node;

new_node=(struct node *)new(node); /*建立新的結點*/
strcpy(new_node->stu.studentnumber,info[0]);
strcpy(new_node->stu.studentname,info[1]);
new_node->stu.allcourse.course1=marksinfo[0];
new_node->stu.allcourse.course2=marksinfo[1];
new_node->stu.allcourse.course3=marksinfo[2]; //對結點的元素付值
new_node->stu.allcourse.averagemark=(marksinfo[0]+
marksinfo[1]+marksinfo[2])/3;
new_node->next=NULL;
if (top==NULL)
{
top=new_node;
current_node=top;
}

current_node->next=new_node; /*指向新的結點*/
current_node=new_node; /*總指向新的結點*/
return top; //*****************************
}
void studentaverage(node *top) /*顯示平均分函數*/
{
int i=0,maxcount=0; /*結點的數目maxcount*/
char response='y';
struct node *t=top;

fstream readcount("countsave.txt",ios::in); /*定義文件流*/
readcount>>maxcount; /*將文件信息讀入變數Maxcount*/
system("cls"); /*清屏*/

cout.flags(ios::left); /*輸出格式為左對齊*/
cout<<setw(14)<<"學號"<<setw(14)<<"姓名"<<setw(14)<<"課程1"<<setw(14)
<<"課程2"<<setw(14)<<"課程3"<<"平均分"<<endl;

for (i=0;i<maxcount;i++)
{
t=top;
top=top->next;

cout.flags(ios::left);

cout<<setw(14)<<t->stu.studentnumber<<setw(14)<<
t->stu.studentname<<setw(14)<<t->stu.allcourse.course1<<setw(14)<<t->stu.allcourse.course2
<<setw(14)<<t->stu.allcourse.course3<<setw(14)<<t->stu.allcourse.averagemark<<endl;
}

system("pause");
}

void courseaverage(node *top)/*顯示每門課程的平均分*/
{
int maxcount;
node *t=top;
float courseaverage_1=0.00;//********************************
float courseaverage_2=0.00;// 保存各門平均分的變數
float courseaverage_3=0.00;//********************************

fstream readcount("countsave.txt",ios::in);
readcount>>maxcount;
system("cls");

for (int i=0;i<maxcount;i++) //********************************************************************
{
t=top;
top=top->next; //遍歷結點累加各門課程分數求平均值
float(courseaverage_1)+=float(t->stu.allcourse.course1);
courseaverage_2+=t->stu.allcourse.course2;
courseaverage_3+=t->stu.allcourse.course3;
} //********************************************************************

cout.flags(ios::left);
cout<<setw(25)<<"課程1"<<setw(25)<<"課程2"<<setw(25)<<"課程3"<<endl;

cout<<setw(25)<<float(courseaverage_1/(maxcount+1))<<setw(25)<<
courseaverage_2/float(maxcount+1)<<setw(25)<<courseaverage_3/float(maxcount+1)<<endl;

system("pause");
}
void orderWithAverageMark(node *top)/*按平均分排序*/
{

struct node *t=top;
static struct node *t0=top; /*保存結點的頭*/
float averagemark_1=0.00;
float averagemark_2=0.00;
static char temp[10]; /*保存字元串的中間變數*/
float temp0; /*整型變數的中間變數*/
int maxcount;
int i;
bool flag; /*判斷冒泡演算法是否結束*/

fstream readcount("countsave.txt",ios::in||ios::out);
readcount>>maxcount;
//*****************************************************************************
//冒泡排序
//if (count
for(int j=0;j<maxcount;j++)
{

top=t0; //結點指針指向表頭,執行下一次排序

for (i=0;i<(maxcount-1);i++)
{
flag=false;
t=top;
averagemark_1=t->stu.allcourse.averagemark;
averagemark_2=top->next->stu.allcourse.averagemark;

if (averagemark_1<=averagemark_2)
{ //****************************************************************
strcpy(temp,t->stu.studentnumber);
strcpy(t->stu.studentnumber,top->next->stu.studentnumber);
strcpy(top->next->stu.studentnumber,temp);

strcpy(temp,t->stu.studentname);
strcpy(t->stu.studentname,top->next->stu.studentname);
strcpy(top->next->stu.studentname,temp);

temp0=t->stu.allcourse.course1;
t->stu.allcourse.course1=top->next->stu.allcourse.course1; //交換兩結點的各數值
top->next->stu.allcourse.course1=temp0;

temp0=t->stu.allcourse.course2;
t->stu.allcourse.course2=top->next->stu.allcourse.course2;
top->next->stu.allcourse.course2=temp0;

temp0=t->stu.allcourse.course3;
t->stu.allcourse.course3=top->next->stu.allcourse.course3;
top->next->stu.allcourse.course3=temp0;

temp0=t->stu.allcourse.averagemark;
t->stu.allcourse.averagemark=top->next->stu.allcourse.averagemark;
top->next->stu.allcourse.averagemark=temp0; //*************************************************************
flag=true;
}

top=top->next;
}
}
//********************************************************************************************
}

int menu()//主菜單
{
int choice;
cout<<"*******************************************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* 1. 輸入學生信息 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 2. 顯示學生平均分 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 3. 顯示每門課的平均分 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 4. 顯示總分在某平均分以上的學生 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 5. 保存數據 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 0. 退出 *"<<endl;
cout<<"* *"<<endl;
cout<<"*******************************************************************************"<<endl;
cout<<" "<<endl;
cout<<" 請選擇:";

loop:cin>>choice;

if (choice>=0&&choice<=5)
return choice;
else
goto loop;

}
int findstdentnumber(node *top,char namestr[5])
{
node *t=top;
int count;

fstream readcount("countsave.txt",ios::in);
readcount>>count;

for (int i=0;i<count;i++)
{
t=top;
top=top->next;
if (strcmp(namestr,t->stu.studentnumber)==0)
{
return 1;
}
}
return 0;
}

node *getinfo()
{
char response='y';
char studentinfo[2][9]; //二維數組保存學號和姓名
float studentcoursemark[3]; //保存各科成績
int count=0;
static int count0;

void savestudentinfo(node *);
node *readstudentinfo();
void freelist(node *);

fstream readcount("countsave.txt",ios::in);/*讀出結點值*/
readcount>>count0;
readcount.close();

do
{
loop0: system("cls");
cout<<endl;
cout<<"請輸入學號:";
cin>>studentinfo[0];
cout<<endl;
if(findstdentnumber(top,studentinfo[0]))
{
cout<<"該學號已存在:"<<endl;
system("pause");
strcpy(studentinfo[0]," ");
goto loop0;
}
cout<<"姓名:";
cin>>studentinfo[1];
cout<<endl;
cout<<"課程1:";
cin>>studentcoursemark[0];
cout<<endl;
cout<<"課程2:";
cin>>studentcoursemark[1];
cout<<endl;
cout<<"課程3:";
cin>>studentcoursemark[2];
top=createlist(studentinfo,studentcoursemark);
count++;
cout<<endl;
cout<<"要繼續嗎?(y or n)";
cin>>response;
}while(count>=0&&count<30&&(response=='y'||response=='Y'));

orderWithAverageMark(top); /*對鏈表按學生平均分進行排序*/

fstream savecount("countsave.txt",ios::out);
savecount<<(count+count0);/*保存結點值並累加*/
savecount.close();

savestudentinfo(top); /*保存學生信息到文件*/

return top;
}
void savestudentinfo(node *top) /*保存學生信息*/
{
int i,numberofstudent;
node *head=top;

fstream count("countsave.txt",ios::in);
count>>numberofstudent; /*獲得學生個數*/
count.close();

orderWithAverageMark(head);

fstream student("studentinfosave.txt",ios::out);

system("cls");

//遍歷鏈表,保存信息
for (i=0;i<numberofstudent;i++)
{

head=top;
top=top->next;
student<<head->stu.studentnumber<<" "<<head->stu.studentname<<" "<<
head->stu.allcourse.course1<<" "<<head->stu.allcourse.course2<<" "<<
head->stu.allcourse.course3<<endl;

}
student.close();
//*********************
cout<<" 保存成功!"<<endl;
system("pause");
}
node *readstudentinfo() /*從文件讀取學生信息*/
{
int numberofstudent;
char studentinfo[2][9];
float studentcoursemark[3];

fstream readcount("countsave.txt",ios::in);
fstream readstuinfo("studentinfosave.txt",ios::in);
readcount>>numberofstudent;

for (int i=0;i<numberofstudent;i++)
{

readstuinfo>>studentinfo[0]>>studentinfo[1]>>studentcoursemark[0]>>
studentcoursemark[1]>>studentcoursemark[2];

top=createlist(studentinfo,studentcoursemark);
}

readcount.close();
readstuinfo.close();
return top;
}

void find(node *top)/*查找函數*/
{
int lowmark=0,i=0,count=0;
struct node *t=top;

system("cls");

cout<<"請輸入一個平均分的下限:";
cin>>lowmark;

system("cls");

fstream readcount("countsave.txt",ios::in);
readcount>>count;

cout.flags(ios::left);
cout<<setw(14)<<"學號"<<setw(14)<<"姓名"<<setw(14)<<"課程1"<<setw(14)
<<"課程2"<<setw(14)<<"課程3"<<setw(14)<<"平均分"<<endl;

if(lowmark>=0&&lowmark<=100)
{
for(int j=0;j<count;j++)
{
t=top;
top=top->next;
if(lowmark<=(t->stu.allcourse.averagemark))//****************************顯示滿足條件的信息
{
cout<<setw(14)<<t->stu.studentnumber<<setw(14)<<t->stu.studentname<<setw(14)<<t->stu.allcourse.course1<<setw(14)
<<t->stu.allcourse.course2<<setw(14)<<t->stu.allcourse.course3<<setw(14)<<t->stu.allcourse.averagemark<<endl;
i++;
}
} //****************************
if (i==0)
{
cout<<endl;
system("cls");
cout<<"找不學生信息!"<<endl;
}
cout<<"共找到"<<i<<"條信息!"<<endl;

system("pause");
}
}

void main()
{

top=readstudentinfo(); /*讀取學生信息*/

for(;;)
{
system("cls");

switch(menu())
{

case 1:
top=getinfo();
break;

case 2:
studentaverage(top);
break;

case 3:
courseaverage(top);
break;
case 4:
find(top);
break;
case 5:
savestudentinfo(top);
break;
case 0:
exit(0);
break;

}
}

}

閱讀全文

與c語言演算法基礎課本答案相關的資料

熱點內容
優信二手車解壓後過戶 瀏覽:60
Windows常用c編譯器 瀏覽:777
關於改善國家網路安全的行政命令 瀏覽:832
安卓如何下載網易荒野pc服 瀏覽:653
javainetaddress 瀏覽:103
蘋果4s固件下載完了怎麼解壓 瀏覽:999
命令zpa 瀏覽:284
python編譯器小程序 瀏覽:943
在app上看視頻怎麼光線調暗 瀏覽:539
可以中文解壓的解壓軟體 瀏覽:591
安卓卸載組件應用怎麼安裝 瀏覽:911
使用面向對象編程的方式 瀏覽:338
程序員項目經理的年終總結範文 瀏覽:928
內衣的加密設計用來幹嘛的 瀏覽:431
淮安數據加密 瀏覽:291
魔高一丈指標源碼 瀏覽:981
松下php研究所 瀏覽:167
c回調java 瀏覽:398
夢幻端游長安地圖互通源碼 瀏覽:744
電腦本地文件如何上傳伺服器 瀏覽:311