导航:首页 > 源码编译 > 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语言算法基础课本答案相关的资料

热点内容
喷油螺杆制冷压缩机 浏览:579
python员工信息登记表 浏览:377
高中美术pdf 浏览:161
java实现排列 浏览:513
javavector的用法 浏览:982
osi实现加密的三层 浏览:233
大众宝来原厂中控如何安装app 浏览:916
linux内核根文件系统 浏览:243
3d的命令面板不见了 浏览:526
武汉理工大学服务器ip地址 浏览:149
亚马逊云服务器登录 浏览:525
安卓手机如何进行文件处理 浏览:71
mysql执行系统命令 浏览:930
php支持curlhttps 浏览:143
新预算法责任 浏览:444
服务器如何处理5万人同时在线 浏览:251
哈夫曼编码数据压缩 浏览:426
锁定服务器是什么意思 浏览:384
场景检测算法 浏览:617
解压手机软件触屏 浏览:350