0% found this document useful (0 votes)
157 views17 pages

10 Assignment Lab Programs With Answers in C#

1. The document contains code solutions to 5 C# .Net lab assignment tasks: (1) calculating student marks and result, (2) determining user status based on age, (3) finding the second biggest number among 3, (4) finding the smallest number among 3, and (5) determining if a character is a vowel or consonant. 2. Each task includes the problem statement and code solution using techniques like if/else statements, switch cases, and character comparison. 3. The code solutions accept user input, perform calculations and comparisons, and display outputs for each task.

Uploaded by

xafan39947
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)
157 views17 pages

10 Assignment Lab Programs With Answers in C#

1. The document contains code solutions to 5 C# .Net lab assignment tasks: (1) calculating student marks and result, (2) determining user status based on age, (3) finding the second biggest number among 3, (4) finding the smallest number among 3, and (5) determining if a character is a vowel or consonant. 2. Each task includes the problem statement and code solution using techniques like if/else statements, switch cases, and character comparison. 3. The code solutions accept user input, perform calculations and comparisons, and display outputs for each task.

Uploaded by

xafan39947
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/ 17

C#.

Net Lab Assignment


Task1:-Write a console program to accept student of 3 subject marks they are m1, m2, and m3 and
calculate 3 subjects’ total marks and average marks and display to the user? And display the result?

If any one subject he got <35 his result is fail.

If student got average marks>=60 First class

If student got average marks>=50 and < 60 Second class

If student got average marks >=35 and <50 3 rd class

Sol:-By using if else if and switch case.

If else if :

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

namespace _1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter student name:");
string sname = Console.ReadLine();
Console.WriteLine("enter m1 marks");
int m1 = int.Parse(Console.ReadLine());
Console.WriteLine("enter m2 marks");
int m2 = int.Parse(Console.ReadLine());
Console.WriteLine("enter m3 marks");
int m3 = int.Parse(Console.ReadLine());
int tot = m1 + m2 + m3;
int avg = tot / 3;
Console.WriteLine("avg is" + avg);
if(m1<35||m2<35||m3<35)
{
Console.WriteLine("student " + sname + " is fail");
}
else if (avg >= 60)
{
Console.WriteLine("student "+sname + " having first class");
}
else if (50 <= avg && avg<60)
{
Console.WriteLine("student "+sname + " having second class");
}
else
{
Console.WriteLine("student "+sname+" having third class");

}
Console.ReadLine();
}
}
}

Switch case:

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

namespace average
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter student name:");
string sname = Console.ReadLine();
Console.WriteLine("enter m1 marks");
int m1 = int.Parse(Console.ReadLine());
Console.WriteLine("enter m2 marks");
int m2 = int.Parse(Console.ReadLine());
Console.WriteLine("enter m3 marks");
int m3 = int.Parse(Console.ReadLine());
int tot = m1 + m2 + m3;
int avg = tot / 3;
Console.WriteLine("avg is" + avg);
switch (m1<35||m2<35||m3<35)
{
case true:
Console.WriteLine("student" + sname + " is fail");
break;
case false:
switch(avg>=35&&avg<50)
{
case true:
Console.WriteLine("student "+sname+"having third class");
break;
case false:
switch (avg >=50&&avg< 60)
{
case true:
Console.WriteLine("student"+sname+" having second
class");
break;
case false:
Console.WriteLine("student"+sname+" having first
class");
break;
}
break;
}
break;
}
Console.ReadLine();
}
}
}
OUTPUR

Task2:-Write a console program to accept user age and display the user status?

If user age>=58 Senior Citizen

If user age between 25 to 57 Working citizen

If user age between 16 to 24 college student

If user age between 4 to 15 School boy

If user age between 1 to 3 playing kid

If user age <1 is invalid age

Sol: using System;


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

namespace user_age_status
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter u r age:");
int a = int.Parse(Console.ReadLine());
if (a >= 58)
{
Console.WriteLine("senior citizen:");
}
else if (a >= 25)
{
Console.WriteLine("working citizen");
}
else if (a >= 24)
{
Console.WriteLine("college student");
}
else if (a >= 4)
{
Console.WriteLine("school boy");
}
else if (a >= 1)
{
Console.WriteLine("playing kid");
}
else
{
Console.WriteLine("Invalid age");
}
Console.ReadLine();

}
}
}
OUTPUT:
Task3:-Write a console program to find the 2nd biggest number among 3 numbers?

Sol: using System;


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

namespace _2nd_biggest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter first number:");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("enter second number:");
int b = int.Parse(Console.ReadLine());
Console.WriteLine("enter third number:");
int c = int.Parse(Console.ReadLine());
if (a > b && a > c)
{
if(b>c)
{
Console.WriteLine(b+" b is second biggest number");
}
else
{
Console.WriteLine(c+" c is second biggest number");
}

}
if (b>c && b>a)
{
if (c > a)
{
Console.WriteLine(c + " c is second biggest number");
}
else
{
Console.WriteLine(a + " a is second biggest number");
}
}
if(c>a && c>b)
{
if (a > b)
{
Console.WriteLine(a + " a is second biggest number");
}
else
{
Console.WriteLine(b + " b is second biggest number");
}
}
if (a ==b&&b== c)
{
Console.WriteLine("a &b & c three values are same");
}

