עזרה בכתיבת תוכנית ב סי - עמוד 2 - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

עזרה בכתיבת תוכנית ב סי


sese

Recommended Posts

הנה:



#include <stdio.h>
#define MAXLEN 20
#define SIZE 3

typedef struct team
{
char name[20];
int scores;
int points;
}TEAM;

void main()
{
TEAM t[SIZE], tmp;
int i, j;
int a, b;

for(i=0;i<SIZE;i++)
{
printf("Insert Name For Team %d: ", i+1);
scanf("%s", t[i].name);
t[i].points=0;
t[i].scores=0;
}

for(i=0;i<SIZE;i++)
{
for(j=i+1;j<SIZE;j++)
{
printf("Game %s vs %s: ", t[i].name, t[j].name);
scanf("%d%d", &a, &b);
t[i].scores+=a;
t[j].scores+=b;
if(a==b)
{
t[i].points++;
t[j].points++;
}
else if(a>b)
t[i].points+=3;
else
t[j].points+=3;

}
}

for(i=0;i<SIZE;i++)
{
for(j=i+1;j<SIZE;j++)
{
if(t[j].points>t[i].points)
{
tmp=t[i];
t[i]=t[j];
t[j]=tmp;
}
}
}

printf("Team\tPoints\n");
for(i=0;i<SIZE;i++)
printf("%s\t%d\n", t[i].name, t[i].points);

for(j=0, i=1;i<SIZE;i++)
if(t[i].scores>t[j].scores)
j=i;
printf("\n\nTeams With Max Scores: \n");
for(i=0;i<SIZE;i++)
if(t[i].scores==t[j].scores)
printf("%s\n", t[j].name);
}

קישור לתוכן
שתף באתרים אחרים

הנה:


#include <stdio.h>
#include <string.h>
#define MAXLEN 20
#define SIZE 3


void main()
{
char name[SIZE][MAXLEN], tmp[MAXLEN];
int scores[SIZE];
int points[SIZE];
int i, j;
int a, b;

for(i=0;i<SIZE;i++)
{
printf("Insert Name For Team %d: ", i+1);
scanf("%s", name[i]);
points[i]=0;
scores[i]=0;
}

for(i=0;i<SIZE;i++)
{
for(j=i+1;j<SIZE;j++)
{
printf("Game %s vs %s: ", name[i], name[j]);
scanf("%d%d", &a, &b);
scores[i]+=a;
scores[j]+=b;
if(a==b)
{
points[i]++;
points[j]++;
}
else if(a>b)
points[i]+=3;
else
points[j]+=3;

}
}

for(i=0;i<SIZE;i++)
{
for(j=i+1;j<SIZE;j++)
{
if(points[j]>points[i])
{
strcpy(tmp, name[i]);
strcpy(name[i], name[j]);
strcpy(name[j], tmp);
a=points[i];
points[i]=points[j];
points[j]=a;
a=scores[i];
scores[i]=scores[j];
scores[j]=a;
}
}
}

printf("Team\tPoints\n");
for(i=0;i<SIZE;i++)
printf("%s\t%d\t%d\n", name[i], points[i], scores[i]);

for(j=0, i=1;i<SIZE;i++)
if(scores[i]>scores[j])
j=i;
printf("\n\nTeams With Max Scores: \n");
for(i=0;i<SIZE;i++)
if(scores[i]==scores[j])
printf("%s\n", name[i]);
}

עוד משהו?

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...