+ 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);
13 Antworten
+ 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!
+ 6
Adding to the problem list given by Koli, several statements are missing the semicolon ; at the end of the statement.
+ 5
Brian oh yeah i see it! Thanksss😅
+ 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.
+ 2
Can one of you guys tell me where i have problem in the code? I'm beginner 🥲
+ 2
Koli way to go❤️🔥 Thank u ^~^
+ 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);
+ 1
Error
+ 1
The Output of the code is 1 and 4
+ 1
<h2> button </h2>
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!!
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
0
M