A. 《c语言程序设计》课程设计
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define BUFFERSIZE 1024
#define MAXACCOUNT 1000
typedef struct BankAccount
{
int account;
int key;
char name[32];
float balance;
}BANKACCOUNT;
BANKACCOUNT accountCollection[MAXACCOUNT];
int curAccount = 0;
void InsertAccount(FILE *fp)
{
BANKACCOUNT newaccount;
printf("please input the account information\n");
printf(">>account num:");
scanf("%d",&(newaccount.account));
printf(">>key:");
scanf("%d",&(newaccount.key));
printf(">>name:");
scanf("%s",newaccount.name);
printf(">>balance:");
scanf("%f",&(newaccount.balance));
fseek(fp,0L,SEEK_END);
fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance);
}
void GetAccount(FILE *fp)
{
int accountnum;
int key;
char name[32];
float balance;
int i =0,j;
char buffer[BUFFERSIZE];
int len;
curAccount = 0;
fseek(fp,0,SEEK_SET);
while(!feof(fp)) /* 因为feof()最后会读2遍,所以最后curAccount多加了1 */
{
fscanf(fp,"%d %d %s %f",&accountnum,&key,name,&balance);
accountCollection[curAccount].account = accountnum;
accountCollection[curAccount].key = key;
strcpy(accountCollection[curAccount].name ,name);
accountCollection[curAccount].balance = balance;
curAccount++;
}
}
void ListAccount(FILE *fp)
{
int i =0;
printf("There is %d accounts at all:\n",curAccount-1);/* curAccount减去多加的1 */
for(i = 0;i< curAccount-1;i++)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
}
}
int SearchAccount(FILE *fp,int accountnum)
{
int i =0;
for(i = 0;i< curAccount-1;i++)
{
if(accountCollection[i].account == accountnum)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
return 1;
}
}
return 0;
}
void DelAccount(FILE *fp,int accountnum)
{
int i;
if(SearchAccount(fp,accountnum)==0)
printf("Can't find the account\n");
else
{
for(i = 0;i<curAccount-1;i++)
{
if(accountCollection[i].account != accountnum)
fprintf(fp,"%d %d %s %.2f\n",accountCollection[i].account,accountCollection[i].key,accountCollection[i].name,accountCollection[i].balance);
}
printf("delete successfully!\n");
}
}
int main()
{
FILE *fp;
int accountnum;
int i;
do{
system("cls"); //清屏
puts("********************************************");
puts("* You can choose : *");
puts("* 1 : Insert a new Account *");
puts("* 2 : List all Accounts *");
puts("* 3 : Find a Account *");
puts("* 4 : Delete a Account *");
puts("* 5 : quit *");
puts("********************************************");
printf("Please input your choice:");
scanf("%d",&i);
system("cls"); //清屏
switch(i)
{
case 1:
if(!(fp = fopen("account.txt","a+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
InsertAccount( fp);
printf("press any key to continue.....\n");
getch();
fclose(fp);
break;
case 2:
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
ListAccount(fp);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 3:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
if(!SearchAccount(fp,accountnum))
printf("There is not the account:%d\n",accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 4:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
fclose(fp);
if(!(fp = fopen("account.txt","w+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
DelAccount(fp,accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
default:
break;
}
}while(i != 5);
return 0;
}
账户数据文件名已经设定为account.txt,这个文件要和上面这个程序放在同一个文件夹下面,不然就得用绝对路径(比如"d:\\book\\account.txt"),account内容可以用记事本打开自己改动,然后运行程序后就可以在程序中添加或删除
B. C语言程序设计题
VC写的
#include<stdio.h>
void main()
{
int x,i,j,m=0;
int a[10]={1,2,3,4,5,6,7,8,9,10};
scanf("%d",&x);
for(i=0;i<10;i++)
{
if(a[i]==x){
m=m+1;
for(j=i;j<10-m;j++)
{
a[j]=a[j+1];
}
}
}
printf("after del\n");
for(i=0;i<10-m;i++)
{
printf("%d ",a[i]);
}
}
C. 急求===《C语言程序设计实验·设计·习题》的答案
这是谭浩强版习题题答案,看与你的是否一致
1.5请参照本章例题,编写一个C程序,输出以下信息:
************
Very Goodj!
************
解:
main()
{
printf(" ************ \n");
printf("\n");
printf(" Very Good! \n");
printf("\n");
printf(" ************\n");
}
1.6编写一个程序,输入a b c三个值,输出其中最大者。
解:main()
{int a,b,c,max;
printf("请输入三个数a,b,c:\n");
scanf("%d,%d,%d",&a,&b,&c);
max=a;
if(max<B)
max=b;
if(max<C)
max=c;
printf("最大数为:%d",max);
}
第三章
3.3 请将下面各数用八进制数和十六进制数表示:
(1)10 (2)32 (3)75 (4)-617
(5)-111 (6)2483 (7)-28654 (8)21003
解:十 八 十六
(10)=(12)=(a)
(32)=(40)=20
(75)=(113)=4b
(-617)=(176627)=fd97
-111=177621=ff91
2483=4663=963
-28654=110022=9012
21003=51013=520b
3.5字符常量与字符串常量有什么区别?
解:字符常量是一个字符,用单引号括起来。字符串常量是由0个或若干个字符
而成,用双引号把它们括起来,存储时自动在字符串最后加一个结束符号'\0'.
3.6写出以下程序的运行结果:
#include
void main()
{
char c1='a',c2='b',c3='c',c4='\101',c5='\116';
printf("a%c b%c\tc%c\tabc\n",c1,c2,c3);
printf("\t\b%c %c\n",c4,c5);
解:程序的运行结果为:
aabb cc abc
A N
3.7将"China"译成密码.密码规律:用原来的字母后面第4个字母代替原来的字母,
例如,字母"A"后面第4个字母是"E",用"E"代替"A".因此,"China"应译为"Glmre".
请编一程序,用赋初值的议程使c1,c2,c3,c4,c5分别变成'G','1','m','r','e',并
输出.
main()
{char c1="C",c2="h",c3="i",c4='n',c5='a';
c1+=4;
c2+=4;
c3+=4;
c4+=4;
c5+=4;
printf("密码是%c%c%c%c%c\n",c1,c2,c3,c4,c5);
}
3.8例3.6能否改成如下:
#include
void main()
{
int c1,c2;(原为 char c1,c2)
c1=97;
c2=98;
printf("%c%c\n",c1,c2);
printf("%d%d\n",c1,c2);
}
解:可以.因为在可输出的字符范围内,用整型和字符型作用相同.
3.9求下面算术表达式的值.
(1)x+a%3*(int)(x+y)%2/4=2.5(x=2.5,a=7,y=4.7)
(2)(float)(a+b)/2+(int)x%(int)y=3.5(设a=2,b=3,x=3.5,y=2.5)
3.10写出下面程序的运行结果:
#include
void main()
{
int i,j,m,n;
i=8;
j=10;
m=++i;
n=j++;
printf("%d,%d,%d,%d\n",i,j,m,n);
}
解:结果: 9,11,9,10
第4章
4.4.a=3,b=4,c=5,x=1.2,y=2.4,z=-3.6,u=51274,n=128765,c1='a',c2='b'.想得
到以下的输出格式和结果,请写出程序要求输出的结果如下:
a= 3 b= 4 c= 5
x=1.200000,y=2.400000,z=-3.600000
x+y= 3.60 y+z=-1.20 z+x=-2.40
u= 51274 n= 128765
c1='a' or 97(ASCII)
c2='B' or 98(ASCII)
解:
main()
{
int a,b,c;
long int u,n;
float x,y,z;
char c1,c2;
a=3;b=4;c=5;
x=1.2;y=2.4;z=-3.6;
u=51274;n=128765;
c1='a';c2='b';
printf("\n");
printf("a=%2d b=%2d c=%2d\n",a,b,c);
printf("x=%8.6f,y=%8.6f,z=%9.6f\n",x,y,z);
printf("x+y=%5.2f y=z=%5.2f z+x=%5.2f\n",x+y,y+z,z+x);
printf("u=%6ld n=%9ld\n",u,n);
printf("c1='%c' or %d(ASCII)\n",c1,c2);
printf("c2='%c' or %d(ASCII)\n",c2,c2);
}
4.5请写出下面程序的输出结果.
结果:
57
5 7
67.856400,-789.123962
67.856400 ,-789.123962
67.86,-789.12,67.856400,-789.123962,67.856400,-789.123962
6.785640e+001,-7.89e+002
A,65,101,41
1234567,4553207,d687
65535,17777,ffff,-1
COMPUTER, COM
4.6用下面的scanf函数输入数据,使a=3,b=7,x=8.5,y=71.82,c1='A',c2='a',
问在键盘上如何输入?
main()
{
int a,b;
float x,y;
char c1,c2;
scanf("a=%d b=%d,&a,&b);
scanf(" x=%f y=%e",&x,&y);
scanf(" c1=%c c2=%c",&c1,&c2);
}
解:可按如下方式在键盘上输入:
a=3 b=7
x=8.5 y=71.82
c1=A c2=a
说明:在边疆使用一个或多个scnaf函数时,第一个输入行末尾输入的"回车"被第二
个scanf函数吸收,因此在第二\三个scanf函数的双引号后设一个空格以抵消上行
入的"回车".如果没有这个空格,按上面输入数据会出错,读者目前对此只留有一
初步概念即可,以后再进一步深入理解.
4.7用下面的scanf函数输入数据使a=10,b=20,c1='A',c2='a',x=1.5,y=-
3.75,z=57.8,请问
在键盘上如何输入数据?
scanf("%5d%5d%c%c%f%f%*f %f",&a,&b,&c1,&c2,&y,&z);
解:
main()
{
int a,b;
float x,y,z;
char c1,c2;
scanf("%5d%5d%c%c%f%f",&a,&b,&c1,&c2,&x,&y,&z);
}
运行时输入:
10 20Aa1.5 -3.75 +1.5,67.8
注解:按%5d格式的要求输入a与b时,要先键入三个空格,而后再打入10与20。%*f
是用来禁止赋值的。在输入时,对应于%*f的地方,随意打入了一个数1.5,该值不
会赋给任何变量。
4.8设圆半径r=1.5,圆柱高h=3,求圆周长,圆面积,圆球表面积,圆球体积,圆柱体积,
用scanf输入数据,输出计算结果,输出时要求有文字说明,取小数点后两位数字.请编
程.
解:main()
{
float pi,h,r,l,s,sq,vq,vz;
pi=3.1415926;
printf("请输入圆半径r圆柱高h:\n");
scanf("%f,%f",&r,&h);
l=2*pi*r;
s=r*r*pi;
sq=4*pi*r*r;
vq=4.0/3.0*pi*r*r*r;
vz=pi*r*r*h;
printf("圆周长为: =%6.2f\n",l);
printf("圆面积为: =%6.2f\n",s);
printf("圆球表面积为: =%6.2f\n",sq);
printf("圆球体积为: =%6.2f\n",vz);
}
4.9输入一个华氏温度,要求输出摄氏温度,公式为C=5/9(F-32),输出要有文字说明,
取两位小数.
解: main()
{
float c,f;
printf("请输入一个华氏温度:\n");
scanf("%f",&f);
c=(5.0/9.0)*(f-32);
printf("摄氏温度为:%5.2f\n",c);
}
第五章 逻辑运算和判断选取结构
5.4有三个整数a,b,c,由键盘输入,输出其中最大的数.
main()
{
int a,b,c;
printf("请输入三个数:");
scanf("%d,%d,%d",&a,&b,&c);
if(a<B)
if(b<C)
printf("max=%d\n",c);
else
printf("max=%d\n",b);
else if(a<C)
printf("max=%d\n",c);
else
printf("max-%d\n",a);
}
方法2:使用条件表达式.
main()
{int a,b,c,termp,max;
printf(" 请输入 A,B,C: ");
scanf("%d,%d,%d",&a,&b,&c);
printf("A=%d,B=%d,C=%d\n",a,b,c);
temp=(a>b)?a:b;
max=(temp>c)? temp:c;
printf(" A,B,C中最大数是%d,",max);
}
5.5 main()
{int x,y;
printf("输入x:");
scanf("%d",&x);
if(x<1)
{y=x;
printf("X-%d,Y=X=%d \n",x,y);
}
else if(x<10)
{y=2*x-1;
printf(" X=%d, Y=2*X-1=%d\n",x,y);
}
else
{y=3*x-11;
printf("X=5d, Y=3*x-11=%d \n",x,y);
}
}
(习题5-6:)自己写的已经运行成功!不同的人有不同的算法,这些答案仅供参考! 818pp.com
# include
void main()
{
float s,i;
char a;
scanf("%f",&s);
while(s>100||s<0)
{
printf("输入错误!error!");
scanf("%f",&s);
}
i=s/10;
switch((int)i)
{
case 10:
case 9: a='A';break;
case 8: a='B';break;
case 7: a='C';break;
case 6: a='D';break;
case 5:
case 4:
case 2:
case 1:
case 0: a='E';
}
printf("%c",a);
}
http://818pp.com/
5.7给一个不多于5位的正整数,要求:1.求它是几位数2.分别打印出每一位数字3.
按逆序打印出各位数字.例如原数为321,应输出123.
main()
{
long int num;
int indiv,ten,hundred,housand,tenthousand,place;
printf("请输入一个整数(0-99999):");
scanf("%ld",&num);
if(num>9999)
place=5;
else if(num>999)
place=4;
else if(num>99)
place=3;
else if(num>9)
place=2;
else place=1;
printf("place=%d\n",place);
printf("每位数字为:");
ten_thousand=num/10000;
thousand=(num-tenthousand*10000)/1000;
hundred=(num-tenthousand*10000-thousand*1000)/100;
ten=(num-tenthousand*10000-thousand*1000-hundred*100)/10;
indiv=num-tenthousand*10000-thousand*1000-hundred*100-ten*10;
switch(place)
{case 5:printf("%d,%d,%d,%d,%d",tenthousand,thousand,hundred,ten,indiv);
printf("\n反序数字为:");
printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,tenthousand);
break;
case 4:printf("%d,%d,%d,%d",thousand,hundred,ten,indiv);
printf("\n反序数字为:");
printf("%d%d%d%d\n",indiv,ten,hundred,thousand);
break;
case 3:printf("%d,%d,%d\n",hundred,ten,indiv);
printf("\n反序数字为:");
printf("%d%d%d\n",indiv,ten,hundred);
case 2:printf("%d,%d\n",ten,indiv);
printf("\n反序数字为:");
printf("%d%d\n",indiv,ten);
case 1:printf("%d\n",indiv);
printf("\n反序数字为:");
printf("%d\n",indiv);
}
}
5.8
1.if语句
main()
{long i;
float bonus,bon1,bon2,bon4,bon6,bon10;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;
bon10=bon6+400000*0.015;
scanf("%ld",&i);
if(i<=1e5)bonus=i*0.1;
else if(i<=2e5)bonus=bon1+(i-100000)*0.075;
else if(i<=4e5)bonus=bon2+(i-200000)*0.05;
else if(i<=6e5)bonus=bon4+(i-400000)*0.03;
else if(i<=1e6)bonus=bon6+(i-600000)*0.015;
else bonus=bon10+(i-1000000)*0.01;
printf("bonus=%10.2f",bonus);
}
用switch语句编程序
main()
{long i;
float bonus,bon1,bon2,bon4,bon6,bon10;
int branch;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;
bon10=bon6+400000*0.015;
scanf("%ld",&i);
branch=i/100000;
if(branch>10)branch=10;
switch(branch)
{case 0:bonus=i*0.1;break;
case 1:bonus=bon1+(i-100000)*0.075;break;
case 2:
case 3:bonus=bon2+(i-200000)*0.05;break;
case 4:
case 5:bonus=bon4+(i-400000)*0.03;break;
case 6:
case 7
case 8:
case 9:bonus=bon6+(i-600000)*0.015;break;
case 10:bonus=bon10+(i-1000000)*0.01;
}
printf("bonus=%10.2f",bonus);
} http://818pp.com/
5.9 输入四个整数,按大小顺序输出.
main()
{int t,a,b,c,d;
printf("请输入四个数:");
scanf("%d,%d,%d,%d",&a,&b,&c,&d);
printf("\n\n a=%d,b=%d,c=%d,d=%d \n",a,b,c,d);
if(a>b)
{t=a;a=b;b=t;}
if(a>c)
{t=a;a=c;c=t;}
if(a>d)
{t=a;a=d;d=t;}
if(b>c)
{t=b;b=c;c=t;}
if(b>d)
{t=b;b=d;d=t;}
if(c>d)
{t=c;c=d;d=t;}
printf("\n 排序结果如下: \n");
printf(" %d %d %d %d \n",a,b,c,d);
}
5.10塔
main()
{
int h=10;
float x,y,x0=2,y0=2,d1,d2,d3,d4;
printf("请输入一个点(x,y):");
scanf("%f,%f",&x,&y);
d1=(x-x0)*(x-x0)+(y-y0)(y-y0);
d2=(x-x0)*(x-x0)+(y+y0)(y+y0);
d3=(x+x0)*(x+x0)+(y-y0)*(y-y0);
d4=(x+x0)*(x+x0)+(y+y0)*(y+y0);
if(d1>1 && d2>1 && d3>1 && d4>1)
h=0;
printf("该点高度为%d",h);
}
D. c语言程序设计选择分支程序实验步骤输入一个学生成绩如果低于60,输出“fail"否则输出“pass"实验过程及结果
#include<stdio.h>
main()
{ int score;
scanf("%d",&score);
if(score>=60) printf("pass\n");
else printf("fail\n");
}
E. C语言设计程序!!!
include<stdio.h>
int main()
{
double a,b,c,s;
s=(a+b+c)/2;
printf("请输入三边长:");
scanf("%lf%lf%lf",&a,&b,&c)
if(a+b>c && a+c>b && b+c>a)
printf("NO triangle!\n");
else
printf("三角形面积为:%d\n,s*(s-a)*(s-b)*(s-c)");
}
F. C语言程序设计课程设计!
图书借阅管理,C语言编程的,只要设计部分的,,m
G. C语言程序设计:3、编程实现,将任意一个给定的字符数组中下标值为奇数的元素由大到小排列,其它元素不变。
#include <stdio.h>
#include <stdlib.h>
void main()
{
int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int lenth=sizeof(a)/sizeof(int)-1;
int i;////数组中奇数元素的个数;
int n,m,temp;////临时变量
int *b;
if(lenth%2==0)
i=lenth/2;
else
i=lenth/2+1;
b=(int *)malloc(i*sizeof(int));
for(n=0;n<=i;n++)
b[n]=a[2*n+1];///去除a数组中的奇数元素给b
for(n=0;n<i;n++)/////对b数组排序
for(m=0;m<i;m++)
{
if(b[i]<b[i+1])
{
temp=b[i+1];
b[i+1]=b[i];
b[i]=temp;
}
}
for(n=0;n<=i;n++)///还原a数组奇数元素
a[2*n+1]=b[n];
for(n=0;n<=lenth;n++)
printf("a[%d]=%d\t",n,a[n]);
}
H. 《C程序设计语言第2版·新版》pdf下载在线阅读全文,求百度网盘云资源
《C程序设计语言(第2版·新版)》([美] Brian W. Kernighan)电子书网盘下载免费在线阅读
链接: https://pan..com/s/1txJqYzmjYS-BSw43eLWrnQ
书名:C程序设计语言(第2版·新版)
作者:[美] Brian W. Kernighan
译者:徐宝文
豆瓣评分:9.4
出版社:机械工业出版社
出版年份:2004-1
页数:258
内容简介:
在计算机发展的历史上,没有哪一种程序设计语言像C语言这样应用广泛。本书作者是C语言的设计者之一Dennis M. Ritchie和着名计算机科学家Brian W. Kernighan合着的一本介绍C语言的权威经典着作。我们现在见到的大量论述C语言程序设计的教材和专着均以此书为蓝本。
原着第1版中介绍的C语言成为后来广泛使用的C语言版本——标准C的基础。人们熟知的“hello,World"程序就是由本书首次引入的,现在,这一程序已经成为众多程序设计语言入门的第一课。原着第2版根据1987年制定的ANSIC标准做了适当的修订.引入了最新的语言形式,并增加了新的示例,通过简洁的描述、典型的示例,作者全面、系统、准确地讲述了C语言的各个特性以及程序设计的基本方法。
对于计算机从业人员来说,本书是一本必读的程序设计语言方面的参考书。
作者简介:
Brian W. Kernighan,贝尔实验室计算科学研究中心高级研究人员,着名的计算机科学家。参加了UNIX系统、C语言、AWK语言和许多其他系统的开发,同时出版了许多在计算机领域具有影响的着作,如《The Elements of Programming Style》《The Practice of Programming》《The UNIX Programming Environment》《The AWK Language》《Software Tools》等。
Dennis M. Ritchie,1967年加入贝尔实验室。他和 Ken L. Thompson 两人共同设计并实现的C语言改变了程序设计语言发展的轨迹,是程序设计语言发展过程中的一个重要里程碑。与此同时,他们还设计并实现了UNIX操作系统。正是由于这两项巨大贡献,Dennis M. Ritchie 于1983年获得了计算机界的最高奖——图灵奖。此外,他还获得了ACM、IEEE、贝尔实验室等授予的多种奖项.。
I. 《C语言程序设计第四版》pdf下载在线阅读全文,求百度网盘云资源
《C语言程序设计第四版》网络网盘pdf最新全集下载:
链接: https://pan..com/s/1OJyaV3BLbsB8eBo8cUAvBQ
简介:《C程序设计(第四版)》是由谭浩强编着,2010年清华大学出版社出版的中国高等院校计算机基础教育课程体系规划教材。该书可作为高等学校各专业的正式教材,也是一本自学的教材
J. C语言程序设计问题——指针与数组(谁能指导我做下这个实验)
我给你解答吧!
这是两个实验吗?要不要分开写一下?