Professional Documents
Culture Documents
C# Pracs 123
C# Pracs 123
Practical number:01
Write a console application that obtains four int values from the user and displays the product.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
int a, b, c, d, e;
void get_no()
{
Console.WriteLine(" Enter four numbers: ");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
d = Convert.ToInt32(Console.ReadLine());
}
void product()
{
e = a * b * c * d;
Console.WriteLine("Product of numbers is: " + e);
Console.ReadLine();
}
static void Main(string[] args)
{
Program p = new Program();
p.get_no();
p.product();
}
}
}
Practical number:02
If you have two integers stored in variables var1 and var2, what Boolean test can you perform to
see if one or the other (but not both) is greater than 10?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int var1, var2;
Console.WriteLine("Enter First number:");
var1=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Second number:");
var2=Convert.ToInt32(Console.ReadLine());
bool c = false;
c=(var1>10 && var2<10);
{
Console.WriteLine("First no is greater than 10 and second number is less
than 10");
Console.ReadLine();
}
c=(var1<10 && var2>10);
{
Console.WriteLine("First no is less than 10 and second number is greater
than 10");
Console.ReadLine();
}
}
}
}
Practical number:03
Write an application that includes the logic from Exercise 1, obtains two numbers from the user, and
displays them, but rejects any input where both numbers are greater than 10 and asks for two new
numbers.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
int var1,var2,var3;
void add()
{
lp: Console.WriteLine("Enter two Numbers:");
var1 = Convert.ToInt32(Console.ReadLine());
var2 = Convert.ToInt32(Console.ReadLine());
Write a console application that places double quotation marks around each word in a string
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
class Program
start:
string myString;
string[] myWords;
myWords = myString.Split(separator);
Console.WriteLine();
Console.ReadLine();
Console.Clear();
goto start;
}
Practical number:06
Write an application that receives the following information from a set of students: Student Id: Student
Name: Course Name: Date of Birth: The application should also display the information of all the
students once the data is entered. Implement this using an Array of Structs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
struct student
class Program
arr[i].s_id = Console.ReadLine();
arr[i].s_name = Console.ReadLine();
arr[i].dob = Console.ReadLine();
Console.WriteLine("----------Student Details-----------");
Console.ReadLine();