+ 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
14 Answers
+ 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.
+ 5
abhishek bairwa
0% Progress of C++ course.
What about to complete them?
+ 4
Why are you use if else statement here 😊
+ 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;
}
+ 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.
+ 3
Rik Wittkopp in Python it would look something like this ☺️:
for i in range(2):
print("Hello "if not i else"world!", end='')
+ 2
Rik Wittkopp for fun, I have shortened your code ☺️:
for(int i=0;i<2;)cout<<(!i++?"Hello ":"world! ");
+ 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='')
+ 1
main() {
if(!printf("hello "))
printf("hello");
else
printf("world");
}
Sir it is right
+ 1
Vasiliy 🤣😅
Where's the fancy one-liner?
0
abhishek bairwa
You can't print Hello World together in single if else statement, you need to use loop here.
- 1
Sir in condition what we have to do so output comes hello world