SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
C# and Dot Net Framework
Prof. K. Adisesha 1
C# and Dot Net Framework
Part A
Steps to execute these programs
Step 1. Path Environment variable for C# Compiler
Copy the path of .NET framework from your computer
Copy the path: “C:WindowsMicrosoft.NETFramework64v4.0.30319”
Search for environment variable in Start menu
Double click on “Path” Variable
Click New
Paste the given path
Press Ok
Step 2. Running the C# program
Save the Program using .cs extension
Open command prompt
Using cd command go to the desired directory(folder)
Step 3. Compile the program using the following method:
“csc filename.cs”
Once compiled successfully corresponding .exe file created with same name as the
program name
Step 4. Run the program at command prompt using: “.filename.exe”
C# Lab Programs:
1.//Fibonacci series program in C#.
using System;
public class Fibonacci
{
public static void Main(string[] args)
{
int n1=0,n2=1,n3,i,number;
Console.Write("Enter the number of elements: ");
number = int.Parse(Console.ReadLine());
Console.Write(n1+" "+n2+" "); //printing 0 and 1
for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
Console.Write(n3+" ");
n1=n2;
n2=n3;
}
}
}
Output:
Enter the number of elements: 15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
C# and Dot Net Framework
Prof. K. Adisesha 2
2. Prime Number Program in C#
using System;
public class PrimeNumber
{
public static void Main(string[] args)
{
int n, i, m=0, flag=0;
Console.Write("Enter the Number to check Prime: ");
n = int.Parse(Console.ReadLine());
m=n/2;
for(i = 2; i <= m; i++)
{
if(n % i == 0)
{
Console.Write("Number is not Prime.");
flag=1;
break;
}
}
if (flag==0)
Console.Write("Number is Prime.");
}
}
Output:
Enter the Number to check Prime: 17
Number is Prime.
Enter the Number to check Prime: 57
Number is not Prime.
3. Palindrome program in C#
using System;
public class Palindrome
{
public static void Main(string[] args)
{
int n,r,sum=0,temp;
Console.Write("Enter the Number: ");
n = int.Parse(Console.ReadLine());
temp=n;
while(n>0)
{
r=n%10;
C# and Dot Net Framework
Prof. K. Adisesha 3
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
Console.Write("Number is Palindrome.");
else
Console.Write("Number is not Palindrome");
}
}
Output:
Enter the Number=121
Number is Palindrome.
Enter the number=113
Number is not Palindrome.
4. Factorial Program in C#:
using System;
public class Factorial
{
public static void Main(string[] args)
{
int i,fact=1,number;
Console.Write("Enter any Number: ");
number= int.Parse(Console.ReadLine());
for(i=1;i<=number;i++){
fact=fact*i;
}
Console.Write("Factorial of " +number+" is: "+fact);
}
}
Output:
Enter any Number: 6
Factorial of 6 is: 720
5. Sum of digits program in C#
using System;
public class Sumdigit
{
public static void Main(string[] args)
{
int n,sum=0,m;
C# and Dot Net Framework
Prof. K. Adisesha 4
Console.Write("Enter a number: ");
n= int.Parse(Console.ReadLine());
while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
Console.Write("Sum is= "+sum);
}
}
Output:
Enter a number: 23
Sum is= 5
Enter a number: 624
Sum is= 12
6. C# Program to find the reverse of a number
using System;
public class ReverseDigit
{
public static void Main(string[] args)
{
int n, reverse=0, rem;
Console.Write("Enter a number: ");
n= int.Parse(Console.ReadLine());
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
Console.Write("Reversed Number: "+reverse);
}
}
Output:
Enter a number: 234
Reversed Number: 432
7. C# Program to swap two numbers without third variable
using System;
public class SwapNumber
C# and Dot Net Framework
Prof. K. Adisesha 5
{
public static void Main(string[] args)
{
int a=5, b=10;
Console.WriteLine("Before swap a= "+a+" b= "+b);
a=a+b; //a=15 (5+10)
b=a-b; //b=5 (15-10)
a=a-b; //a=10 (15-5)
Console.Write("After swap a= "+a+" b= "+b);
}
}
Output:
Before swap a= 5 b= 10
After swap a= 10 b= 5
8. //C# Program to Print Pascal Triangle
using System;
public class PascalTri
{
public static void Main(string[] args)
{
int i,j,k,l,n;
Console.Write("Enter the Range=");
n= int.Parse(Console.ReadLine());
for(i=1; i<=n; i++)
{
for(j=1; j<=n-i; j++)
{
Console.Write(" ");
}
for(k=1;k<=i;k++)
{
Console.Write(k);
}
for(l=i-1;l>=1;l--)
{
Console.Write(l);
}
Console.Write("n");
}
}
}
C# and Dot Net Framework
Prof. K. Adisesha 6
Output:
Enter the Range=5
1
121
12321
1234321
123454321
9. Program to demonstrate Multithreaded Programming in C#.NET
using System.Threading;
using System;
namespace ThreadingDemo
{
class ThreadProg
{
static void Main(string[] args)
{
Thread t = Thread.CurrentThread;
//By Default, the Thread does not have any name
//if you want then you can provide the name explicitly
t.Name = "Main Thread";
Console.WriteLine("Current Executing Thread Name :" + t.Name);
Console.WriteLine("Current Executing Thread Name :" + Thread.CurrentThread.Name);
Console.Read();
}
}
}
Output:
Current Executing Thread Name :Main Thread
Current Executing Thread Name :Main Thread
10. //Program to find square of a number using subroutines and functions in C#.NET
using System;
class SubProgram
{
// function with integer return type declaration
public int square(int nmbr)
{
int sq = nmbr * nmbr;
// Lets provide a return statement
return sq;
}
public static void Main(string[] args)
C# and Dot Net Framework
Prof. K. Adisesha 7
{
SubProgram pr = new SubProgram(); // Creating a class Object
Console.Write("Enter a number: ");
int n= int.Parse(Console.ReadLine());
int rslt = pr.square( n); //Calling the method and assigning the value to an integer type
Console.WriteLine("Square of the given number is "+ rslt); //Printing the result
}
}
Output
Square of the given number is 4
Part B
Based on VB.net

Más contenido relacionado

La actualidad más candente

Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQLAdil Mehmoood
 
COMPUTER SCIENCE & ENGINEERING ACTION PLAN
COMPUTER SCIENCE & ENGINEERING ACTION PLANCOMPUTER SCIENCE & ENGINEERING ACTION PLAN
COMPUTER SCIENCE & ENGINEERING ACTION PLANrkosta
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interfaceShubham Sharma
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVASURIT DATTA
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling sharqiyem
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)Manisha Keim
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statementsKuppusamy P
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVAVINOTH R
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Languagesatvirsandhu9
 
