• +1-617-874-1011 (US)
  • +44-117-230-1145 (UK)
Online Customer Service
Follow Us:

Conditional Operator

Syntax:

Expression 1 ? Expression 2 : Expression 3

Meaning:

If the Expression 1 is true then the value returned will be given by Expression 2 otherwise it will be given by Expression 3

Example of Else – If:

#include <stdio.h>
#include <conio.h>
void main()
{
int result;
printf(“Enter your marks: ”);
scanf(“%d”,&result);

if (result >= 75)
printf("Passed: Grade A\n");
else if (result >= 60)
printf("Passed: Grade B\n");
else if (result >= 45)
printf("Passed: Grade C\n");
else
printf("Failed\n");

return;
}

Conditional Operator Homework Help

Example of Conditional Operator:

To find the maximum of a and b:

#include <stdio.h>
#include <conio.h>
int main()
{
int a,b,max;
printf(“Enter a and b: ”);
scanf(“%d %d”,&a,&b);

max = (a>b) ? a : b;
printf(“Maximum is %d”,max);

return;
}

Here the statement,

max = (a>b) ? a : b;
means,
if (a>b)
max = a;
else
max = b;

Topics in C Programming

PLACE ORDER NOW

Resources

  • 24 x 7 Availability.
  • Trained and Certified Experts.
  • Deadline Guaranteed.
  • Plagiarism Free.
  • Privacy Guaranteed.
  • Free download.
  • Online help for all project.
  • Need Assignment Help

Testimonial

Urgenthomework helped me with finance homework problems and taught math portion of my course as well. Initially, I used a tutor that taught me math course I felt that as if I was not getting the help I needed. With the help of Urgenthomework, I got precisely where I was weak:
Read More

Tap to Chat
Get Instant Assignment Help
Tap to Chat
Get Instant Assignment Help