0% found this document useful (0 votes)
18 views15 pages

(VP) Lab # 01

Lb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views15 pages

(VP) Lab # 01

Lb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

ASP.

NET WITH C#

PRACTICAL NO. : 01(A)

AIM: Write a console application that obtains four int values from the user and displays the
product.
Hint: you may recall that the Convert.ToDouble() command was used to convert the input
from the console to a double; the equivalent command to convert from a string to an int is
Convert.ToInt32().

CODE:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num1, num2,num3,num4,prod;
Console.Write("Enter number 1: ");
num1 = Int32.Parse(Console.ReadLine());
Console.Write("Enter number 2: ");
num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 3: ");
num3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 4: ");
num4 = Convert.ToInt32(Console.ReadLine());
prod = num1 * num2 * num3 * num4;
Console.WriteLine(num1 + "*" + num2 + "*" + num3 + "*" + num4 + "=" + prod);
}
}
}

OUTPUT:
Enter number 1: 6
Enter number 2: 5
Enter number 3: 4
Enter number 4: 3
6*5*4*3=360
ASP.NET WITH C#

PRACTICAL NO. : 01(B)

AIM: 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;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int var1, var2;
Console.Write("Enter number 1: ");
var1 = Int32.Parse(Console.ReadLine());
Console.Write("Enter number 2: ");
var2 = Convert.ToInt32(Console.ReadLine());
if ((var1 > 10 && var2 <= 10) || (var2 > 10 && var1 <= 10))
{
Console.WriteLine("Boolean test succedded \n Both number are not >10");
}
}
}
}

OUTPUT:
Enter number 1: 5
Enter number 2: 11
Boolean test succedded
Both number are not >10
ASP.NET WITH C#

PRACTICAL NO. : 01(C)

AIM: 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;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int var1, var2;
label1:
Console.Write("Enter number 1: ");
var1 = Int32.Parse(Console.ReadLine());
Console.Write("Enter number 2: ");
var2 = Convert.ToInt32(Console.ReadLine());
if ((var1 > 10 && var2 > 10) )
{
Console.WriteLine("Both No are greater than 10 are not allowed");
goto label1;
}
else
{
Console.WriteLine("Number 1: "+var1);
Console.WriteLine("Number 2 :"+var2);
}
}
}
}

OUTPUT:
Enter number 1:15
Enter number 2: 16
Both no. are greater than 10 are not allowed
Enter number 1:5
Enter number 2: 15
Number 1: 5
Number 2 :15
ASP.NET WITH C#

PRACTICAL NO. : 01(D)

AIM: Write a console application that places double quotation marks around each word in
a string .

CODE:
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string str1;
Console.Write("Enter string 1: ");
str1 = Console.ReadLine();
string[] words = str1.Split(' ');
for (int i = 0; i < words.Length; i++)
{
Console.Write("\" " + words[i] + "\" ");
}
}
}
}

OUTPUT:
Enter string 1: we can and we will
ASP.NET WITH C#

PRACTICAL NO. : 01(E)

AIM: Write an application that uses two command-line arguments to place values into a
string and an integer variable, respectively. Then display these values.

CODE:
using System;
namespace cmdLineArgs
{
class Program
{
static void Main(string[] args)
{
string str = args[0];
int n = Convert.ToInt32(args[1]);
Console.WriteLine("String:" + str);
Console.WriteLine("Number:" + n);
}
}
}

OUTPUT:
String : Roman
Number : 10
ASP.NET WITH C#

PRACTICAL NO. : 01(F)

AIM: 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 Structures.

CODE:
using System;
namespace ArrayOfStructs
{
class Program
{
struct Student
{
public string studid, name, cname;
public int day, month, year;
}
static void Main(string[] args)
{
Student[] s = new Student[5];
int i;
for (i = 0; i < 5; i++)
{
Console.Write("Enter Student Id:");
s[i].studid = Console.ReadLine();
Console.Write("Enter Student name : ");
s[i].name = Console.ReadLine();
Console.Write("Enter Course name : ");
s[i].cname = Console.ReadLine();
Console.Write("Enter date of birth\n Enter day(1-31):");
s[i].day = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter month(1-12):");
s[i].month = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter year:");
s[i].year = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("\n\nStudent's List\n");
for (i = 0; i < 5; i++)
{
Console.WriteLine("\nStudent ID : " + s[i].studid);
Console.WriteLine("\nStudent name : " + s[i].name);
Console.WriteLine("\nCourse name : " + s[i].cname);
Console.WriteLine("\nDate of birth(dd-mm-yy) : " + s[i].day + "-" + s[i].month +
"-" + s[i].year);
}}}}
ASP.NET WITH C#

OUTPUT:
Enter Student Id:0001
Enter Student name : Prachit
Enter Course name : MSCit
Enter date of birth
Enter day(1-31):29
Enter month(1-12):9
Enter year:1995
Enter Student Id:0002
Enter Student name : Aniket
Enter Course name : Bscit
Enter date of birth
Enter day(1-31):4
Enter month(1-12):3
Enter year:1996
Enter Student Id:0003
Enter Student name : Prathamesh
Enter Course name : BMS
Enter date of birth
Enter day(1-31):9
Enter month(1-12):8
Enter year:2000
Enter Student Id:0004
Enter Student name : Sumit
Enter Course name :MScet
Enter date of birth
Enter day(1-31):25
Enter month(1-12):5
Enter year:1994
Enter Student Id : 0005
Enter Student name : Zaid
Enter Course name : BCOM
Enter date of birth
Enter day(1-31):6
Enter month(1-12):7
Enter year:1993

Student's List

Student ID : 0001
Student name : Prachit
Course name : MSCit
Date of birth(dd-mm-yy) : 29-9-1995
Student ID : 0002
Student name : Aniket
Course name : Bscit
Date of birth(dd-mm-yy) : 4-3-1996
Student ID : 0003
Student name : Prathamesh
Course name : BMS
Date of birth(dd-mm-yy) : 9-8-2000
ASP.NET WITH C#

Student ID : 0004
Student name : Sumit
Course name : MScet
Date of birth(dd-mm-yy) : 25-5-1994
Student ID : 0005
Student name : Zaid
Course name : BCOM
Date of birth(dd-mm-yy) : 6-7-1993
ASP.NET WITH C#

PRACTICAL NO. : 01(G)

AIM: Write programs using conditional statements and loops:


I) Generate Fibonacci series.