if(a==b&&b!=c)
{
Console.WriteLine("a & b two values are same");
}
else if(b == c&&c!=a)
{
Console.WriteLine("b & c two values are same");
}
else if (c == a&&a!=b)
{
Console.WriteLine("c & a two values are same");
}

Console.ReadLine();

}
}
}
OUTPUT:
Task4:-Write a console program to find the smallest number among 3 numbers?

Sol: using System;


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

namespace smallest_among_three
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter first number:");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("enter second number:");
int b = int.Parse(Console.ReadLine());
Console.WriteLine("enter third number:");
int c = int.Parse(Console.ReadLine());
if (a > b && a > c)
{
if (b > c)
{
Console.WriteLine(c + " c is smallest number");
}
else
{
Console.WriteLine( b+ " bis smallest number");
}

}
if (b > c && b > a)
{
if (c > a)
{
Console.WriteLine(a + " a is smallest number");
}
else
{
Console.WriteLine(c + " c is smallest number");
}
}
if (c > a && c > b)
{
if (a > b)
{
Console.WriteLine(b + " b is smallest number");
}
else
{
Console.WriteLine(a + " a is smallest number");
}
}
if (a == b && b == c)
{
Console.WriteLine("a &b & c three values are same");
}

if (a == b && b != c)
{
Console.WriteLine("a & b two values are same");
}
else if (b == c && c != a)
{
Console.WriteLine("b & c two values are same");
}
else if (c == a && a != b)
{
Console.WriteLine("c & a two values are same");
}

Console.ReadLine();

}
}
}
OUTPUT:
Task5:-Write a console program accept a letter from the user?
Display it is vowel or consonant?

Note:-a, e, i, o, u are vowels

Sol: using System;


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

namespace aeiou1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter u r character:");
char ch = char.Parse(Console.ReadLine());
char vowel1='a',vowel2='e',vowel3='i',vowel4='o',vowel5='u';
if(ch==vowel1||ch==vowel2||ch==vowel3||ch==vowel4||ch==vowel5)
{
Console.WriteLine(ch+" is vowel");
}
else
{
Console.WriteLine(ch+" is consonant");
}
Console.ReadLine();

}
}
}
OUTPUT:

Task6:-Write a console program to display the numbers like below?

O/p

55555
4444
333
22
1

Sol:

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

namespace logic_numbers1
{
class Program
{
static void Main(string[] args)
{
for (int i = 5; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
Console.Write(i + " ");
}
Console.WriteLine();
}
Console.ReadLine();

}
}
}
OUTPUT:

Task7:-Write a console program to display the numbers like below?


O/p

Enter your range:

123456789
12345678
1234567
123456
12345
1234
123
12
1

Sol: using System;


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

namespace logic_number2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter u r range:");
int n = int.Parse(Console.ReadLine());
for (int i = n; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
Console.Write(j + " ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}

OUTPUT:
Task 8:- Write a console program to display the numbers like below within the range?

O/p

Enter your range:

15

1
23
456
7 8 9 10
11 12 13 14 15

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

namespace logical_number3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter u r range:");
int n = int.Parse(Console.ReadLine());
int a = 1;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
if(a<=n)
Console.Write(a + " ");
a++;
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
OUTPUT:

Task9:-Write a console program to display the biggest number among 4 numbers?

Sol:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace biggest_number_by_use_array
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter four numbers");
int[] a = new int[4];
for (int i = 0; i < 4; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
Array.Sort(a);
Console.WriteLine("Largest number is: " + a[a.Length - 1]);
Console.ReadLine();
}
}
}
OUTPUT:

Task10:-Write a console program to calculate electricity bill based on slab rate?

Here we have3 types of customers

If customer type is Industry user has to enter 1


Then cost per unit is Rs8
If customer type is Residential user has to enter 2
Then cost per unit is Rs6
If customer type is Agriculture user hast to enter 3
Then cost per unit is Rs2
If user entered other than 1, 2, 3 then display Invalid customer type.
Sol:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace calculateelectric_bill
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter customer name:");
string cname = Console.ReadLine();
Console.WriteLine("enter customer units:");
int cunits = int.Parse(Console.ReadLine());
restart:
Console.WriteLine("enter customer type:" + "\n" + "enter 1 for Industry:" +
"\n" + "enter 2 per Residential:" + "\n" + "enter 3 for Agriculture:");
char ctype=char.Parse(Console.ReadLine());
switch(ctype)
{
case '1':
Console.WriteLine(cname+" Industry bill is:"+ cunits*8+"Rs");
break;
case '2':
Console.WriteLine(cname+" Residential bill is:"+ cunits*6+"Rs");
break;
case '3':
Console.WriteLine(cname+" Agricuture bill is:"+ cunits*2+"Rs");
break;
default:
Console.WriteLine("invalid input:");
goto restart;
}
Console.ReadLine();
}
}
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy