hww2.c
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Author: Ilaha Ahmadzada
* Created: 24.11.2018
*
*/
#include <stdio.h>
#include <string.h>
//function prototypes
void readdata(char name[15][15],float points[15], int n);
void printdata(char name[15][15],float points[15], int n);
void comparedata(char name[15][15],float points[15],int n);
int main ()
{
char names[15][15];
float points[15];
int n;
int i;
char temp[15][15];
printf("Please enter the number of competitors ( The value should be less than 15)\n");
scanf("%d",&n);
while(n<1 || n>15) //checks if the entered value of n is between 1 and 15
{
printf("PLEASE ADD NUMBER BETWEEN 1 AND 15\n\n");
scanf("%d",&n);
}
readdata(names,points,n);
printdata(names,points,n);
comparedata(names,points,n);
printf("Top 3:\n"); // displays Top 3 competitors
for(i=0;i<3;i++)
{
printf("No%d: %s %.2f\n",i+1, names[i],points[i]);
}
int j=0;
for(i=0; i<n; i++)
{
if(points[i]==0)
{
strcpy(temp[j] ,names[i]);
j++;
}
}
if(j==0)
{
printf("Disqualified one: none\n");
}
else
{
for(i=0; i<j; i++)
{
printf("Disqualified one: %s\n", temp[i]);
}
}
return 0;
}
/**
* Function to get values for Names and Points with user input.
* User will enter names and points of competitors by order.
*
*/
void readdata(char name[15][15],float points[15],int n)
{
int i;
for(i=0; i<n;i++)
{
scanf("%s%f", name[i],&points[i]);
}
}
/**
* Function to display the values for Names and
* Points which is declared by user input with in function.
* Function will print out names and points of the phtotographer
* s respectively.
*
*/
void printdata(char name[15][15],float points[15],int n)
{
int i;
for(i=0; i<n;i++)
{
printf("%s\t", name[i]);
printf("%.2f\n", points[i]);
}
}
/**
* Function to sort all competitors by decreasing order
*/
void comparedata(char name[15][15],float points[15],int n)
{
int i;
int j;
float temp;
char t[15][15];
for(i=0; i<n;i++)
{
for (j = 0; j < (n - i - 1); j++)
{
if (points[j] < points[j + 1])
{
temp = points[j];
points[j] = points[j + 1];
points[j + 1] = temp;
strcpy(t[15], name[j]);
strcpy(name[j], name[j+1]);
strcpy(name[j+1], t[15]);
}
}
}
}