Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ilahma
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a1826c0b
authored
Dec 03, 2018
by
ilahma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
429e7b48
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
0 deletions
Homework2/hww2.c
Homework2/hww2.c
0 → 100644
View file @
a1826c0b
/**
* 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
]);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment