指針作業(yè)(完成)_第1頁
指針作業(yè)(完成)_第2頁
指針作業(yè)(完成)_第3頁
指針作業(yè)(完成)_第4頁
指針作業(yè)(完成)_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

7/7指針作業(yè)(完成)

C語言作業(yè)

學(xué)生學(xué)院計(jì)算機(jī)學(xué)院

專業(yè)班級網(wǎng)絡(luò)工程2班

學(xué)號3108007075學(xué)生姓名李德

成績

(2008年12月30日)

廣東工業(yè)大學(xué)計(jì)算機(jī)學(xué)院編制

指針作業(yè)

1.利用指針編程,對5X5矩陣a中任意兩行進(jìn)行交換,交換時(shí)不能使用數(shù)組。

解:1.ex.h

#include

voidenter(intn,inta[5][5]);

voidswap(int*p1,int*p2,inta[5][5]);

voidprint(intn,inta[5][5]);

2.file1.c

#include

#include"ex.h"

inta[5][5];

voidmain()

{

externvoidenter(intn,inta[5][5]);

externvoidswap(int*p1,int*p2,inta[5][5]);

externvoidprint(intn,inta[5][5]);

intn*p1,*p2;

enter(n,a);

swap(p1,p2,a);

print(n,a);

}

3.file2.c

#include

voidenter(intn,inta[5][5])

{

printf("input5*5_matrix:\n");

for(n=0;n

voidswap(int*p1,int*p2,inta[5][5])

{

int*p,i1,i2,n;

printf("choosethetwolinesyouwanttoswatch:\n");

scanf("%d,%d",

if(i1>4||i2>4)

printf("entererror!\n");

else

for(n=0;n

voidprint(intn,inta[5][5])

{

printf("thenewmatrixis:\n");

for(n=0;n

voidenter(intm);

voidcopystr(char*p1,char*p2,intm);

voidsort(charstr2[],intm);

2.file1.c

#include

#include

#include"ex.h"

intm;

charstr2[10];

voidmain()

{

externvoidenter(intm);

externvoidcopystr(char*p1,char*p2,intm);

externvoidsort(charstr2[],intm);

charstr1[10];

enter(m);

copystr(str1,str2,m);

printf("result:%s\n",str2);

sort(str2,m);

}

3.file2.c

#include

voidcopystr(char*p1,char*p2,intm)

{

intn;

n=0;

while(n

voidsort(charstr2[],intm)

{

inti,j;

chart;

for(j=1;jstr2[i+1])

{

t=str2[i];

str2[i]=str2[i+1];

str2[i+1]=t;

}

printf("stringsorted:");

for(i=0;is2),0(s1=s2),-1(s1

voidstdio(char*p1,char*p2);

cmpstr(char*p1,char*p2);

2.file1.c

#include

#include"ex.h"

voidmain()

{

externvoidstdio(char*p1,char*p2);

externcmpstr(char*p1,char*p2);

char*p1,*p2;

stdio(p1,p2);

cmpstr(p1,p2);

}

3.file2.c

#include

voidstdio(char*p1,char*p2)

{

intm;

charstr1[20],str2[20];

printf("inputtwostrings:\n");

scanf("%s",str1);

scanf("%s",str2);

p1=

p2=

m=cmpstr(p1,p2);

printf("theresultis:%d\n",m);

}

4.file3.c

#include

cmpstr(char*p1,char*p2)

{

inti;

i=0;

while(*(p1+i)==*(p2+i))

if(*(p1+i++)=='\0')return(0);

return(*(p1+i)-*(p2+i));

}

5.運(yùn)行結(jié)果

○1

○2.

○3.

5.求出所有這樣的三位整數(shù),它的2倍,3倍仍然是三位整數(shù),這三個(gè)三位數(shù)使用1到9之間不同的數(shù)字。如m=192,2m=384,3m=756。

解:1.ex.h

#include

voidcount(inta[9]);

check(intt,int*s,inta[9]);

2.file1.c

#include

#include”ex.h”

inta[9];

voidmain()

{

externvoidcount(inta[9]);

externvoidcheck(intt,int*s,inta[9]);

intt,*s;

count(a);

check(t,s,a);

}

3.file2.c

#include

voidcount(inta[9])

{

intm,count=0;

for(m=123;m

check(intt,int*s,inta[9])

{

int*p,*q;

for(p=s;pnum==0)

p2->next=NULL;

else

{

p2->next=p1;

p2=p1;

len++;

}

}

p1=head;

printf("\noriginallist:\n");

do

{

printf("%2d",p1->num);

if(p1->next!=NULL)

p1=p1->next;

}while(p1->next!=NULL);

printf("%2d",p1->num);

printf("\n");

sort(stu.num,stu*next);

printf("thenewlist:\n");

do

{

printf("%2d",p1->num);

if(p1->next!=NULL)

p1=p1->next;

}while(p1->next!=NULL);

printf("%2d",p1->num);

printf("\n");

}

voidsort(strcutstu.num,structstu*next){未完成}

2.有鏈表a和b,它們中的每個(gè)節(jié)點(diǎn)都包括學(xué)號,姓名,成績。編程從a表中刪去b表中有相同學(xué)號的節(jié)點(diǎn)。

解:1.程序如下:

#includenext=a+i;

elsep1->next=NULL;

printf("%4d%8s%3d\n",p1->num,p1->name,p1->score);

if(inext=NULL;

printf("%4d%8s%3d\n",p2->num,p2->name,p2->score);

if(inext;

}

p1=head1;

while(p1!=NULL)

{

p2=head2;

while((p1->num!=p2->num)

if(p1->num==p2->num)

if(p1==head1)

head1=p1->next;

else

{

p->next=p1->next;

p1=p1->next;

}

else

{

p=p1;

p1=p1->next;

}

}

printf("\nresult:\n");

p1=head1;

while(p1!=NULL)

{

printf("%4d%7s%3d\n",p1->num,p1->name,p1->score);

p1=p1->next;

}

}

2.運(yùn)行結(jié)果

3.把一個(gè)鏈表按反序排序,即將原鏈頭當(dāng)作鏈尾,原鏈尾當(dāng)作鏈頭。解:1.程序如下:

#include

#include

structstu

{

intnum;

structstu*next;

}*p1,*p2;

structstu*creat(void)

{

inttemp;

structstu*head=NULL;

printf("\ninputnumber:");

while(scanf("%d",

if(head==NULL)

head=p1;

else

p2->next=p1;

p1->num=temp;

printf("inputnumber:");

p2=p1;

}

p2->next=NULL;

return(head);

}

voidoutput(structstu*outhead)

{

for(p1=outhead;p1!=NULL;printf("%4d",p1->num),p1=p1->next);}

structstu*turnback(structstu*head)

{

structstu*new,*newhead=NULL;

do{

p2=NULL;

p1=head;

while(p1->next!=NULL)p2=p1,p1=p1->next;

if(newhead==NULL)newhead=p1,new=newhead->next=p2;

new=new->next=p2;

p2->next=NULL;

}while(head->n

溫馨提示

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

評論

0/150

提交評論