في هذا البرنامج يتم فيه ادخال اصوات المنتخبيين لبعض المرشحيين
البرنامج صحيح ولا يحتاج الى اي شي من التصحيح لكن المشكلة عند عملية run
بدخل اصوات للمرشحيين عادي لكن لايظهر كم عدد الاصوات لكل مرشحالمطلوب(اظهار مجموع الاصوات لكل مرشح ومين الفائز)
الرجاء المسسسسسسسسسسسسسسساعدة فورا علما بان البرنامج على تركيب بيانات في السي
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
struct Node
{
int info;
struct Node *next;
}
typedef struct Node *PTR;
PTR Getnode();
void AddEndList(PTR list ,int x);
PTR Formlist();
void PrintList(PTR list);
void PrintCounter (PTR list);
/******************************************/
int main(){
PTR list=NULL;
int x,i;
int n;
printf("how many nodes");
scanf("%d",&n);
printf("Enter x=");
scanf("%d",&x);
/*******************************************/
list=Getnode();
list->info=x;
list->next=NULL;
for ( i=1; i<n; ++i)
{
printf("Enter x=");
scanf("%d",&x);
AddEndList(list,x);
}
return (0);
}
/************************************************/
PTR Getnode()
{
PTR p=(PTR)malloc(sizeof(struct Node));
return(p);
}
/**************************************************/
void AddEndList(PTR list,int x)
{
PTR p=list;
while(p->next !=NULL)
p=p->next;
PTR q =Getnode();
q->info=x;
p->next=q;
q->next=NULL;
}
/********************************************************/
void PrintList(PTR list){
PTR p=list;
while (p!=NULL){
printf("%d->",p->info);
p=p-> next;
}
printf("NULL");
}
/******************************************************/
void PrintCounter (PTR list)
{
PTR p=list;
int i;
int Counter[7];
for( i=0;i<7; ++i)
Counter =0;
while (p!=NULL){
switch(p->info)
{
case 1:
Counter [0]++;
break;
case 2:
Counter [1]++;
break;
case 3:
Counter [2]++;
break;
case 4:
Counter [3]++;
break;
case 5:
Counter [4]++;
break;
case 6:
Counter [5]++;
break;
case 7:
Counter [6]++;
break;
default:
break;
}
p=p->next;
}
for(i=0;i<7;++i)
{
printf("\n \t%d=%d",i+1,Counter);
}
}