Practical 5 to 8
Practical 5 to 8
Practical file
Of
Visual Programming Lab
(DCO 612)
9.
10.
Practical 5: - Write a program to design following pyramids using C# dot Net.
Pattern 1 :
using System;
namespace Pattern
{
class Program
{
static void Main(string[] args)
{
int numRows;
Console.WriteLine("Enter number of rows ");
numRows = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
for (int i = numRows; i >= 1; --i)
{
for (int j = 1; j <= i; ++j) {
Console.Write(j);
}
Console.WriteLine();
}
}
}
}
Output: -
Pattern 2:
using System;
namespace Pattern
{
class Program
{
}
}
}
Output :-
Practical 6: - Write a program in C# dot Net to sort an Array of n elements. Also, show the
number of swapping occurred in sorting process.
using System;
namespace SortArray
{
class Program
{
static void Main(string[] args)
{
int[] myArr = new int[5] { 17, 79, 2, 43, 25 };
int i, j, temp;
int count = 0;
Console.WriteLine("Elements:\n ");
for (i = 0; i < 5; i++)
{
Console.Write("{0} ", myArr[i]);
}
for (i = 0; i < 5; i++)
{
for (j = i + 1; j < 5; j++)
{
if (myArr[i] > myArr[j])
{
temp = myArr[i];
myArr[i] = myArr[j];
myArr[j] = temp;
count++;
}
}
}
Console.Read();
}
}
}
Output: -
Practical 7: - Write a program to create list for n number of students using the concept of
“List”.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ListExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the number of student you want to add in list");
int n = Convert.ToInt32(Console.ReadLine());
List<String> userList = new List<String>();
String input;
}
Console.Read();
}
}
}
Ouput:-
Practical 8: - Write a program to search the name of students in an array using “For each
loop”.
using System;
namespace Program_8
{
class Program
{
static void Main(string[] args)
{
string[] arr = { "abc", "def", "xyz","mno", "jkl" };
Console.WriteLine("Enter name of the student you want to search for ");
string studentName = Console.ReadLine();
Console.WriteLine("Students in the class\n");
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
Console.WriteLine();
foreach (string name in arr)
{
if (name == studentName) {
Console.WriteLine(studentName + " is present");
}
else
{
Console.WriteLine(studentName + " is not present");
}
Console.Read();
}
}
}
}
Output: -