Java Presentation
Java PresentationJava Presentation
Java Presentationpm2214
 
[Question Paper] ASP.NET With C# (75:25 Pattern) [April / 2016]
[Question Paper] ASP.NET With C# (75:25 Pattern) [April / 2016][Question Paper] ASP.NET With C# (75:25 Pattern) [April / 2016]
[Question Paper] ASP.NET With C# (75:25 Pattern) [April / 2016]Mumbai B.Sc.IT Study
 

La actualidad más candente (20)

Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 
JAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdfJAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdf
 
COMPUTER SCIENCE & ENGINEERING ACTION PLAN
COMPUTER SCIENCE & ENGINEERING ACTION PLANCOMPUTER SCIENCE & ENGINEERING ACTION PLAN
COMPUTER SCIENCE & ENGINEERING ACTION PLAN
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
[Question Paper] ASP.NET With C# (75:25 Pattern) [April / 2016]
[Question Paper] ASP.NET With C# (75:25 Pattern) [April / 2016][Question Paper] ASP.NET With C# (75:25 Pattern) [April / 2016]
[Question Paper] ASP.NET With C# (75:25 Pattern) [April / 2016]
 

Similar a C# Lab Programs.pdf

Similar a C# Lab Programs.pdf (20)

Hems
HemsHems
Hems
 
C#.net
C#.netC#.net
C#.net
 
C# console applications.docx
C# console applications.docxC# console applications.docx
C# console applications.docx
 
1 c introduction
1 c introduction1 c introduction
1 c introduction
 
Net practicals lab mannual
Net practicals lab mannualNet practicals lab mannual
Net practicals lab mannual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdfC# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
P2
P2P2
P2
 
ASP.NET
ASP.NETASP.NET
ASP.NET
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
C++ Certified Associate Programmer CPA
C++ Certified Associate Programmer CPAC++ Certified Associate Programmer CPA
C++ Certified Associate Programmer CPA
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
C#unit4
C#unit4C#unit4
C#unit4
 
