Skip to content

Commit

Permalink
conditional_operator
Browse files Browse the repository at this point in the history
Answers of conditional operator programming exercises.
  • Loading branch information
bcalagoz committed Sep 22, 2022
1 parent 15b4503 commit 6e8fef9
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified codeforwin_c_exercises/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Write a C program to input two numbers and find
maximum between two numbers using conditional/ternary
operator ?:. How to find maximum or minimum between two numbers
using conditional operator in C program.
*/

#include<stdio.h>

int main(){

float x , y ;

printf("Enter two numbers:");
scanf("%f %f",&x,&y);

x>y ? printf("Maximum= %.2f",x) : printf("Maximum= %.2f",y);

return 0;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Write a C program to input three numbers from user
and find maximum between three numbers using conditional/ternary
operator ?:. How to find maximum between three numbers using conditional operator.
*/

#include<stdio.h>

int main(){

int x , y , z;

printf("Enter three number:");
scanf("%d %d %d",&x,&y,&z);

(x>=y && x>=z) ? printf("Maximum = %d",x) : (y>=z) ? printf("Max:%d",y) : printf("Max:%d",z);

return 0;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Write a C program to input a number and check whether
number is even or odd using Conditional/Ternary operator ?:.
How to check even or odd numbers using conditional operator in C program.
*/

#include<stdio.h>

int main(){

int num;

printf("Enter a number:");
scanf("%d",&num);

(num % 2 == 0) ? printf("%d is an EVEN number.\n",num) : printf("%d is an ODD number.\n",num);


return 0;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Write a C program to input a year and check whether
year is leap year or not using conditional/ternary operator ?:.
How to check leap year using conditional operator in C programming.
*/

#include<stdio.h>

int main(){

int year;

printf("Enter a year:");
scanf("%d",&year);

(year % 4 == 0 && year % 100 != 0)? printf("LEAP Year") : (year % 400 == 0) ? printf("LEAP Year") : printf("COMMON Year");

return 0;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Write a C program to input a character and check whether the
character is alphabet or not using Conditional/Ternary operator ?:.
How to check alphabets using conditional operator in C programming.
*/

#include<stdio.h>

int main(){

char x;

printf("Enter any character:");
scanf("%c",&x);

(x>='a'&& x<='z') || (x>='A'&& x<='Z')
? puts("ALPHABET")
: puts("not ALPHABET");

return 0;
}

0 comments on commit 6e8fef9

Please sign in to comment.