+ 1

C++ condition what we have to implement

If () Printf("hello"); else: Printf("world"); What we have to do in output so hello world comes

10th Nov 2021, 8:30 AM
Abhishek
Abhishek - avatar
14 ответов
+ 6
Given such `if...else` block employed, you can't. There's no way to define a condition that evaluates as true and false at the same time. It's just as it is impossible to define a condition that will direct the control flow to enter both the `if` and also the `else` block.
10th Nov 2021, 8:39 AM
Ipang
+ 5
abhishek bairwa 0% Progress of C++ course. What about to complete them?
10th Nov 2021, 9:41 AM
A͢J
A͢J - avatar
+ 4
Why are you use if else statement here 😊
10th Nov 2021, 8:35 AM
Sâñtôsh
Sâñtôsh - avatar
+ 4
abhishek bairwa The following code is just for a bit of fun, but achieves your objective #include <iostream> using namespace std; int main() { int statement = 10; for(int i=0; i<2; i++){ if (statement *i ==0){ cout << "hello "; } else { cout << "world "; } } return 0; }
10th Nov 2021, 9:07 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
abhishek bairwa Yes that's right but if you want to do like that then your question should be change. You have written extra else statement instead you can just do this: if(printf("hello ")) printf("world"); In your case if part never would be execute.
10th Nov 2021, 6:54 PM
A͢J
A͢J - avatar
+ 3
Vasiliy I think in Python too much 🤣😅
12th Nov 2021, 9:25 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Rik Wittkopp in Python it would look something like this ☺️: for i in range(2): print("Hello "if not i else"world!", end='')
12th Nov 2021, 9:58 AM
Solo
Solo - avatar
+ 2
Rik Wittkopp for fun, I have shortened your code ☺️: for(int i=0;i<2;)cout<<(!i++?"Hello ":"world! ");
12th Nov 2021, 9:00 AM
Solo
Solo - avatar
+ 2
Rik Wittkopp it is inconvenient to read it on a small screen ☺️ for i in 0,1:print("Hello "if not i else"world!", end='')
12th Nov 2021, 11:07 AM
Solo
Solo - avatar
+ 1
main() { if(!printf("hello ")) printf("hello"); else printf("world"); } Sir it is right
10th Nov 2021, 3:52 PM
Abhishek
Abhishek - avatar
+ 1
Vasiliy 🤣😅 Where's the fancy one-liner?
12th Nov 2021, 10:36 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
abhishek bairwa You can't print Hello World together in single if else statement, you need to use loop here.
10th Nov 2021, 3:15 PM
A͢J
A͢J - avatar
- 1
Sir in condition what we have to do so output comes hello world
10th Nov 2021, 11:43 AM
Abhishek
Abhishek - avatar
12th Nov 2021, 6:17 AM
✓`•°`™AnOnimus™`°•`✓ فايز الله‎
✓`•°`™AnOnimus™`°•`✓   فايز الله‎ - avatar