已便程序匯總_第1頁
已便程序匯總_第2頁
已便程序匯總_第3頁
已便程序匯總_第4頁
已便程序匯總_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、1樓最近發(fā)現(xiàn)好多朋友有這樣的問題,我估計原因可能在此 因為這個程序是你復(fù)制過來的,而他打的這個程序是用中文輸入打出來的 所以出現(xiàn)unknown character '0xa1',也就是C編譯不能識別字符。 C語言程序100例書中,就是這樣的,如果出現(xiàn)錯誤,我想你最好能夠自己輸入一遍,這樣就可以了,而且還能提高你的C語言書寫。2 #include<stdio.h>#include<string.h>void main()int i;char *a4="cao yan","mei qing","hu chao

2、","zhang bin wei"void zhuanhuan(char *q4);zhuanhuan(a);for(i=0;i<4;i+)printf("%st",ai);void zhuanhuan(char *q4)int i,j;char *m;for(i=0;i<3;i+) for(j=0;j<2;j+) if(strcmp( qj,qj+1)>0) m=qj;qj=qj+1;qj+1=m;比記:在指針數(shù)組做形參時,指針符號*不能掉,只能是*q4的形式,在指針數(shù)組做實參時,即不能帶*也不能寫成a6形式,只能寫成

3、a的形式3.#include <stdio.h>#include<string.h>void main()char *name4="cao yan ","zhang bin wei","mei qing ","hu cao"int i ;char change(char *p4);change(name);for (i=0;i<4;i+) printf(namei);printf("n");char change(char *p4)int i ,j;char * t

4、emp;int k;for(i=0;i<3;i+)k=i;for(j=i+1;j<4;j+) if(strcmp(pj,pk)<0)k=j; temp=pk;pk=pi;pi=temp;#include <stdio.h>int table10;void lookup(int *t,int *a,int n) int k; *a=t0; for(k=1;k<n;k+) if( tk<*a ) *a=tk; void main() int k,min,*p=&min;for (k=0;k<10;k+) scanf("%d"

5、;,table+k);lookup(table , p ,10);printf("min=%dn",min);4.#include<stdio.h> #include<math.h>float x1,x2;void main()int a,b,c;float h,m=0.0; void bigger_than_zero( float j,float k, float l);void equal_to_zero( float j,float k,float l);scanf("%d%d%d",&a,&b,&c

6、);printf("求%d*x*x+%d*x+%d=0的根n",a,b,c);m=b*b-4*a*c;h=sqrt(m);printf("m=%fn",m);printf("h=%fn", h);if(m>0)bigger_than_zero(a,b,h);if(m=0)equal_to_zero(a,b,h);void bigger_than_zero(float j, float k, float l)x1=(-k+l)/(2*j);x2=(-k-l)/(2*j);printf("%15.10f,%15.10f&q

7、uot;,x1,x2);void equal_to_zero(float j,float k, float l)x1=x2=(-k)/(2*j);printf("%15.10f,%15.10f",x1,x2);筆記:void函數(shù)不需要返回值,但需要設(shè)置一個全局變量5.#include <stdio.h>void main( ) int a11=100,40,28,19,16,13,9,6,4,1;int num,i,j;printf("a:n");for(i=0;i<10;i+)printf("%5d",ai);pr

8、intf("n");printf("insert:");scanf("%d",&num);if(num<a9) /*插入在數(shù)組尾*/ a10=num;else for(i=0;i<10;i+)/*插入在數(shù)組中間*/if(ai<num) for(j=9;j>=i;j-) aj+1=aj;ai=num;/*移動元素*/break; for(i=0;i<11;i+)printf("%5d",ai);6.0#include <stdio.h>#include<stri

9、ng.h>void main()char *name4="cao yan ","zhang bin wei","mei qing ","hu cao"int i ;char change(char *p4);change(name);for (i=0;i<4;i+) printf(namei);printf("n");char change(char *p4)int i ,j;char * temp;int k;for(i=0;i<3;i+)k=i;for(j=i+1;j<

10、;4;j+) if(strcmp(pj,pk)<0)k=j; temp=pk;pk=pi;pi=temp;7.0#include<stdio.h>void main()int a34=1,2,3,4,5,6,7,8,9,10,11,12;int i;printf("%dn",*(a0+9);printf("%dn",*(a1+6);printf("%dn",*(*(a+1)+2);筆記:*之后的一切在編繹之后都將變成類似與2000,2002的地址,所謂指針變量里面就是地址常量(如2000,2002)。8.0# def

11、ine LOW 10# define HIGH 5#define CHANGE 2int i=LOW#include<stdio.h>void main ()int workover (int i),reset (int i);int i=HIGH;reset(i/2);printf("i=%dn",i);reset(i=i/2);printf("i=%dn",i);reset(i/2);printf("i=%dn",i);workover(i);printf("i=%dn",i);int wokeov

12、er (int i)i=(i%i)*(i*i)/(2*i)+4);printf("i=%dn",i);return(i);int reset(int i)i=i<=CHANGE?HIGH:LOW;return(i);9.0#include<stdio.h>#include<malloc.h>#define KEEP 0#define LENGTH sizeof(struct student)struct student int num ;int score;char name20;struct student *next;void main (

13、)struct student *head,*p,*q;int n;p=q=(struct student *)sizeof(LENGTH);scanf("%d%d%s",p->num,p->score,p->name);head=0;n=0;while(p->num!=0)n+;if(n=1)head=p;else q->next=p;q=p;p=(struct student *)sizeof(LENGTH);scanf("%d%d%s",p->num,p->score,p->name);while(p

14、!=0)printf("%d%d%sn",p->num,p->score,p->name);p=p->next;10.0void main ()struct student int num ;int age ;char name20;stu3=1,20,"caoyan",2,21,"zhang bin wei",3,22,"mei qing "struct student *p;int i;p=stu;for(i=0;i<3;i+)printf ("%6d%6d%s"

15、;,stui.num,stui.age,);printf("n");11#include<stdio.h>void main()void search(float(*p)4,int n);float a34=50,51,59,69,74,62,68,96,94,53,68,67; search(a,3);void search(float(*p)4,int n)int i,j,flag;for(j=0;j<n;j+) flag=0; for(i=0;i<4;i+) if(*(*(p+j)+i)<60)flag=1; if (f

16、lag=1) printf("NO.%dfails,his scores are :n",j+1); for(i=0;i<4;i+) printf("%5.1f",*(*(p+j)+i); printf("n"); 12#include<stdio.h>void main ()int a,b,c,t,*p1,*p2,*p3;scanf("%d%d%d",&a,&b,&c);p1=&a;p2=&b;p3=&c;if(*p1>*p2)t=*p1;*

17、p1=*p2;*p2=t;if(*p1>*p3)t=*p1;*p1=*p3;*p3=t;if(*p2>*p3)t=*p2;*p2=*p3;*p3=t;printf("%4d%4d%4dn",a,b,c);printf("%4d%4d%4dn",*p1,*p2,*p3);13#include<stdio.h>void main()int a34=1,2,3,4,5,6,7,8,9,10;int *p;int i;p=a0;for(i=0;i<10;i+)printf("%4d",*p+);if(p-a0)%

18、3=0)printf("n");printf("n");14#include<stdio.h>void main()int a34=1,2,3,4,5,6,7,8,9,10,11,12;int i,j,k;int*p,*b;int(*m)4,(*h)4,(*l)4;p=a0;m=a+1;h=a;l=a+2;b=a0;printf("%dn",*(a0+9);printf("%dn",*(a1+6);printf("%dn",*(*(a+1)+5);for(i=0;i<3;i+)

