0% found this document useful (0 votes)
25 views7 pages

Yash Awp1d

The document describes a C# program that implements 5 operations: 1) generating a Fibonacci series, 2) testing if a number is prime, 3) testing if a character is a vowel, 4) using a foreach loop to iterate through an array, and 5) reversing a number and finding the sum of its digits. The main method uses a switch statement to allow the user to select which operation to perform by entering a number, and calls the corresponding method to run that operation.

Uploaded by

wilson
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)
25 views7 pages

Yash Awp1d

The document describes a C# program that implements 5 operations: 1) generating a Fibonacci series, 2) testing if a number is prime, 3) testing if a character is a vowel, 4) using a foreach loop to iterate through an array, and 5) reversing a number and finding the sum of its digits. The main method uses a switch statement to allow the user to select which operation to perform by entering a number, and calls the corresponding method to run that operation.

Uploaded by

wilson
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/ 7

PRACTICAL 1D

AIM:- Create an application to demonstrate following operations


i. Generate Fibonacci series.

ii. Test for prime numbers.

iii. Test for vowels.

iv. Use of for each loop with arrays.

v. Reverse a number and find sum of digits of a number.

CODE :-
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace practical1d

class Prcatical1d

public void Generate_Fibonacci_Series(int n)

int n0 = 0;

int n1 = 1;

Console.WriteLine(n0);

Console.WriteLine(n1);

for(int i=3;i<=n;i++)
{

int n3 = n0 + n1;

Console.WriteLine(n3);

n0 = n1;

n1 = n3;

public bool isPrime(int num)

bool revalue = true;

for (int i = 2; i <= num / 2; i++)

if (num % i == 0)

revalue=false;

break;

return revalue;

public bool CheckVowels(char c)

bool revalue = false;

if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')

revalue = true;

}
return revalue;

public void Foreach_operation(char[] arr)

foreach (char ch in arr)

Console.WriteLine(ch);

public void reverse_Num(int num)

int m;

int sum = 0;

int rev = 0;

while (num > 0)

m = num % 10;

sum += m;

rev = rev * 10 + m;

num = num / 10;

Console.WriteLine("The reverse of number is : {0}", rev);

Console.WriteLine("The sum of digits is : {0}", sum);

class Program
{

static void Main(string[] args)

Prcatical1d p1 = new Prcatical1d();

Console.WriteLine("1)Fibonnaci\n2)Prime Number\n3)Vowels\n4)Foreach Loop\n5)Reverse a number


and find sum of digits of a number");

Console.Write("Enter the Operation Number you want to perform");

int choice = int.Parse(Console.ReadLine());

switch(choice)

case 1:

Console.Write("Enter how many numbers in Fibonnaci series");

int n = int.Parse(Console.ReadLine());

p1.Generate_Fibonacci_Series(n);

break;

case 2:

Console.WriteLine("Enter the number to check : ");

int num;

num = int.Parse(Console.ReadLine());

bool ans=p1.isPrime(num);

if (ans == true)

Console.WriteLine("{0} is a Prime Number", num);

else

Console.WriteLine("{0} is not a Prime Number",num);

break;

case 3:

Console.WriteLine("Enter the character");


char ch = Console.ReadKey().KeyChar;

bool ans1= p1.CheckVowels(ch);

if (ans1 == true)

Console.WriteLine("{0} is a Character", ch);

else

Console.WriteLine("{0} is not a Character", ch);

break;

case 4:

char[] myArray = { 'Y', 'A', 'S', 'H' };

Console.WriteLine("The characters of the given arrays are as follows:");

p1.Foreach_operation(myArray);

break;

case 5:

Console.WriteLine("Enter any number");

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

p1.reverse_Num(a);

break;

default:

Console.WriteLine("Wrong Entry");

break;

Console.ReadLine();

}
OUTPUT
i)Fibonacci series.

ii)prime numbers.

iii)vowels.
iv. Use of for each loop with arrays.

5)Reverse a number and find sum of digits of a number Enter the Operation Number you
want to perform

You might also like