0% found this document useful (0 votes)
21 views9 pages

Awp Practical

Uploaded by

Highcourt Raja
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)
21 views9 pages

Awp Practical

Uploaded by

Highcourt Raja
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/ 9

Fibonacci Series

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++;
}
}
}
}
Prime number

using System;
namespace testprime
{
class Program
{
static void Main(string[] args)
{
int num, counter;
Console.Write("Enter number:");
num = int.Parse(Console.ReadLine());
for (counter = 2; counter <= num / 2; counter++)
{
if ((num % counter) == 0)
break;
}
if (num == 1)
Console.WriteLine(num + "is neither prime nor composite");
else if (counter < (num / 2))
Console.WriteLine(num + "is not prime number");
else
Console.WriteLine(num + "is prime number");
}
}
}
Interfaces
ODDEVEN.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InterFaceDemo {
interface IOne {
void ONE(); //Pure Abstract Method Signature
}
interface ITwo {
void TWO();
}
interface IThree: IOne {
void THREE();
}
interface IFour {
void FOUR();
}
interface IFive: IThree {
void FIVE();
}
interface IEVEN: ITwo, IFour {}
class ODDEVEN: IEVEN, IFive //Must Implement all the abstract method, in
Derived class.
{
public void ONE() //Implementation of Abstract Method.
{
Console.WriteLine("This is ONE");
}
public void TWO() {
Console.WriteLine("This is TWO");
}
public void THREE() {
Console.WriteLine("This is THERE");
}
public void FOUR() {
Console.WriteLine("This is FOUR");
}
public void FIVE() {
Console.WriteLine("This is FIVE");
}
}
}

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InterFaceDemo {
class Program {
static void Main(string[] args) {
Console.WriteLine("This is ODD");
IFive obj1 = new ODDEVEN();
obj1.ONE();
obj1.THREE();
obj1.FIVE();
Console.WriteLine("\n\nThis is EVEN");
IEVEN obj2 = new ODDEVEN();
obj2.TWO();
obj2.FOUR();
Console.ReadLine();
}
}
}

Using Delegates and events

TrafficSignal.cs
using System;
namespace TrafficDelegateExample
{
public delegate void TrafficDel();
class TrafficSignal
{
public static void Yellow()
{
Console.WriteLine("Yellow light signals to get ready");
}
public static void Green()
{
Console.WriteLine("Green light signals to go");
}
public static void Red()
{
Console.WriteLine("Red light signals to stop");
}
TrafficDel[] td = new TrafficDel[3];
public void IdentifySignal()
{
td[0] = new TrafficDel(Yellow);
td[1] = new TrafficDel(Green);
td[2] = new TrafficDel(Red);
}
public void display()
{
td[0]();
td[1]();
td[2]();
}
}}

Program.c

using System;
namespace TrafficDelegateExample
{
class Program
{
static void Main(string[] args)
{
TrafficSignal ts = new TrafficSignal();
ts.IdentifySignal();
ts.display();
}}}
Exception handling
NotEvenException.cs
using System;
namespace ExceptionHandlingExample
{
class NotEvenException:Exception
{
public NotEvenException(string msg)
: base(msg)
{
}
}}

Program.cs
using System;
namespace ExceptionHandlingExample
{
class Program
{
static void Main(string[] args)
{
int num;
try
{
Console.Write("Enter a number: ");
num = int.Parse(Console.ReadLine());
if ((num % 2) != 0) throw new NotEvenException("Not an even number ");
else
Console.WriteLine("Its even number ");
}
catch (NotEvenException e) { Console.WriteLine(e.Message); }
}}}

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