0% found this document useful (0 votes)
32 views

Write A Program Using A Loop That Prints The Following Output. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 - . - NTH Iteration

The document contains 5 programming problems: 1. Write a program to print increasing sequences of numbers from 1 to nth iteration. 2. Write a program that takes n values from the user and sorts them in ascending order. 3. Write a guessing game that allows the user to guess a secret number and tells them if their guess is too high or too low, printing the number of tries at the end. 4. Write a program to calculate the factorial of a given number. 5. No details are provided for the 5th problem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Write A Program Using A Loop That Prints The Following Output. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 - . - NTH Iteration

The document contains 5 programming problems: 1. Write a program to print increasing sequences of numbers from 1 to nth iteration. 2. Write a program that takes n values from the user and sorts them in ascending order. 3. Write a guessing game that allows the user to guess a secret number and tells them if their guess is too high or too low, printing the number of tries at the end. 4. Write a program to calculate the factorial of a given number. 5. No details are provided for the 5th problem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Write a program using a loop that prints the following output.

1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 . . . nth iteration.

using System;

Console.WriteLine("\n");

using System.Collections.Generic;
using System.Linq;

for (int i = 1; i <= value; i++)

using System.Text;

using System.Threading.Tasks;
for (int j = 1; j <= i; j++)
namespace Problem12

{
classProblem12

Console.Write(i);

staticvoid Main(string[] args)

Console.Write(" ");

int value;

Console.ReadKey();

Console.WriteLine("Enter A Value:");

value = Convert.ToInt32(Console.R

eadLine());
}

Output:

2. Write a program that takes n values from user and then sorts them in ascending order.
using System;
using System.Collections.Generic;

staticvoid Main(string[] args)


{

using System.Linq;

int num;

using System.Text;

int temp;

using System.Threading.Tasks;

namespace Problem34

Console.WriteLine("Enter The Numbers Yo


u Want To Enter:");

{
num = Convert.ToInt32(Console.Re
classProblem34
{

adLine());
int[] array = newint[num];

temp = array[j];
for (int i = 0; i < num; i++)

array[j] = array[j + 1];

array[j + 1] = temp;
}

Console.WriteLine("Enter " + i + " Value:")

;
}
array[i] = Convert.ToInt32(Cons
ole.ReadLine());

Console.WriteLine("In Ascending Order:");


for (int i = 0; i < num; i++)

for (int i = 0; i < num ; i++)


{
for (int j = 0; j < num - 1; j++)

Console.WriteLine(array[i]);
}

Console.ReadKey();
}

if (array[j] > array[j + 1])


}

{
}

Output:

3. Write a guessing game where the user has to guess a secret number.
After every guess the program tells the user whether their number was
too large or too small. At the end the number of tries needed should be
printed. I counts only as one try if they input the same number multiple
times consecutively.
4. Factorial of N.
Console.Write("Enter a number: ")
Dim num As Integer = Console.ReadLine
Dim total As Integer = num
For i As Integer = 1 To num - 1
total = total * (num - i)
Next
Console.WriteLine(total.ToString)
Console.ReadLine()

5.

You might also like