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
1 Antwort
+ 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;
}
}