#10: Ternary Operator in C | C Programming for Beginners

  Рет қаралды 95,755

Programiz

Programiz

Күн бұрын

Пікірлер: 249
@programizstudios
@programizstudios 2 жыл бұрын
🔥Finding it Damn Hard to Understand C Programming? Learn to code-the right way-with interactive lessons, quizzes & challenges. Build a strong programming base; it's IMPORTANT! Try Programiz PRO for Free: bit.ly/master-c-programming
@AlaskarAbdoul
@AlaskarAbdoul Жыл бұрын
/* Can you create a program to check whether a number is odd or eve? > Use a ternary operator to check if the number is odd or even. > If number is odd, print "The number is Odd" > If number is even, print "The number is Even" */ #include int main() { int number; printf("Enter a number: "); scanf("%d", &number); // by using Ternary Operator (number % 2==0) ? printf("The number is Even") : printf("The number is Odd"); }
@eazyj_c
@eazyj_c 11 ай бұрын
thanks
@zonekenne5329
@zonekenne5329 9 ай бұрын
did you try doing this operation with the "double" data type? @@eazyj_c
@user-qq1ze2ml2q
@user-qq1ze2ml2q 7 ай бұрын
Thank You!
@varalakshmidevathi7997
@varalakshmidevathi7997 2 ай бұрын
Thanks
@hurulaynmuhamedsalimcedarp5770
@hurulaynmuhamedsalimcedarp5770 2 жыл бұрын
Programming Task: #include int main() { int number; printf("Enter a number: "); scanf("%d", &number); (number%2 == 0) ? printf("%d is an even number.", number) : printf("%d is an odd number.", number); return 0; }
@msreekanth8886
@msreekanth8886 4 ай бұрын
wtf
@joechen9498
@joechen9498 2 ай бұрын
#include int main() { int number; printf("Please enter the number:"); scanf("%d", &number); (number%2 == 0) ? printf("Number is an even number"): printf("Number is an odd number"); return 0; }
@michaelspencer6008
@michaelspencer6008 2 жыл бұрын
You did an excellent job explaining the switch statement. I was and am still amazed at how easy you made this so understandable. Please continue teaching us. You have an absolute gift in how you explain these concepts. Thank you sooo much!
@user-be1qh8iz5u
@user-be1qh8iz5u 5 ай бұрын
hey buddy! How much part of C have you completed to date?
@rhythmahmed1873
@rhythmahmed1873 2 жыл бұрын
//Can you create a program to check whether a number is odd or even? //***Use a ternary operator to check if the number is odd or even //***If the number is odd print the number is odd //***If the number is even print the number is even #include int main() { int number; printf("Enter a number: "); scanf("%d", &number); (number % 2==0) ? printf("The number is Even.") : printf("The number is Odd."); return 0; }
@nuetrkn
@nuetrkn Жыл бұрын
Thank you
@yasminehey3854
@yasminehey3854 Жыл бұрын
i did the same thing and it worked but later on i made the ternary as int result=(number % 2==0) ? printf("The number is Even.") : printf("The number is Odd."); but when i print the resut itdoes say in the output whether the number is odd or even but it always adds 13 or 14 i dont understand why there is the "14 or 13 "
@sanargasimov
@sanargasimov Жыл бұрын
@@yasminehey3854 The program then checks whether 'num' is even or odd using the modulus operator %, and uses the ternary operator to print a message indicating whether the number is even or odd. However, the use of 'printf' in the ternary operator is not recommended because it returns the number of characters printed, not the value of the condition. As a result, the value of result will be 23 or 19, depending on the message printed. A better approach would be to use a separate variable to store the message, and then print that variable and the value of result separately. Here's an updated version of the program: #include int main() { int num = 78; char* message = (num % 2 == 0) ? "Your number is EVEN" : "Your number is ODD"; printf("%s ", message); int result = (num % 2 == 0) ? 0 : 1; printf("%d ", result); return 0; } This program first declares a char* variable named message, and assigns it a string value based on whether num is even or odd. It then uses printf to print message and a newline character. Finally, it declares an int variable named result, and assigns it a value of 0 if num is even or 1 if num is odd. It then uses printf to print result and a newline character.
@sammuchina8189
@sammuchina8189 Жыл бұрын
in this part of your code, " (number % 2==0) ? printf("The number is Even.") : printf("The number is Odd."); " what does the % mean kindly🙏
@muhammadfukii1518
@muhammadfukii1518 Жыл бұрын
@@sammuchina8189 % is could be DEVISION or as per our concept REMAINDER
@SANJAYR-yy1zg
@SANJAYR-yy1zg 6 ай бұрын
Answer is option c Result=5>3 ? 5 : 3;
@rahulc.h2440
@rahulc.h2440 Жыл бұрын
for the quiz, it opts C coz in the if-else statement the if part is evaluated to be true and hence gives 5 so the same principle applies Ternary:- (CONDITION) ? Statement1(Executed when True) : Statement2(Executed when False)
@abdulazizhabib4441
@abdulazizhabib4441 7 ай бұрын
it is option c
@adityasharma3947
@adityasharma3947 11 ай бұрын
B as we have to print Result = 5 but in C the value of just 5 is will be as output
@batmanelhakeky
@batmanelhakeky 11 ай бұрын
Your tutorials are so helpful. i learnt switch statement and im now learning tenrary operator. keep the great work up!
@shohanurrahmanshoron1804
@shohanurrahmanshoron1804 2 жыл бұрын
I tried this in front of my teacher and even he doesn't know about this operator. Thank U❤️❤️❤️
@shankaradari4741
@shankaradari4741 Жыл бұрын
Really useful content I really want to thank the teachers who are making the classes
@sundeepchowdaryattaluri8797
@sundeepchowdaryattaluri8797 2 жыл бұрын
Thanks for providing this useful and & well content for us.... Code #include int main() { int a; scanf("%d", &a); (a %2 ==0) ? printf("%d is even", a): printf("%d is odd", a); } Ans for Question is C.
@benchmarkslab2005
@benchmarkslab2005 2 жыл бұрын
One thing I can't understand bro. Why we used %d is even and %d is odd. If I used without %d it isn't working. But they didn't use %d in age calculator. Plzz explain bro
@rakesh1045
@rakesh1045 Жыл бұрын
#include int main(); { Int number=2; (number % 2 == 0) ? Printf("the number is even") : printf("the number is odd"); return 0 ; }
@Judyy.Sabryy
@Judyy.Sabryy 10 ай бұрын
Love it, explantion was clear and straightforward, however, I suggest you also talk about how to implement nested Ternary operators.
@annettewairimu5542
@annettewairimu5542 5 ай бұрын
how are you doing after 5 months in programming?
@mdsahil2203
@mdsahil2203 2 жыл бұрын
Thanks for providing " Good quality "content By the way answer is option C
@shreyasy9164
@shreyasy9164 2 жыл бұрын
why c
@shreyasy9164
@shreyasy9164 2 жыл бұрын
i think option B is corrrect
@mandip863
@mandip863 2 жыл бұрын
@@shreyasy9164 yes boss b is ans
@dhanushs1802
@dhanushs1802 2 жыл бұрын
@@shreyasy9164 in the option B, if you change 5>3 to 3>5 , result will be 0 instead the result should be 3. So C is the answer.
@monalisabanra2733
@monalisabanra2733 Жыл бұрын
b can also be the answer i checked it
@qarikhalidwaheed1643
@qarikhalidwaheed1643 Жыл бұрын
Thanks for explaining this code simply
@user-nt4nm4fb3u
@user-nt4nm4fb3u 7 ай бұрын
Great explanation as always! Thank you for everyone to make this happen.
@annettewairimu5542
@annettewairimu5542 5 ай бұрын
how are you doing after two months?
@sunangashilpakar3672
@sunangashilpakar3672 2 жыл бұрын
Thankyou for explaining it so simply.. was waiting for your video ❤️
@annettewairimu5542
@annettewairimu5542 5 ай бұрын
how are you doing after two years in programming?
@kankarlabharath6819
@kankarlabharath6819 2 жыл бұрын
Mam your explanation is very good and nice, can you make a tutorial videos on Data structures and algorithms in good explanation based on c language.
@pristinewalek4578
@pristinewalek4578 2 жыл бұрын
Beautiful 🤩 Thank you for explaining it so well
@Ech-chatouiMohammed
@Ech-chatouiMohammed 3 күн бұрын
VERY GREAT CONTENT
@Darkness-898
@Darkness-898 3 ай бұрын
PROGRAMMING TASK: #include int main() { int num; printf("Enter number here: "); scanf("%d", &num); (num%2==0)?printf("The number is even."):printf("The number is odd."); return 0; } PROGRAMIZ QUIZ ANSWER: Option(B) 5>3?5:3;
@laxmanpeddi9714
@laxmanpeddi9714 2 жыл бұрын
(option c)...........cool and clear content by progrmizzzz.....plz keep going......
@shreyasy9164
@shreyasy9164 2 жыл бұрын
why c??????
@pretty_you2243
@pretty_you2243 Жыл бұрын
@@shreyasy9164 5>3? Is a condition. After evaluating the condition, value will be assigned to result variable as either 5 or 3.
@alirezaz9896
@alirezaz9896 2 жыл бұрын
the best C language tutorial👌👌👌
@qarikhalidwaheed1643
@qarikhalidwaheed1643 Жыл бұрын
It's going super good because of you explaining💞💕
@light-warrior
@light-warrior 7 ай бұрын
The programming task: #include int main () { int number; printf("Enter a number: "); scanf("%d ", &number); (number % 2 == 0) ? printf("It is an even number ") : printf("It is an odd number "); return 0; } and B is the correct answer.
@rubakvanitha8164
@rubakvanitha8164 11 ай бұрын
Thank you for your happy programming for us🎉
@eliskaellagalikova3251
@eliskaellagalikova3251 Жыл бұрын
I am going to write a test about this tomorrow🙄but I finally understant🥳
@amayaamarasinghe5838
@amayaamarasinghe5838 Жыл бұрын
Thank you! The explanation is so useful!!!
@venkatasumanth3027
@venkatasumanth3027 2 жыл бұрын
ur way of teaching is exlent.....
@ahmed_fsi
@ahmed_fsi 2 жыл бұрын
Thank you! I didn't think it would be that easy to learn.
@sayalikhairnar3211
@sayalikhairnar3211 2 жыл бұрын
The great teacher of c programing
@unruly_ronin
@unruly_ronin 11 ай бұрын
Subscribed coz you guys are brilliant and have a great presentation style Edit: Answer is C
@qarikhalidwaheed1643
@qarikhalidwaheed1643 Жыл бұрын
❤❤❤thank you for explaining it so easily❤❤❤
@benjaminhuka7434
@benjaminhuka7434 2 жыл бұрын
wonderful explaination, thank you!
@ludowithsanjay
@ludowithsanjay 2 жыл бұрын
Thank you🙏 mam. Your teaching quality is awesome👏
@kam-sc9gs
@kam-sc9gs 8 ай бұрын
Ma'am thank you so much, I really appreciate ur work, and it really help me so much❤
@yunandaraung2556
@yunandaraung2556 Жыл бұрын
Thank you so much for such wonderful explanation!
@annettewairimu5542
@annettewairimu5542 5 ай бұрын
how are you doing after 1 year in programming?
@nihatdonmzov4166
@nihatdonmzov4166 Жыл бұрын
Great video. Thank you so much
@seabasschukwu6988
@seabasschukwu6988 Жыл бұрын
GREAT EXPLANATION!
@fountain9886
@fountain9886 Жыл бұрын
#include int main (){ int num ; printf("Enter a number :"); scanf("%d", &num); if ( num % 2 == 0){ printf("The number is even."); } else if (num % 2 != 0){ printf("The number is odd."); } return 0; } it is coded in the common style.
@clarencelucius9085
@clarencelucius9085 7 ай бұрын
excellent teacher
@williamowusu7778
@williamowusu7778 Жыл бұрын
Thanks 👍
@miarose5382
@miarose5382 2 жыл бұрын
was waiting for you mam ... please upload the next video soon
@Sickpisspakh23971
@Sickpisspakh23971 Жыл бұрын
Thank you, padma ❤
@mahoney_tech
@mahoney_tech Жыл бұрын
#include int main () { int number = 10; (number % 2 == 0) ? printf("this is even number "): printf("This is odd number"); return 0; }
@bhavanasai6981
@bhavanasai6981 Ай бұрын
#include int main() { int num; printf("Enter Num:"); scanf("%d", &num); (num % 2 == 0) ? printf("Number is even") : printf("Number is odd"); return 0; }
@spoilermedia-h6i
@spoilermedia-h6i 6 ай бұрын
#include int main() { double num1=1; double num2=3,result; result=1+3; printf("enter the number: "); scanf("%d", &result); (result>=4)? printf("the number is even"):printf("the numer is odd"); return 0; }
@balashebjadhav977
@balashebjadhav977 Жыл бұрын
The answer is option C)
@mojo7281
@mojo7281 5 ай бұрын
Programming Task: #include #include int main() { int number; printf("Enter Number: "); scanf("%d", &number); (number % 2==0) ? printf("EVEN #") : printf("ODD #"); return 0; }
@uppilipavitra9634
@uppilipavitra9634 3 ай бұрын
#include int main(){ int a=0; (a%2==0)?printf("the number is even"):printf("the number is odd"); return 0 ; }
@countrysideshowyaigrock4689
@countrysideshowyaigrock4689 Жыл бұрын
Thank you very much!!
@srikanthkotaru515
@srikanthkotaru515 Жыл бұрын
// Online C compiler to run C program online #include int main() { // Write C code here int number = 11; int result = (number % 2 == 0) ? printf("it is even") : printf("it is odd"); return 0; }
@ndikevinetawe8751
@ndikevinetawe8751 4 ай бұрын
C is the answer
@naveenperspective
@naveenperspective 7 ай бұрын
Option c
@gogulram2551
@gogulram2551 2 жыл бұрын
program is #include int main() { int num; printf("enter the number: "); scanf("%d", &num); (num % 2 == 0) ? printf("number is even") : printf("number is odd"); return 0; }
@JoeMama-zc8ub
@JoeMama-zc8ub 2 жыл бұрын
The real MVP
@buddharatnamanandhar3837
@buddharatnamanandhar3837 2 жыл бұрын
its going good !!
@fountain9886
@fountain9886 Жыл бұрын
#include int main () { int num ; printf("Enter your Number :"); scanf("%d", &num); (num%2==0)? printf("Number is Even") : printf("Number is Odd"); return 0; }
@David_Chijioke
@David_Chijioke 3 ай бұрын
thanks a lot
@user-uj8ss9dp7l
@user-uj8ss9dp7l 3 ай бұрын
Love it❤
@haydenawc7189
@haydenawc7189 7 ай бұрын
i’m learning sm
@abercharity8023
@abercharity8023 Жыл бұрын
// Online C compiler to run C program online #include int main() { int num =25; (num%2)? printf("The numberis odd") : printf("The number is even"); return 0;
@MagaScampini
@MagaScampini 5 ай бұрын
I think the answer is B. Because the condition in the if...Else statement is if (5 > 3) instead of if the result = (5 > 3); for in that case the right answer would be C. Can anyone confirm?
@onic9623
@onic9623 Жыл бұрын
Option C : result = 5> 3 ? 5 : 3; ----------------------------------------------------------- #include int main() { int num; printf("Enter A Number: "); scanf("%d", &num); (num % 2 == 0) ? printf("Even") : printf("Odd"); return 0; }
@bekmirzo9259
@bekmirzo9259 4 ай бұрын
6:20 the answer is C
@avdeshsingh001
@avdeshsingh001 Жыл бұрын
Thanks ma'am
@aaronbenjamin3143
@aaronbenjamin3143 2 жыл бұрын
I have a question can I? create a program to integrate into a program like array and basic computer calculator etc. I hope you can answer thank you
@based1712
@based1712 Жыл бұрын
The answer is option B.
@KarthickShoko
@KarthickShoko 2 ай бұрын
Option B
@ebubeanieke2072
@ebubeanieke2072 8 ай бұрын
C is the right answer
@christlike8712
@christlike8712 Жыл бұрын
#include int main() { int num = 4; (num%2==0)? printf("This is an even number"): printf("This is an odd number"); return 0; }
@subhajitNath0
@subhajitNath0 2 жыл бұрын
good quality 😊
@zonekenne5329
@zonekenne5329 9 ай бұрын
why do I get an error when I try to do the operation with a "double" data type. I expected the integer to be converted to double since the double is greater than the int in the ranking
@AFCOE
@AFCOE Жыл бұрын
Hello madam. Mind is displaying "number is even" when I haven't insert anything. int number; (number%2==0)? printf("number is even"): printf("number is odd");
@ejoshtech5358
@ejoshtech5358 2 жыл бұрын
How is the flow chart drawn? But is this advisable to use in an exam
@gayathri0301
@gayathri0301 3 ай бұрын
C option for quiz mam
@raakshas5547
@raakshas5547 2 жыл бұрын
Mam, aapke liye chand taare tod ke laa sakta hoo.......coding challenge to keya chiz hai ? Ye lo answer.... #include #include int main() { int num; printf("Enter the age "); scanf("%d",&num); (num%2==0)?printf("The number is even"):printf("The number is odd"); return 0; } Aapka 2nd question ka answer hai option B.
@sara-cq8ev
@sara-cq8ev Жыл бұрын
// Online C compiler to run C program online #include int main() { int number; printf("enter your number "); scanf("%d",&number); (number %2==0)? printf("num is even") : printf("nub is odd"); return 0; }
@issabello.
@issabello. Жыл бұрын
love it
@RiyaShorts18
@RiyaShorts18 Жыл бұрын
Correct ans is B
@jerseyclubbydn153
@jerseyclubbydn153 Жыл бұрын
#include int main() { int number = 21; (number%2==0) ? printf("Even ") :printf("Odd"); return 0; }
@ogunlalusarah1138
@ogunlalusarah1138 Жыл бұрын
good work
@MercylineNyaboke-b9x
@MercylineNyaboke-b9x 10 ай бұрын
Nice❤❤❤
@behailus-tube5024
@behailus-tube5024 5 ай бұрын
programming task int number; printf("Enter a number: "); scanf("%d", &number); int resulte = (number%2 == 0) ? printf(" an even number") : printf(" an odd number");
@ebbahinnocent2930
@ebbahinnocent2930 3 ай бұрын
I choose B
@MeesalaSrilatha-bk2ps
@MeesalaSrilatha-bk2ps 2 ай бұрын
OptB
@Mvrck44
@Mvrck44 21 күн бұрын
Quizz answer: C
@xclusiveo.jstudio5359
@xclusiveo.jstudio5359 Жыл бұрын
#include int main(){ int x= 358; (x % 2 == 0) ? printf("the number is even") : printf("the number is odd"); return 0; }
@qarikhalidwaheed1643
@qarikhalidwaheed1643 Жыл бұрын
Here's my code #include int main() { int num; int ans; printf("Enter Number: "); scanf("%d", &num); ans = num % 2; if (ans == 1) { printf("Number is Odd"); } else { printf("Number is even"); } return 0; }
@salmanmugharbel
@salmanmugharbel 10 ай бұрын
good
@jagavardhan576
@jagavardhan576 5 ай бұрын
Answer for the que?
@seabasschukwu6988
@seabasschukwu6988 Жыл бұрын
the correcr answer is C
@ravikiranhs8464
@ravikiranhs8464 Ай бұрын
It just shows error in char line
@mawadasalem5439
@mawadasalem5439 5 ай бұрын
Answer is :b
@Girma_Chew
@Girma_Chew 2 жыл бұрын
I hope this will be the correct answer, I have tried it on online compiler provided by Programiz. /*This is a program to check whether a number is EVEN or ODD by enquiring an input from a user.*/ #include int main(){ int number; printf("Enter any number! "); scanf("%d", &number); (number%2==0) ? printf("The number %d is Even.",number) : printf("The number %d is Odd.",number); return 0; } //Thank U for helping us.
@shaikabuzar3495
@shaikabuzar3495 2 ай бұрын
answer is c
@sawewfelipe7480
@sawewfelipe7480 3 ай бұрын
answer i s C
@sayun8848
@sayun8848 Жыл бұрын
Answer is C
@AniquaIbnatMir-e3b
@AniquaIbnatMir-e3b Ай бұрын
The answer is Option (C). result = 5 > 3 ? 5 : 3;
@phaneendravr900
@phaneendravr900 23 күн бұрын
how? Please tell me a code
#11: Switch Statement in C | C Programming for Beginners
11:10
Programiz
Рет қаралды 146 М.
#9: If Else Statements in C | C Programming for Beginners
12:51
Programiz
Рет қаралды 181 М.
Throwing Swords From My Blue Cybertruck
00:32
Mini Katana
Рет қаралды 11 МЛН
At the end of the video, deadpool did this #harleyquinn #deadpool3 #wolverin #shorts
00:15
Anastasyia Prichinina. Actress. Cosplayer.
Рет қаралды 17 МЛН
Violet Beauregarde Doll🫐
00:58
PIRANKA
Рет қаралды 52 МЛН
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 393 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,2 МЛН
what even is a "reference"?
5:44
Low Level Learning
Рет қаралды 130 М.
#8: Boolean and Comparison Operators in C Programming
14:41
Programiz
Рет қаралды 119 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
#15  C Functions | C Programming for Beginners
17:21
Programiz
Рет қаралды 206 М.
Throwing Swords From My Blue Cybertruck
00:32
Mini Katana
Рет қаралды 11 МЛН