0

for loop

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int i, j; for( i= 1; i<=4; i++){ for( j = 1; j<=4; j++){ if(i==j){ Console.WriteLine("1 "); } else{ Console.WriteLine("0 "); } Console.WriteLine("\n"); } } } } } // how do I get to display 1000 0100

11th Aug 2022, 12:15 AM
Microne mafika
Microne mafika - avatar
1 Answer
+ 1
Microne mafika for( i= 1; i<=2; i++){ for( j = 1; j<=4; j++){ if(i==j){ Console.Write("1"); } else{ Console.Write("0"); } } Console.Write(" "); } use Console.Write() instead of Console.WriteLine() and you wanted a space between the first 4 (1000) to the second 4 (0100) which you put a line break. You also had 4 on the outer for loop which should have been 2. And one more correction in your code you missed a curl bracket https://code.sololearn.com/cz1VB4Pd1FAm/?ref=app
11th Aug 2022, 12:26 AM
BroFar
BroFar - avatar