19、 for(j=0;j<4;j+)printf("%on",&aij);for(k=0;k<12;k+) printf("%10dn",&*(p+k);if(k%4=0)printf("n");for(i=0;i<4;i+) printf("%4d",*(*m+i); printf("n");for(i=0;i<4;i+) printf("%4d",*(*h+i); printf("n");for(i=0;i<4

20、;i+) printf("%4d",*(*l+i); printf("n");for(i=13;i<19;i+) printf("%4d",*(b+i); printf("n");比記:若想指針變量指向二維數(shù)組,則要把二維數(shù)組的首址給之,若想指針變量指向二維數(shù)組的某一行則要定義int(*m)4。15#include<stdio.h>void main()int i;char a10="cao yan"char change(b10);change(a10);for(i=0;i&

21、lt;10;i+) printf("%c",ai);char change(b10)int i,j;char m;for(i=0;i<9;i+) for(j=0;j<9-i;j+) if(aj>zj+i) m=aj;aj=aj+1;aj+1=m;16#include<stdio.h>void main()int a34=1,2,3,4,5,6,7,8,9,10,11,12;int *p;p=a0;printf("%dn",*(a0+9);printf("%dn",*(a1+6);printf("

22、%dn",*(*(a+1)+2);printf("%dn",*(p+9);17#include<stdio.h>void main()int a3=1,2,3;int *p;int i,j;p=a;for(i=0;i<=2;i+)printf("%d",*(p+i);for(i=0;i<=2;i+)printf("%d",*(a+i);for(i=0;i<=2;i+)printf("%d",pi);for(i=0;i<=2;i+)printf("%d"

23、;,ai);比記:將數(shù)組名賦值給指針變量時,只是簡單的替換18#include<stdio.h>void main()int a=5;char *name5="caoyan","is","a","good","student"int *p;p=&a;printf("%dn",p);printf("%dn",&p);printf("%dn",*p);printf("%dn",&a);

24、printf("%on",name0);printf("%on",name0+1);printf("%on",name);printf("%on",&name00);printf("%cn",*(name4+3);printf("%cn",*name0);printf("%on",name);printf("%cn",*name0);19#include<stdio.h>void main()char a="

25、;I love china very much"char b44="is","a","good","boy"char *p,i;char (*m)4;p=a;m=b+2;printf("%sn",a);for(i=0;i<=23;i+) printf("%c",ai);printf("n");printf("%sn",p);printf(p);printf(a);puts(p);printf("%c"

26、,*(p+22);printf("n");for(i=0;i<4;i+) printf("%c",*(*m+i); 比記:輸出n就等于輸出空格,printf(p)括號內(nèi)可以是數(shù)組名或指向該數(shù)組的指針變量名20#include<stdio.h>void main ()int a=4;int sum(int b);int c;c=sum(a);printf("%d",c);int sum(int b)if (b>10) return(7);else return(5);21#include<stdio.h&g

27、t;#include<string.h>void main ()char a;a='x11'printf("%cn",a);putchar(a);printf("%dn",a);putchar('016');putchar('n');printf("016");putchar(29);比記:putchar只能輸出字符,若后面接數(shù)字,則輸出數(shù)字對應(yīng)的字符。'x11'或'011'形式時相當(dāng)于數(shù)字printf("016")putc

28、har('016')是固定形式都是輸出字符。22#include <stdio.h>void main( ) int i , k;int s10; void sort(int x,int n);printf(" Input number : n");for (i=0; i<10; i+)scanf("%d",&si);sort(s, 10);for (k=0; k<10; k+)printf( "%5d", sk);printf("n");void sort( int

29、 x, int n ) int i, j, temp,min; for ( i=0; i<9; i+) min=i; for(j=i+1;j<10;j+) if ( xj < xmin)min=j; if(min!=i) temp=xmin; xmin=xi; xi=temp; 23#include <stdio.h>int table10;void lookup(int *t,int *a,int n) int k; *a=t0; for(k=1;k<n;k+) if( tk<*a ) *a=tk; void main() int k,min,*p=

30、&min;for (k=0;k<10;k+) scanf("%d",table+k);lookup(table , p ,10);printf("min=%dn",min);26#include<stdio.h>void main()int a11=11,15,20,23,29,41,51,63,79,93;int i,x,num,n=0;scanf("%d",&x);for(i=0;i<10;i+)if(ai<x&&x<ai+1)num=i+1;printf(&qu

31、ot;%dn",num);for(i=9;i<10;i+)ai+1=ai;if(i=num)break;a4=x;for(i=0;i<11;i+)n+;printf("%-4d",ai);if(n%3=0)printf("n");printf("n");27#include<stdio.h>void main()int min(intx,inty);int max(int s,int k);int a,b;scanf("%d%d",&a,&b);printf(&qu

32、ot;%d,%d的最小公倍數(shù)是%dn",a,b,min(a,b);printf("%d,%d的最大公約數(shù)是%d",a,b,max(a,b);int min(int x,int y)float m;int n,j;for(n=1;n<10000;n+)m=(x*n)/y;if(x*n)%y=0)break;j=x*n;return(j);int max(int s,int k)float m;int n,h;for(n=1;n<10000;n+)m=(s*n)/k;if(s*n)%k=0)break;h=k/n;return(h);28#include&

33、lt;stdio.h>#include<math.h>#define S(a,b,c) (a+b+c)/2#define AREA(a,b,c) sqrt(S(a,b,c)*(S(a,b,c)-a)*(S(a,b,c)-b)*(S(a,b,c)-c)void main()int a,b,c;float s,area;scanf("%d%d%d",&a,&b,&c);if(a+b>c&&a+c>b&&b+c>a)s=S(a,b,c);area=AREA(a,b,c);printf(&q

34、uot;s=%10.5f",s);printf("area=%10.5f",area);else printf("不能構(gòu)成三角形");筆記:1.宏定義帶參永遠是機械性的死代入2.宏的套用使用2.若出現(xiàn)Linking.ertertrtyrty.obj : error LNK2001: unresolved external symbol _printDebug/ertertrtyrty.exe : fatal error LNK1120: 1 unresolved externals的錯誤,可能是printf中的某個字母打掉了29#include

35、<stdio.h>void main()int a33;int i,j;int change(int array33);printf("請輸入九個數(shù):");for(i=0;i<3;i+) for(j=0;j<3;j+)scanf("%d",&aij);for(i=0;i<3;i+) for(j=0;j<3;j+) printf("%3d",aij);printf("n");change(a);int change(int array33) int h,k,t; for(h

36、=0;h<3;h+) for(k=0;k<=h;k+) t=arrayhk; arrayhk=arraykh; arraykh=t; for(h=0;h<3;h+)for(k=0;k<3;k+)printf("%dt",arrayhk); printf("n"); 30#include <stdio.h>void main( )int n;int caoyan(int x);scanf("%d",&n);printf("%dn",n); caoyan(n);int cao

37、yan(int x)int i;for(i=2;i<=x-1;i+)if(x%i=0) printf("%d不是素數(shù)",x);break;if(i=x)printf("%d是素數(shù)",x);筆記:若使用if(x%i=0)break; printf("%d不是素數(shù)",x);則會出錯,當(dāng)輸出素數(shù)13時,則if(x%i=0)break循環(huán)停止,后面作為一個和if(x%i=0)break; 無關(guān)的語句依就輸出,若使用if(x%i=0) printf("%d不是素數(shù)",x);break;則循環(huán)停止且只輸出一次。一旦遇到b

38、reak語句,則后面的語句都不執(zhí)行,若使用continue語句,則后面的不執(zhí)行,而是執(zhí)行i+,后執(zhí)行i<531#include <stdio.h>void main( ) int mark; int n=0 , sum=0 ; int max=0 , min=100 ; for ( ; ; ) ; scanf("%d", &mark); if ( mark > 100 ) printf(" Mark > 100 , Please reinput n ") ; continue; if ( mark=-1) break

39、; n + ; sum=sum + mark ; if( mark > max ) max = mark ; if( mark < min ) min = mark ; sum=sum/ n ; printf("max =%d , min = %d, aver = %d n", max , min , sum); 32#include <stdio.h> main() int i,j,row=0,colum=0,max; int a34=1,2,3,4,9,8,7,6,-10,10,-2,2; max=a00; for(i=0;i<=2;i+)

40、 for(j=0;j<=3;j+) if(aij>max) max=aij; row=i; colum=j; printf("max=%d,row=%d,colum=%dn",max,row,colum); 33#include<stdio.h>void main()int i,sum,n;int amass(i);sum=0; scanf("%d",&n); for(i=1;i<=n;i+)sum=sum+amass(i);printf("%d",sum);int amass(int i)int

41、 c;if(i=1)c=2;else c=10*amass(i-1)+amass(1);return(c);34#include<stdio.h>void main()int i,t,j,k;int a10;printf("請輸入十個整數(shù):");for(i=0;i<10;i+)scanf("%d",&ai);for(j=0;j<9;j+) for(i=0;i<9-j;i+) if(ai>ai+1) t=ai; ai=ai+1; ai+1=t; for(i=0;i<10;i+)printf("%5

42、d",ai);35#include<stdio.h>void main() int i,k,n;n=0;for(i=3;i<=100;i+)for(k=2;k<i;k+)if(i%k=0)break; if (i=k)n+;if(n%5=0)printf("n");printf("%-6d",i);36#include<stdio.h>void main()int a,b,c;int j,h;for(a=1;a<=9;a+) for(b=0;b<=9;b+) for(c=0;c<=9;c+)h=100*a+10*b+c;j=a*a*a+b*b*b+c*c*c;if(h=j)printf("%d%d%d是水仙花數(shù)n",a,b,c);37【進制轉(zhuǎn)化】#include<stdio.h>void main()int x;int change(int n);scanf("%d",&x);printf("十六進制數(shù)%d轉(zhuǎn)化成十進制數(shù)是%dn",x,change(x);int change(int n)int a,b

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論