OOPs-lab-report
OOPs-lab-report
Submitted to
Mohsin Hossain
Lecturer
Department of Computer Science and Engineering
Uttara University, Uttara, Dhaka
Submitted by
Md Mahfujur Rahman
Department of Computer Science and Engineering
Uttara University
Semester: Spring-2025
Student Id: 2241081221
Semester: 3rd
1. Reverse a string.
Code:
class Program
{
static void Main(string[] args)
{
System.Console.Write("\nEnter a Name: ");
string name = Console.ReadLine();
string newStr="";
for (int i = name.Length-1; i>=0; i--){
newStr += name[i];
}
}
}
Output:
Output:
Code:
class Program
{
static void Main(string[] args)
{
System.Console.Write("Enter an number: ");
int n = int.Parse(Console.ReadLine());
int j =1;
Output:
int fac=1;
for(int i=1; i<=n; i++){
fac = fac*i;
}
System.Console.WriteLine($"Factorial of number {n} is: {fac}");
}
}
Output:
switch (operators)
{
case "+":
System.Console.WriteLine($"{n1} + {n2} is: {n1+n2}");
break;
case "-":
System.Console.WriteLine($"{n1} - {n2} is: {n1-n2}");
break;
case "*":
System.Console.WriteLine($"{n1} * {n2} is: {n1*n2}");
break;
case "/":
System.Console.WriteLine($"{n1} / {n2} is: {n1/n2}");
break;
default:
System.Console.WriteLine("Invalid operetor.");
break;
}
}
}
Output:
newStr += str[i];
}
if(newStr == str){
System.Console.WriteLine("String is palindrome.");
}
else{
System.Console.WriteLine("String isn't palindrome");
}
}
}
Output:
7. Generate the Fibonacci sequence.
Code:
class Program
{
static void Main(string[] args)
{
System.Console.Write("\n\nEnter the digit to you want feb sequence:
");
int n = int.Parse(Console.ReadLine());
int a = 0;
int b = 1;
System.Console.Write($"\nFebonacci sequence is: {0}, {1}");
for(int i=1; i<n-1; i++ ){
int temp = a+b;
System.Console.Write(", "+temp);
a =b;
b=temp;
}
}
}
Output:
Output:
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a decimal number: ");
int decimalNumber = int.Parse(Console.ReadLine());
Output:
10. Find the second largest element in an array.
Code:
class Program
{
static void Main(string[] args)
{
int [] arr = {4,6,3,7,9};
int large = arr[0];
int secLarge = int.MinValue;
for(int i=0; i<arr.Length; i++){
if(arr[i]> large){
large = arr[i];
}
}
}
}
Output:
Code:
Output:
Code:
Output:
Code:
Output:
Code:
Output:
Output:
Code:
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("\n");
int [] arr = {4,6,1,23,8,56,3};
System.Console.Write("Unsoted array is: ");
for(int i =0; i<arr.Length; i++){
System.Console.Write(arr[i]+" ");
}
System.Console.WriteLine("\n");
for(int i=0; i<arr.Length-1; i++){
for (int j=0; j<arr.Length-i-1; j++){
if(arr[j]>arr[j+1]){
int temp = arr[j];
arr[j]= arr[j+1];
arr[j+1]= temp;
}
}
}
System.Console.Write("\nSorted array is: ");
for(int i =0; i<arr.Length; i++){
System.Console.Write(arr[i]+" ");
}
System.Console.WriteLine("\n");
}
}
Output:
Code:
using System;
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the first number: ");
int a = int.Parse(Console.ReadLine());
return a;
}
}
Output:
Code:
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Enter number: ");
int n = int.Parse(Console.ReadLine());
System.Console.WriteLine("Enter power: ");
int p = int.Parse(Console.ReadLine());
Output: