Professional Documents
Culture Documents
Using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LAB_IA
{
internal class Quadrati_Euqation
{
public static void Main()
{
int a, b, c;
double d, x1, x2;
Console.Write("\n\n");
Console.Write("Calculate the root of Quadratic Equation");
Console.Write("-------");
Console.Write("\n\n");
Console.Write("Input the Value of a:");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the Value of b:");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the Value of c:");
c = Convert.ToInt32(Console.ReadLine());
d = b * b - 4 * a * c;
if (d == 0)
{
Console.Write("Both roots are equal");
x1 = (-d / (2.0 * a));
x2 = x1;
Console.Write("First Root Root1={0}\n,x1");
Console.Write("First Root Root2={0}\n,x2");
}
else if (d > 0)
{
Console.Write("Both roots are real and diff-2\n");
x1 = d + Math.Sqrt (2 * a);
x2 = -d- Math.Sqrt (2 * a);
Console.Write("First Root Root1={0}\n",x1);
Console.Write("Second Root Root2={0}\n", x2);
}
else
{
Console.Write("Both roots are Imaginary");
}
}
}
}
OUT PUT:
2.Write a C# sharp To count the frequency of each element of an array
using System;
using System.Threading.Tasks;
namespace BCAV404
{
internalclassLAB2
{
publicstaticvoid Main(string[] args)
{
int[] arr1 = newint[100];
int[] fr1 = newint[100];
int n, i, j, ctr;
Console.Write("\n\nCount the frequency of each element of anarray:");
Console.Write("-----------------------------------------------\n");
Console.Write("Input the number of elements to be stored in the Array :");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("Input {0} elements in the array:\n", n);
for (i = 0; i < n; i++)
{
Console.Write("element -{0} :", i);
arr1[i] = Convert.ToInt32(Console.ReadLine());
fr1[i] = -1;
}
for (i = 0; i < n; i++)
{
ctr = 1;
for (j = i + 1; j < n; j++)
{
if (arr1[i] == arr1[j])
{
ctr++;
fr1[j] = 0;
}
}
if (fr1[i] != 0)
{
fr1[i] = ctr;
}
}
Console.Write("\n The frequency of all elements of the array :\n");
for (i = 0; i < n; i++)
{
if (fr1[i] != 0)
{
Console.Write("{0} occurs {1} times\n", arr1[i], fr1[i]);
}
}
}
}
Output:
3.write the program in c# sharp to count the total number of alphabets Digits and special
characters in a string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCAV404
{
internalclassLAB3
{
publicstaticvoid Main()
{
string str;
int alp, digit, splch, i, l;
alp = digit = splch = i = 0;
namespace BCAV404
{
internalclassLAB4
{
publicstaticint SumCal(int n)
{
string n1 = Convert.ToString(n);
int sum = 0;
for (int i = 0; i < n1.Length; i++)
sum += Convert.ToInt32(n1.Substring(i, 1));
return sum;
}
publicstaticvoid Main()
{
int num;Console.Write("\n\nFunction:To calculate the sum of the individual digits of a number:\
n");
Console.Write("------------------------------------------------\n");
Console.Write("Enter a number:");
num = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The sum of the digits of the number(0)is:{1}\n", num, SumCal(num));
}
}
}
Output:
5. Create an Application that allows the user to enter a number in the text box name
‘getnum’.Check wether the number in the text box’grtnem’ is palindrome or not.Print the massage
accordingliy in thr label control name lbl display when the user clkicks on the button’check’.
Source Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pallindrome
{
publicpartialclasslbl1 : Form
{
publiclbl1()
{
InitializeComponent ();
}
{
rem = num % 10;
sum = (sum * 10) + rem;
num = num / 10;
}
if (temp == sum)
{
lbl.Text = "The given number is not pallindrome";
}
}
}
}
Output:
Design part:
Properties:
Label3 lbl --
Output:
Propertries:
}
}
Output:
08: Write a program that inputs the co-ordinates of three mouse clicks from the user and then
draws a triangle in the output windows using those three points.
Source Code:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Windows.Forms;
namespace triangle
{
Public partial class Form1 : Form
{
publicForm1()
{
InitializeComponent();
}
properties:
namespace BCAV404
{
internalclassLAB5
{
classHuman
{
publicstring name;
publicHuman(string na)
{
name = na;
}
}
classMan : Human
{
publicint age;
publicMan(int age, string name) : base(name)
{
this.age = age;
}
}
classEmployee : Man
{
publicint emp_id;
publicint emp_salary;
publicEmployee(int id, int salary, string name, int age) : base(age, name)
{
emp_id = id;
emp_salary = salary;
}
publicvoid print()
{
Console.WriteLine("Emp ID: " + emp_id);
Console.WriteLine("Emp Name: " + name);
Console.WriteLine("Emp Salary: " + emp_salary);
Console.WriteLine("Emp Age: " + age);
}
staticvoid Main(string[] args)
{
Employee emp = new Employee(101, 1000, "Rahul", 31);
emp.print();
}
}
}
}
Output:
10. C# Program to Demonstrate I List Inteface.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ListInterface_2
{
internal class ListInterFace2
{
static void Show(IList<string> list)
{
foreach (string str in list)
{
Console.WriteLine("\t"+ str);
}
}
data.Add("nikhita");
data.Add("Aishwarya");
data.Add("Anju");
Console.WriteLine("Subjects Name:");
Show(subjects);
Console.WriteLine("Student Name:");
Show(data);
}
}
}
Output:
11.Write a program to Display the selected date in the calendar
Source code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calendar1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Textbox txtDate --
Source Code:
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingMySql.Data.MySqlClient;
namespaceStudent_Info
{
publicpartialclassinfo : System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{
cmd.Parameters.AddWithValue("@name", txtname.Text);
cmd.Parameters.AddWithValue("@add1", txtAdd1.Text);
cmd.Parameters.AddWithValue("@add2",txtAdd2.Text);
cmd.Parameters.AddWithValue("@email", txtEmail.Text);
con.Open();
introwsAffected = cmd.ExecuteNonQuery();
Label1.Text = "Data inserted into database successfully";
con.Close();
}
}
Output:
Properties:
Control ID Text
Label1 lblDisplay
TextBox1 txtName
TextBox2 txtAdd1
TextBox3 txtAdd2
TextBox4 txtEmail
Source Code:
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingMySql.Data.MySqlClient;
namespaceStudent_Info
{
publicpartialclassinfo : System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{
cmd.Parameters.AddWithValue("@name", txtAuthName.Text);
con.Open();
Label1.Text = "Connection Successful";
MySqlDataReaderrd= cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
con.Close();
}
}
}
Output:
Properties :
Controls ID Text
TextBox1 txtAuthName
GridView1 GridView1
Label1 lblDisplay