CODE:
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int num1=0,num2=1,num3,num4,num,counter;
Console.Write ("Upto how many number you want fibonacci
series:"); num=int.Parse(Console.ReadLine()); counter=3;

Console.Write(num1+"\t"+num2);
while(counter<=num)
{
num3 = num1 + num2;
if (counter >= num)
break;
Console.Write("\t" + num3);
num1 = num2;
num2 = num3;
counter++;
}
}
}
}

OUTPUT:
Upto how many number you want fibonacci series:5
0 1 1 2 3
ASP.NET WITH C#

PRACTICAL NO. : 01(G)

AIM: Write programs using conditional statements and loops:


II) Generate various patterns (triangles, diamond and other patterns) with numbers.

CODE -1:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int row, col;
for (row = 1; row <= 5; row++)
{
for (col = 1; col <= row; col++)
Console.Write(col);
Console.WriteLine();
}
}
}
}

OUTPUT:
1
12
123
1234
12345
ASP.NET WITH C#

CODE -2:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int row, sp, col;
for (row = 1; row <= 5; row++)
{
for (sp = 1; sp <= 5 - row; sp++)
{
Console.Write(' ');
}
for (col = 1; col <= row; col++)
{
Console.Write(col);
}
Console.WriteLine();
}
}}}}

OUTPUT:
1
12
123
1234
12345
ASP.NET WITH C#

CODE -3:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int row, sp, col,revcol;
for (row = 1; row <= 5; row++)
{
for (sp = 1; sp <= 5 - row; sp++)
{
Console.Write(' ');
}
for (col = 1; col <= row; col++)
{
Console.Write(col);
}
for (revcol = col - 2; revcol >= 1; revcol--)
{
Console.Write(revcol);
}
Console.WriteLine();
}
}
}
}

OUTPUT:
1
121
12321
1234321
123454321
ASP.NET WITH C#

CODE-4:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int row, sp, col, revcol;
for (row = 1; row <= 5; row++) {
for (sp = 1; sp <= 5 - row; sp++)
{
Console.Write(' ');
}
for (col = 1; col <= row; col++)
{
Console.Write(col);
}
for (revcol = col - 2; revcol >= 1; revcol--)
{ Console.Write(revcol); }
Console.WriteLine();
}
for (row = 4; row >= 1; row--) {
for (sp = 1; sp <= 5 - row; sp++)
{
Console.Write(' ');
}
for (col = 1; col <= row; col++)
{
Console.Write(col);
}
for (revcol = col - 2; revcol >= 1; revcol--)
{ Console.Write(revcol); }
Console.WriteLine();
} }}}

OUTPUT:
1
121
12321
1234321
123454321
1234321
12321
121
1
ASP.NET WITH C#

CODE-5:
using System;
namespace pattern
{
class Program
{
static void Main(string[] args)
{
int row, col,sp,reverse;
for (row = 1; row <= 5; row++)
{
for (sp = 1; sp <= 5 - row; sp++)
Console.Write(" ");
for (col = 1; col <= row; col++)
if (col == 1)
Console.Write("*");
else
Console.Write(" ");
for (reverse = col - 2; reverse >= 1; reverse--)
if (reverse == 1)
Console.Write("*");
else
Console.Write(" ");
Console.WriteLine();
}
for (row = 4; row >=1; row--)
{
for (sp = 1; sp <= 5 - row; sp++)
Console.Write(" ");
for (col = 1; col <= row; col++)
if (col == 1)
Console.Write("*");
else
Console.Write(" ");
for (reverse = col - 2; reverse >= 1; reverse--)
if (reverse == 1)
Console.Write("*");
else
Console.Write(" ");
Console.WriteLine();
}
}}}

OUTPUT:
ASP.NET WITH C#

*
**
* *
* *
* *
* *
* *
**
*

You might also like