c# how to get this sample output using for loop for diagonal. please help soon | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

c# how to get this sample output using for loop for diagonal. please help soon

Write a C# program that will input an integer, in the range of 2 to 9 from the user. Using a loop, check that a valid number within the desired range was entered. Display appropriate error messages as shown below: Enter a value from 2 to 9:beef you have entered an invalid value. Enter a value from 2 to 9:1 you have entered an invalid value. Enter a value from 2 to 9:10 you have entered an invalid value. Enter a value from 2 to 9:4 1 2 3 4

4th Nov 2020, 2:05 AM
ramandeep kaur
1 Answer
+ 4
Your questions is not too complicated, try to understand by analyzing below code. You need a condition to analyze whether input is valid or not, if input is valid than you have to create a for loop to print from 1 to input number. int userinput=Convert.ToInt32(Console.ReadLine()); String str=""; if(userinput >= 2 && userinput <=9){ for(int i=1;i<=9;i++){ str+=" "; Console.WriteLine(str+i); if(i==userinput) break; } }
4th Nov 2020, 12:53 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar