+ 6

What's this code's output?

int a,c; a = 1 If (a==1) { Console.Writeline(a++) Else Console.Writeline(a--); } C=a+2; Console.WriteLine(c);

13th Nov 2023, 7:42 AM
Nesa Cheraghi
Nesa Cheraghi - avatar
17 Respostas
+ 9
See your problems 1> C# is a case sensitive. So, use `else` and `Console.WriteLine` instead of `Else` and `Console.Writeline` respectively and also `c` instead of `C`. 2>You are trying to insert an `else` statement inside an `if` statement which result in error. See this code:- https://code.sololearn.com/cnh7FGAO98Of/?ref=app
13th Nov 2023, 8:43 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 8
it will cause an error cuz you have put else statement inside if statement
13th Nov 2023, 8:06 AM
Alhaaz
Alhaaz - avatar
+ 7
Your this code will surely result in error.Your question is not clear Instead of writing code please send it's link
13th Nov 2023, 7:59 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 6
Nesa Cheraghi Can you send your code link here?
13th Nov 2023, 8:26 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 6
Nesa Cheraghi there is a Code section on Sololearn where you can test the output yourself. You may get the answer faster that way than waiting for the community to respond to a Q&A post. Also you'll discover syntax errors right away!
13th Nov 2023, 8:38 AM
Brian
Brian - avatar
+ 6
Adding to the problem list given by Koli, several statements are missing the semicolon ; at the end of the statement.
13th Nov 2023, 9:02 AM
Brian
Brian - avatar
+ 5
Brian oh yeah i see it! Thanksss😅
13th Nov 2023, 8:52 AM
Nesa Cheraghi
Nesa Cheraghi - avatar
+ 4
The output of that code will produce a bunch of errors until you correct it, and when corrected, the code will output 1 and 4.
13th Nov 2023, 8:15 AM
Jan
Jan - avatar
+ 2
Can one of you guys tell me where i have problem in the code? I'm beginner 🥲
13th Nov 2023, 8:38 AM
Nesa Cheraghi
Nesa Cheraghi - avatar
+ 2
Koli way to go❤️‍🔥 Thank u ^~^
13th Nov 2023, 8:50 AM
Nesa Cheraghi
Nesa Cheraghi - avatar
+ 1
This code has some errors. Your if statements are wack and the Console.WriteLine statements are obviously incorrect. C# is a case sensitive language, so the corrected code must be like this: int a, c; a = 1; if (a) { Console.WriteLine(a); a++; } else { Console.WriteLine(a); a--; } c = a += 2; Console.WriteLine(c);
14th Nov 2023, 1:59 AM
roadster
roadster - avatar
+ 1
Error
14th Nov 2023, 7:35 PM
-dgl
-dgl - avatar
+ 1
The Output of the code is 1 and 4
15th Nov 2023, 1:59 AM
Soma Swarna
Soma Swarna - avatar
+ 1
<h2> button </h2>
21st Nov 2023, 8:40 PM
Augustin Caré
Augustin Caré - avatar
0
Yeah, I got it what you wanted to do. First you have to correct your code by separating the else statement from if statement and then close both the Statements of if and else respectively in the curl brackets ,, After doing this ,you will get the output 4 I hope it helped you!!
13th Nov 2023, 4:37 PM
Sachin Sharma
Sachin Sharma - avatar
0
There are a couple of syntax errors in the provided code. Here's the corrected version: using System; class Program { static void Main() { int a, c; a = 1; if (a == 1) { Console.WriteLine(a++); } else { Console.WriteLine(a--); } c = a + 2; Console.WriteLine(c); } } Now, let's break down the code: a is initialized to 1. The if statement checks if a is equal to 1. Since it is, it executes the code inside the if block, printing the current value of a (1) and then incrementing it (a++). c is assigned the value of a + 2, where a is now 2. The final value of c (2 + 2) is printed. So, the output of this code will be: 1 4
13th Nov 2023, 5:30 PM
Delali Boateng Benjamin
0
M
13th Nov 2023, 5:30 PM
Augustin Caré
Augustin Caré - avatar