#include<stdio.h>
#include<stdlib.h>
typedef struct node
{int data;//牌的編號
int count;//記錄翻牌的次數
struct node *next;//指向下一個結點的指標
}LinkList;
LinkList *create(int k)//創建鏈表函式
{LinkList *head,*p,*q;
int i=0;
head=(LinkList*)malloc(sizeof(LinkList));//申請頭結點空間
p=head;//指標p指向頭結點
q=(LinkList *)malloc(sizeof(LinkList));//申請結點空間
while(i<k)
{q->data=https://bbs.csdn.net/topics/i+1;//給每個結點的data賦值
q->count=0;//給每個結點的count賦值
p->next=q;//q鏈接到p之后
p=q;//將q作為新的p
q=q->next;//q指標后移
q=(LinkList*)malloc(sizeof(LinkList));i++;}
p->next=NULL;//將最后一個結點的next域賦為空
return(head);}
LinkList *overcard(LinkList *head,int k)//翻牌函式
{LinkList *p;
for(int i=2;i<=k;i++)
{p=head->next;//p指向首元素結點?
while(p!=NULL)
{if((p->data)%i==0)//若牌的編號能被基數i整除,則使
p->count++;
p=p->next;}//p指標后移}
return(head);}
int result()//輸出結果函式
{Linklist *q;
q=head->next;//q指向首元素結點
printf("正面向上的牌編號為:");
while(q!=NULL)
{if((q->count)%2==0)//若翻過的次數為偶數則正面朝上,輸出
printf("%4d",q->data);
q=q->next;}
printf("\n");}
void main()
{char ch;
k=52;//共有52張牌
LinkList *head,*p;
printf("執行此程式(Y),不執行此程式(Q)\n");
scanf("%c",&ch);
while(1)
{if(ch=='Y')
{head=creat(k);
p=overcard(head,k);
result(p);}
else if(ch=='Q')
{printf("退出程式!\n");break;}
scanf("%c",&ch);}
}
--------------------Configuration: oo - Win32 Debug--------------------
Compiling...
oo.cpp
C:\Program Files (x86)\Visual C++\Bin\oo.cpp(35) : error C2601: 'result' : local function definitions are illegal
C:\Program Files (x86)\Visual C++\Bin\oo.cpp(45) : error C2601: 'main' : local function definitions are illegal
Error executing cl.exe.
oo.exe - 2 error(s), 0 warning(s)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/140614.html
標籤:基礎類
