Wednesday 9 March 2016

A Task


A task is given to 3 persons to complete it within a particular time. If the person exceeds the time limit he will be disqualified. Only those who complete it within the given time limit is qualified. Among the qualified persons, the person who completes the task first will be rewarded.

Write a program to find the person who is rewarded.

Input Format: 
First input corresponds to the Time limit for the task in hours. Second,Third and Fourth Inputs correspond to the number of hours Taken by the first , second and third persons respectively to complete the task. 

Output Format: 
Display the person who Completes first. 
[All text in bold corresponds to input and the rest corresponds to output] 

Sample Input and Output 1: 
Enter the Time Limit:
10
Enter the time taken by the first person:
5
Enter the time taken by the second person:
6
Enter the time taken by the third person:
4
Third person wins!!!

Sample Input and Output 2: 
Enter the Time Limit:
5
Enter the time taken by the first person:
3
Enter the time taken by the second person:
6
Enter the time taken by the third person:
4
First person wins!!!

Sample Input and Output 3: 
Enter the Time Limit:
4
Enter the time taken by the first person:
9
Enter the time taken by the second person:
6
Enter the time taken by the third person:
7
No person wins:-(

Code:
  #include<stdio.h>
int main()
{
  int time,t[3];
  printf("Enter the Time Limit:\n");
  scanf("%d",&time);
  printf("Enter the time taken by the first person:\n");
  scanf("%d",&t[0]);
  printf("Enter the time taken by the second person:\n");
  scanf("%d",&t[1]);
  printf("Enter the time taken by the third person:\n");
  scanf("%d",&t[2]);
 
    if((t[0]<t[1])&&(t[0]<t[2]))
    {
      if(t[0]<time)
        printf("First person wins!!!");
      else
        printf("No person wins:-(");
    }
    else if((t[1]<t[0]))
    {
      if (t[1]<time)
      printf("Second person wins!!!");
      else
        printf("No person wins:-(");
    }
    else 
      if(t[2]<time)
      {
      printf("Third person wins!!!");
      }
  else
    printf("No person wins:-(");
  return 0;
}

No comments:

Post a Comment