第一篇:用C語言描述的五角星完整代碼
#include
int i1,j1,k1,i2,j2,k2,i3,j3,k3,i4,j4,k4,m4,n4;printf(“五角星:n”);for(i1=1;i1<6;i1++)
// /*這是五角星的上面一個角*/ { for(j1=1;j1<19-i1;j1++)
// /*這是空格*/
printf(“ ”);
for(k1=1;k1<=2*i1-1;k1++)///*這是“*”*/
printf(“*”);
printf(“n”);} for(i2=1;i2<5;i2++)
// /*這是五角星的中間兩個角*/ { for(j2=1;j2<3*i2-3;j2++)
printf(“ ”);
for(k2=1;k2<=42-6*i2;k2++)
printf(“*”);
printf(“n”);} for(i3=1;i3<3;i3++)
//
/*這是中間與下部相接的部分*/ { for(j3=1;j3<12-i3;j3++)
printf(“ ”);
for(k3=1;k3<=12+2*i3;k3++)
printf(“*”);
printf(“n”);} for(i4=1;i4<5;i4++)
//
/*這是五角星的下面兩個角*/ { for(j4=1;j4<10-i4;j4++)
printf(“ ”);
for(k4=1;k4<=10-2*i4;k4++)
printf(“*”);
for(m4=1;m4<6*i4-3;m4++)
printf(“ ”);
for(n4=1;n4<=10-2*i4;n4++)
printf(“*”);
printf(“n”);} printf(“Congratulations!nWe've successfully drawn a we?n(*^_^*)n”);
return 0;}
beautiful pentagon,haven't
第二篇:C語言課程設計代碼
#include “stdio.h” #include
void main(){ int n=0;struct course *head=NULL;void insert(struct course **head,struct course *cou);void Print(struct course **head,int *n);void Modify(struct course **head,int *n);void Require(struct course **head);void Creat(struct course **head,int *n);void Delete(struct course **head,int *n);void Fun(struct course **head,int *n);
Fun(&head,&n);}
void insert(struct course **head,struct course *cou){ struct course *p0,*p1,*p2;p2=p1=*head;p0=cou;if(*head){
while((p0->semester>p1->semester)&&(p1->next))
{
p2=p1;
p1=p1->next;
}
if(p0->semester
semester)
{
if(*head==p1)*head=p0;
else p2->next=p0;
p0->next=p1;}
else
{
if(p0->semester==p1->semester){ while((p0->cID>p1->cID)&&(p1->next)&&(p0->semester==p1->semester))
{
} if(p0->semester!=p1->semester){
} else {
if(p0->cID<=p1->cID){
if(*head==p1)*head=p0;else p2->next=p0;p2=p1;p1=p1->next;p2->next=p0;p0->next=p1;
p0->next=p1;
}
else
{p1->next=p0;p0->next=NULL;}
}
}
else
{p1->next=p0;p0->next=NULL;}
} } else
{
*head=p0;
p0->next=NULL;} }
void Print(struct course **head,int *n){ struct course *p;p=*head;if(*head){
if(*n==1)printf(“nThis %d record is:n”,*n);
else printf(“nThese %d records are:n”,*n);
printf(“semester cID
name
creditn”);
do
{ printf(“%-10d%-10d%-18s%-12.1f n”,p->semester,p->cID,p->name,p->credit);
p=p->next;
}while(p!=NULL);} else printf(“nList null!n”);}
void Modify(struct course **head,int *n){ struct course *p,*p2;int cID;if(*head){
Print(head,n);while(1){ printf(“nPlease input the cID which you want to modify:”);
scanf(“%d”,&cID);p2=p=*head;while(p->next&&(cID!=p->cID)){
p2=p;
p=p->next;} if(cID==p->cID){
printf(“Please input the new cID(1~60):”);
scanf(“%d”,&p->cID);
while(p->cID<0||p->cID>60)
{
printf(“nError!”);
printf(“nPlease input the new cID(1~60):”);
scanf(“%d”,&p->cID);
}
printf(“Please input the new semester(1~8):”);
scanf(“%d”,&p->semester);while(p->semester<0||p->semester>8)
{
printf(“nError!”);
printf(“nPlease input the new semester(1~8):”);
scanf(“%d”,&p->semester);
}
printf(“Please input the new credit:”);
scanf(“%f”,&p->credit);
printf(“Please input the new name:”);
scanf(“%s”,p->name);
if(p==*head)*head=p->next;
else p2->next=p->next;
insert(head,p);
break;
}
else printf(“%d not been found!n”,cID);
} } else {printf(“nList null!n”);} }
void Require(struct course **head){ struct course *p;float sum=0;int sem,i=0;printf(“nPlease input the semester which is required:”);
scanf(“%d”,&sem);p=*head;while(p){
if(sem==p->semester)
{
i++;if(i==1)printf(“nsemester cID
name
creditn”);printf(“%-10d%-10d%-18s%-12.1f n”,p->semester,p->cID,p->name,p->credit);
sum=sum+p->credit;
}
p=p->next;} printf(“The sum of credit in this term is:%.1fn”,sum);}
void Creat(struct course **head,int *n){ struct course *p1;while(1){
p1=(struct course *)malloc(LEN);
printf(“Please input the cID(1~60):”);
scanf(“%d”,&p1->cID);
while(p1->cID<0||p1->cID>60)
{
printf(“nError!”);
printf(“nPlease input the cID(1~60):”);
scanf(“%d”,&p1->cID);
}
if(p1->cID==0)break;
printf(“Please input the semester(1~8):”);
scanf(“%d”,&p1->semester);
while(p1->semester<0||p1->semester>8)
{
printf(“nError!”);
printf(“nPlease input the semester(1~8):”);scanf(“%d”,&p1->semester);
}
} } printf(“Please input the credit:”);scanf(“%f”,&p1->credit);printf(“Please input the name:”);scanf(“%s”,p1->name);insert(head,p1);*n=*n+1;printf(“nYou can continue until the cID is ”0“!n”);Print(head,n);void Delete(struct course **head,int *n){
struct course *p1,*p2;int cID;Print(head,n);if(*head){ printf(“Please input the cID of the course which you want to delete:”);scanf(“%d”,&cID);p1=*head;
while(cID!=p1->cID&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(cID==p1->cID)
{
if(p1==*head)*head=p1->next;
else p2->next=p1->next;
printf(“Have delete cID:%dn”,cID);
*n=*n-1;
}
else printf(“%d not been found!n”,cID);} }
void Fun(struct course **head,int *n){ char num;
while(1)
{
system(“cls”);
puts(“**************** Main Menu ******************”);
puts(“* 1.Add Records
2.Print Records
*”);
puts(“* 3.Delete Records
4.Modify Records *”);
puts(“* 5.Require Records 6.Exit
*”);
printf(“Please input your choice: ”);
scanf(“%d”,&num);
switch(num)
{
case 1:Creat(head,n);break;
case 2:Print(head,n);break;
case 3:Delete(head,n);break;
case 4:Modify(head,n);break;
case 5:Require(head);break;case 6:exit(0);break;
default: break;
}
printf(“nPress ”Enter“ to continue!”);getchar();getchar();
} }
第三篇:c語言迷宮問題代碼實現
C語言迷宮問題代碼如下:
#include
#include
#define LEN sizeof(SEAT)
#define MAXSIZE 100
#define LENGTH 30
typedef struct
{
int x;//橫坐標
int y;//縱坐標
int di;//表示方向,0-3分別表示東南西北。
}SEAT;
struct StackList
{
SEAT stack[MAXSIZE];
int top;
}*Stack;
int EmptyStack(StackList*Stack)//判斷是否為空棧
{
if(Stack->top==0)
return 0;
else
return 1;
}
int Move[4][2]={{0,1},{1,0},{0,-1},{-1,0}};//分別表示向東、西、南、北需要加上的坐標
int Mase[LENGTH][LENGTH]={0};//初始化為0
int length,width;
void InitMase()//在迷宮的外圍添加一層“墻壁”(賦值為1),使得迷宮的任意一點都有四個方向
{
int i,j;
for(i=0;i { for(j=0;j Mase[i][j]=1; } for(i=0;i { for(j=0;j Mase[j][i]=1; } } void InitStack(StackList*Stack)//初始化 { Stack->top=0; return; } int PushStack(StackList*Stack,SEAT CurSeat)//進棧 { if(Stack->top==MAXSIZE-1) return false; else { Stack->stack[Stack->top].x=CurSeat.x; Stack->stack[Stack->top].y=CurSeat.y; Stack->stack[Stack->top].di=CurSeat.di; Stack->top++; return true; } } int PopStack(StackList*Stack)//出棧 { if(Stack->top==0) return false; else { Stack->top--; return true; } } int Pass(SEAT p)//判斷當前是否可行 { if(Mase[p.x][p.y]==0) { return true; } else return false; } SEAT NextSeat(SEAT CurSeat)//查找下一個點,并返回 { SEAT temp; temp.x=CurSeat.x+Move[CurSeat.di][0]; temp.y=CurSeat.y+Move[CurSeat.di][1]; return temp; } void Mark(SEAT p)//標記已經走過的點,避免重復 { Mase[p.x][p.y]=-1; } int PathWay(SEAT start,SEAT end)//找路線 { Stack=(struct StackList*)malloc(sizeof(struct StackList)); InitStack(Stack); SEAT CurSeat; CurSeat.x=start.x+1;//由于多加了一層墻壁,因此坐標的值要加1 CurSeat.y=start.y+1;// CurSeat.di=start.di;// do { if(Pass(CurSeat)) { PushStack(Stack,CurSeat); Mark(CurSeat); if(CurSeat.x==end.x+1&&CurSeat.y==end.y+1)//如果找到出口,返回{ return true; } else { int find=0; while(CurSeat.di<3&&find==0)//找下一個結點的方向 { CurSeat.di++; SEAT temp; temp=NextSeat(CurSeat); if(Mase[temp.x][temp.y]==0) { temp.di=-1; CurSeat=temp; find =1; } } } } else { if(EmptyStack(Stack))//當前的點不能走,出棧 PopStack(Stack); if(EmptyStack(Stack))//當前的點變為前一個點 { CurSeat=Stack->stack[Stack->top-1]; } while(CurSeat.di==3&&EmptyStack(Stack))////當前的點找不到下一個點,出棧 { PopStack(Stack); CurSeat=Stack->stack[Stack->top-1];//當前的點變為前一個點} if(EmptyStack(Stack)) { int find=0; while(CurSeat.di<3&&find==0)////找下一個結點的方向 { CurSeat.di++; SEAT temp; temp=NextSeat(CurSeat); if(Mase[temp.x][temp.y]==0) { temp.di=-1; CurSeat=temp; find =1; } } } } }while(EmptyStack(Stack)); return false; } void PrintStack(StackList*Stack)//輸出路線 { if(Stack->top==0) printf(“There is no route can be out of the mazen”); else { int i; for(i=0;i { if(i!=0) printf(“->(%d,%d)”,Stack->stack[i].x-1,Stack->stack[i].y-1); else printf(“(%d,%d)”,Stack->stack[i].x-1,Stack->stack[i].y-1); } } } void PrintMase()//輸出迷宮 { int i,j; for(i=1;i { for(j=1;j { if(j!=1) printf(“ %d”,Mase[i][j]); else printf(“%d”,Mase[i][j]); } printf(“n”); } } int main() { int n; SEAT start,end; printf(“Please enter the maze of the length and width:n”); scanf(“%d%d”,&length,&width); printf(“Please enter the number of the maze wall unit(0 printf(“Please enter the labyrinth of the coordinates of the wall unit(0<=row,column):n”);while(--n>=0) { int x,y; scanf(“%d%d”,&x,&y); Mase[x+1][y+1]=1; } InitMase(); PrintMase(); printf(“Please enter the coordinates entrance(0<=x<%d,0<=y<%d):n”,length,width); scanf(“%d%d”,&start.x,&start.y); start.di=-1; printf(“Please enter the coordinates exports(0<=x<%d,0<=y<%d):n”,length,width); scanf(“%d%d”,&end.x,&end.y); end.di=0; if(PathWay(start,end)) PrintStack(Stack); else printf(“There is no route can be out of the mazen”);return 0; } of the of the maze maze 《數據結構》課程設計題目(程序實現采用C語言) 題目1:猴子選王(學時:3) 一堆猴子都有編號,編號是1,2,3...m,這群猴子(m個)按照1-m的順序圍坐一圈,從第1開始數,每數到第n個,該猴子就要離開此圈,這樣依次下來,直到圈中只剩下最后一只猴子,則該猴子為大王。 要求:m及n要求從鍵盤輸入,存儲方式采用向量及鏈表兩種方式實現該問題求解。 //鏈表 #include typedef struct _RingNode { int pos; struct _RingNode *next;}RingNode, *RingNodePtr; // 創建約瑟夫環,pHead:鏈表頭指針,count:鏈表元素個數 void CreateRing(RingNodePtr pHead, int count){ RingNodePtr pCurr = NULL, pPrev = NULL; int i = 1; pPrev = pHead; while(--count > 0) { pCurr =(RingNodePtr)malloc(sizeof(RingNode)); i++; pCurr->pos = i; pPrev->next = pCurr; pPrev = pCurr; } pCurr->next = pHead;// 構成環狀鏈表 } void KickFromRing(RingNodePtr pHead, int n){ RingNodePtr pCurr, pPrev; int i = 1; // 計數 pCurr = pPrev = pHead; while(pCurr!= NULL) { if(i == n) { // 踢出環 printf(“n%d”, pCurr->pos); // 顯示出圈循序 pPrev->next = pCurr->next; free(pCurr); pCurr = pPrev->next; i = 1; } pPrev = pCurr; pCurr = pCurr->next; if(pPrev == pCurr) { // 最后一個 printf(“nKing is %d”, pCurr->pos); // 顯示出圈循序 free(pCurr); break; } i++; } } int main(){ int n = 0, m = 0; RingNodePtr pHead = NULL; printf(“M(person count)= ”); scanf(“%d”, &m); printf(“N(out number)= ”); scanf(“%d”, &n); if(m <= 0 || n <= 0) { printf(“Input Errorn”); return 0; } // 建立鏈表 pHead =(RingNodePtr)malloc(sizeof(RingNode)); pHead->pos = 1; pHead->next = NULL; CreateRing(pHead, m);// 開始出圈 printf(“nKick Order: ”); KickFromRing(pHead, n); printf(“n”); system(“pause”); return 0;} //數組做: #include void SelectKing(int MonkeyNum, int CallNum); void main(){ int MonkeyNum; int CallNum; /* 輸入猴子的個數 */ printf(“Monkey Num = ”); scanf(“%d”, &MonkeyNum); /* 輸入M的值 */ printf(“Call Num = ”); scanf(“%d”, &CallNum); SelectKing(MonkeyNum, CallNum); } void SelectKing(int MonkeyNum, int CallNum){ int *Monkeys;// 申請一個數組,表示所有的猴子; int counter = 0;//計數,當計數為猴子個數時表示選到最后一個猴子了; int position = 0;// 位置,數組的下標,輪流遍歷數組進行報數; int token = 0;// 令牌,將報數時數到M的猴子砍掉; // 申請猴子個數大小的數組,把桌子擺上。 Monkeys =(int *)malloc(sizeof(int)* MonkeyNum); if(NULL == Monkeys) { printf(“So many monkeys, system error.n”); return; } // 將數組的所有內容初始化為0,被砍掉的猴子設置為1 memset(Monkeys, 0, sizeof(int)*MonkeyNum); // 循環,直到選中大王 while(counter!= MonkeyNum) { // 如果這個位置的猴子之前沒有砍掉,那么報數有效 if(Monkeys[position] == 0) { token++;// 成功報數一個,令牌+1,繼續報數直到等于M // 如果報數到M,那么將這個猴子砍去 if(token == CallNum) { Monkeys[position] = 1;// 設置為1,表示砍去 counter++;// 計數增加 token = 0;// 設置為0,下次重新報數 // 如果是最后一個猴子,把它的位置打印,這個就是大王了 if(counter == MonkeyNum) { printf(“The king is the %d monkey.n”, position+1); } } } // 下一個猴子報數 position =(position + 1)%MonkeyNum; } // 釋放內存,開頭為所有猴子創建的桌子 free(Monkeys); return;} 題目2 :字符逆轉(學時:3) 從鍵盤讀入一個字符串,把它存入一個鏈表(每個結點存儲1個字符),并按相反的次序將字符串輸出到顯示屏。 #include struct node { struct node *prev; char c; struct node *next;};struct node *input(struct node *top);int main(void){ struct node T,*top=&T,*bottom=&T,*p=NULL;T.prev=NULL;T.next=NULL;T.c='
主站蜘蛛池模板:
夫妻免费无码v看片|
性欧美牲交xxxxx视频欧美|
亚洲av丰满熟妇在线播放|
国产av成人无码精品网站|
老司机午夜精品视频资源|
久久久久国产精品人妻电影|
久久精品国产亚洲av高清漫画|
狠狠综合亚洲综合亚洲色|
人人玩人人添人人澡欧美|
撩起胸让我的?蹭来蹭去|
一本久道综合色婷婷五月|
国产97视频人人做人人爱|
波多野结衣初尝黑人|
国产免费网站看v片在线无遮挡|
久久久久久精品成人鲁丝电影|
亚洲精品成人久久av|
亚洲精品一区二区久|
亚洲春色av无码专区最|
国内精品久久久久久99蜜桃|
天天躁日日躁狠狠躁超碰97|
欧洲av无码放荡人妇网站|
国产乡下三级全黄三级bd|
中文日产码2023天美|
日本一区二区三区高清无卡|
国产v综合v亚洲欧美久久|
国产电影一区二区三区|
国产成人高清精品免费软件|
少妇无码一区二区三区|
久人人爽人人爽人人片av|
欧美人与物videos另类xxxxx|
免费人成视频x8x8|
久久亚洲精品ab无码播放|
国产 字幕 制服 中文 在线|
亚洲色欲综合一区二区三区|
一二区成人影院电影网|
日韩人妻无码精品二专区|
亚洲av综合av国产av|
无码一区二区三区中文字幕|
国产精品日本亚洲欧美|
一道久久爱综合久久爱|
久久久噜噜噜久久中文福利|
第四篇:數據結構經典題目及c語言代碼總結