0% found this document useful (0 votes)
180 views5 pages

Sanfoundry Sourcecode

The document contains 5 C# programs: 1. A program to calculate the square footage of a room based on length and width input. 2. A program to create a sealed class. 3. A program to perform unboxing of an integer. 4. A program to display all prime numbers between 1 and 100. 5. A program to determine if an input number is positive, negative, or zero.

Uploaded by

chessgeneral
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
180 views5 pages

Sanfoundry Sourcecode

The document contains 5 C# programs: 1. A program to calculate the square footage of a room based on length and width input. 2. A program to create a sealed class. 3. A program to perform unboxing of an integer. 4. A program to display all prime numbers between 1 and 100. 5. A program to determine if an input number is positive, negative, or zero.

Uploaded by

chessgeneral
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 5

/*

* C# Program to Display Squarefeet of a House

*/

using System;

class pgm

public static void Main()

int length, width, area;

Console.Write ("Enter length of room in feet: ");

length = Convert.ToInt32 (Console.ReadLine());

Console.Write ( "Enter width of room in feet:");

width = Convert.ToInt32(Console.ReadLine());

area = length * width;

Console.WriteLine ("Floor is " + area + " square feet.");

Console.ReadLine();

}
-----------------------------------------------------------------------------
--
/*

* C# Program to Create Sealed Class

*/

using System;

sealed class SealedClass

public int x;

public int y;

class SealedTest
{

static void Main()

SealedClass sc = new SealedClass();

sc.x = 100;

sc.y = 180;

Console.WriteLine("x = {0}, y = {1}", sc.x, sc.y);

Console.ReadLine();

}
-----------------------------------------------------------------------------
--
/*

* C# Program to Perform Unboxing Operation

*/

using System;

class sample

int data;

void insert(object x)

data = (int)x * 5;

object delete()

data=0;

return (object)data;

public static void Main()

sample s = new sample();


s.insert(10);

Console.WriteLine("Data : {0}", s.data);

Console.WriteLine("Data : {0}", s.delete());

Console.ReadLine();

}
-----------------------------------------------------------------------------
--
/*

* C# Program to Display All the Prime Numbers Between 1 to 100

*/

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace PrimeNumber

class Program

static void Main(string[] args)

bool isPrime = true;

Console.WriteLine("Prime Numbers : ");

for (int i = 2; i <= 100; i++)

for (int j = 2; j <= 100; j++)

if (i != j && i % j == 0)

isPrime = false;
break;

if (isPrime)

Console.Write("\t" +i);

isPrime = true;

Console.ReadKey();

}
-----------------------------------------------------------------------------
--
/*

* C# Program to Accept a Number from the user and Display it

* if it is Positive

*/

using System;

class program

public static void Main(string[] args)

Console.WriteLine("Enter a number: ");

int number = Convert.ToInt32(Console.ReadLine());

if (number > 0)

Console.WriteLine("Number is positive");

}
else if (number == 0)

Console.WriteLine("Number is 0");

else

Console.WriteLine("Number is negative");

Console.ReadLine();

You might also like