C# p3
C# p3C# p3
C# p3
 
C Programming
C ProgrammingC Programming
C Programming
 

Más de Prof. Dr. K. Adisesha

Software Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdfSoftware Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdfSoftware Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdfSoftware Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdfSoftware Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdfSoftware Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdfSoftware Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdfProf. Dr. K. Adisesha
 
Computer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. AdiseshaComputer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. AdiseshaProf. Dr. K. Adisesha
 
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. AdiaeshaCCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. AdiaeshaProf. Dr. K. Adisesha
 
CCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. AdiseshaCCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. AdiseshaProf. Dr. K. Adisesha
 
CCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. AdiseshaCCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. AdiseshaProf. Dr. K. Adisesha
 
CCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdfCCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdfProf. Dr. K. Adisesha
 

Más de Prof. Dr. K. Adisesha (20)

Software Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdfSoftware Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdf
 
Software Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdfSoftware Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdf
 
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdfSoftware Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
 
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdfSoftware Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
 
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdfSoftware Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
 
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdfSoftware Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
 
Computer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. AdiseshaComputer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. Adisesha
 
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. AdiaeshaCCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
 
CCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. AdiseshaCCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. Adisesha
 
CCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. AdiseshaCCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. Adisesha
 
CCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdfCCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdf
 
Introduction to Computers.pdf
Introduction to Computers.pdfIntroduction to Computers.pdf
Introduction to Computers.pdf
 
R_Programming.pdf
R_Programming.pdfR_Programming.pdf
R_Programming.pdf
 
Scholarship.pdf
Scholarship.pdfScholarship.pdf
Scholarship.pdf
 
Operating System-2 by Adi.pdf
Operating System-2 by Adi.pdfOperating System-2 by Adi.pdf
Operating System-2 by Adi.pdf
 
Operating System-1 by Adi.pdf
Operating System-1 by Adi.pdfOperating System-1 by Adi.pdf
Operating System-1 by Adi.pdf
 
Operating System-adi.pdf
Operating System-adi.pdfOperating System-adi.pdf
Operating System-adi.pdf
 
Data_structure using C-Adi.pdf
Data_structure using C-Adi.pdfData_structure using C-Adi.pdf
Data_structure using C-Adi.pdf
 
JAVA PPT -2 BY ADI.pdf
JAVA PPT -2 BY ADI.pdfJAVA PPT -2 BY ADI.pdf
JAVA PPT -2 BY ADI.pdf
 
JAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdfJAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdf
 

