Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

ilahma / iax0583

  • This project
    • Loading...
  • Sign in
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 867530f8 authored 6 years ago by ilahma's avatar ilahma
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

Add new file

parent 7ec2d5d1
Hide whitespace changes
Inline Side-by-side
Showing with 114 additions and 0 deletions
  • Homework2/hW2_182430MVEB_ilaha_ahmadzada_
Homework2/hW2_182430MVEB_ilaha_ahmadzada_ 0 → 100644
View file @ 867530f8
/**
* 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];
float temp;
int n;
int i;
int j;
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]);
}
if(points[i]==0) // checks if there is any Disqualified one (means Points=0) or not
{
printf("Disqualified one(s): %s %.f \n", names[i],points[i]);
}
else
{
printf("Disqualified: none");
}
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 phtotographers 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;
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;
}
}
}
}
This diff is collapsed. Click to expand it.
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment