當前位置:首頁 » 編程語言 » 王明軍劉佩琦c語言程序設計
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

王明軍劉佩琦c語言程序設計

發布時間: 2022-06-07 05:27:11

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

提取碼: sejp

書名: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

?pwd=gvk5 提取碼: gvk5
簡介:《C程序設計(第四版)》是由譚浩強編著,2010年清華大學出版社出版的中國高等院校計算機基礎教育課程體系規劃教材。該書可作為高等學校各專業的正式教材,也是一本自學的教材

J. C語言程序設計問題——指針與數組(誰能指導我做下這個實驗)

我給你解答吧!
這是兩個實驗嗎?要不要分開寫一下?