Último

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Último (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

C# Lab Programs.pdf

  • 1. C# and Dot Net Framework Prof. K. Adisesha 1 C# and Dot Net Framework Part A Steps to execute these programs Step 1. Path Environment variable for C# Compiler Copy the path of .NET framework from your computer Copy the path: “C:WindowsMicrosoft.NETFramework64v4.0.30319” Search for environment variable in Start menu Double click on “Path” Variable Click New Paste the given path Press Ok Step 2. Running the C# program Save the Program using .cs extension Open command prompt Using cd command go to the desired directory(folder) Step 3. Compile the program using the following method: “csc filename.cs” Once compiled successfully corresponding .exe file created with same name as the program name Step 4. Run the program at command prompt using: “.filename.exe” C# Lab Programs: 1.//Fibonacci series program in C#. using System; public class Fibonacci { public static void Main(string[] args) { int n1=0,n2=1,n3,i,number; Console.Write("Enter the number of elements: "); number = int.Parse(Console.ReadLine()); Console.Write(n1+" "+n2+" "); //printing 0 and 1 for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed { n3=n1+n2; Console.Write(n3+" "); n1=n2; n2=n3; } } } Output: Enter the number of elements: 15 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
  • 2. C# and Dot Net Framework Prof. K. Adisesha 2 2. Prime Number Program in C# using System; public class PrimeNumber { public static void Main(string[] args) { int n, i, m=0, flag=0; Console.Write("Enter the Number to check Prime: "); n = int.Parse(Console.ReadLine()); m=n/2; for(i = 2; i <= m; i++) { if(n % i == 0) { Console.Write("Number is not Prime."); flag=1; break; } } if (flag==0) Console.Write("Number is Prime."); } } Output: Enter the Number to check Prime: 17 Number is Prime. Enter the Number to check Prime: 57 Number is not Prime. 3. Palindrome program in C# using System; public class Palindrome { public static void Main(string[] args) { int n,r,sum=0,temp; Console.Write("Enter the Number: "); n = int.Parse(Console.ReadLine()); temp=n; while(n>0) { r=n%10;
  • 3. C# and Dot Net Framework Prof. K. Adisesha 3 sum=(sum*10)+r; n=n/10; } if(temp==sum) Console.Write("Number is Palindrome."); else Console.Write("Number is not Palindrome"); } } Output: Enter the Number=121 Number is Palindrome. Enter the number=113 Number is not Palindrome. 4. Factorial Program in C#: using System; public class Factorial { public static void Main(string[] args) { int i,fact=1,number; Console.Write("Enter any Number: "); number= int.Parse(Console.ReadLine()); for(i=1;i<=number;i++){ fact=fact*i; } Console.Write("Factorial of " +number+" is: "+fact); } } Output: Enter any Number: 6 Factorial of 6 is: 720 5. Sum of digits program in C# using System; public class Sumdigit { public static void Main(string[] args) { int n,sum=0,m;
  • 4. C# and Dot Net Framework Prof. K. Adisesha 4 Console.Write("Enter a number: "); n= int.Parse(Console.ReadLine()); while(n>0) { m=n%10; sum=sum+m; n=n/10; } Console.Write("Sum is= "+sum); } } Output: Enter a number: 23 Sum is= 5 Enter a number: 624 Sum is= 12 6. C# Program to find the reverse of a number using System; public class ReverseDigit { public static void Main(string[] args) { int n, reverse=0, rem; Console.Write("Enter a number: "); n= int.Parse(Console.ReadLine()); while(n!=0) { rem=n%10; reverse=reverse*10+rem; n/=10; } Console.Write("Reversed Number: "+reverse); } } Output: Enter a number: 234 Reversed Number: 432 7. C# Program to swap two numbers without third variable using System; public class SwapNumber
  • 5. C# and Dot Net Framework Prof. K. Adisesha 5 { public static void Main(string[] args) { int a=5, b=10; Console.WriteLine("Before swap a= "+a+" b= "+b); a=a+b; //a=15 (5+10) b=a-b; //b=5 (15-10) a=a-b; //a=10 (15-5) Console.Write("After swap a= "+a+" b= "+b); } } Output: Before swap a= 5 b= 10 After swap a= 10 b= 5 8. //C# Program to Print Pascal Triangle using System; public class PascalTri { public static void Main(string[] args) { int i,j,k,l,n; Console.Write("Enter the Range="); n= int.Parse(Console.ReadLine()); for(i=1; i<=n; i++) { for(j=1; j<=n-i; j++) { Console.Write(" "); } for(k=1;k<=i;k++) { Console.Write(k); } for(l=i-1;l>=1;l--) { Console.Write(l); } Console.Write("n"); } } }
  • 6. C# and Dot Net Framework Prof. K. Adisesha 6 Output: Enter the Range=5 1 121 12321 1234321 123454321 9. Program to demonstrate Multithreaded Programming in C#.NET using System.Threading; using System; namespace ThreadingDemo { class ThreadProg { static void Main(string[] args) { Thread t = Thread.CurrentThread; //By Default, the Thread does not have any name //if you want then you can provide the name explicitly t.Name = "Main Thread"; Console.WriteLine("Current Executing Thread Name :" + t.Name); Console.WriteLine("Current Executing Thread Name :" + Thread.CurrentThread.Name); Console.Read(); } } } Output: Current Executing Thread Name :Main Thread Current Executing Thread Name :Main Thread 10. //Program to find square of a number using subroutines and functions in C#.NET using System; class SubProgram { // function with integer return type declaration public int square(int nmbr) { int sq = nmbr * nmbr; // Lets provide a return statement return sq; } public static void Main(string[] args)
  • 7. C# and Dot Net Framework Prof. K. Adisesha 7 { SubProgram pr = new SubProgram(); // Creating a class Object Console.Write("Enter a number: "); int n= int.Parse(Console.ReadLine()); int rslt = pr.square( n); //Calling the method and assigning the value to an integer type Console.WriteLine("Square of the given number is "+ rslt); //Printing the result } } Output Square of the given number is 4 Part B Based on VB.net