Q1: Solving a problem using Ternary Operator in C programming.
Q: Admission to a professional course is subject to the following conditions:
(a) Marks in Mathematics >= 60
(b) Marks in Physics >= 50
(c) Marks in Chemistry >= 40
(d)Total in three subjects >= 200
or
(e) Total in Mathematics and Physics >= 150
Given the marks in the three subjects, write a program to process the applications to list the eligible candidates and also declaring the reason for which the candidate were not selected.
Answer:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
int main()
{
int mat,phy,chm,total3,total2;
printf("Enter the marks : \n");
scanf("%d%d%d",&mat,&phy,&chm);
total3 = mat + chm + phy;
//summation of three marks//
total2 = mat + phy;
((mat>=60 && phy>=50 && chm>=40 && total3 >=200))||((total2>=150))?(printf("He's Selected.\n")):
((mat<60)?(printf("He's failed in Math!")):((phy<50)?(printf("He's failed in Physics!")):
((chm<40)?(printf("He's failed in Chemistry!")):(printf("")))));
return 0;
}
Comments
Post a Comment