-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Answers of conditional operator programming exercises.
- Loading branch information
Showing
12 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+48.3 KB
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise1/exercise1
Binary file not shown.
20 changes: 20 additions & 0 deletions
20
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise1/exercise1.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+48.3 KB
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise2/exercise2
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise2/exercise2.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+48.3 KB
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise3/exercise3
Binary file not shown.
20 changes: 20 additions & 0 deletions
20
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise3/exercise3.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+48.3 KB
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise4/exercise4
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise4/exercise4.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+48.4 KB
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise5/exercise5
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
codeforwin_c_exercises/conditional_operator_programmin_exercises/exercise5/exercise5.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |