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

Prime No. Code: Using Using Using Using Namespace Class Static Void String Int Int For If

The document contains code examples for several C# programs, including: 1) A program that checks if a number is prime by testing if it is divisible by any number between 2 and its half. 2) A program that calculates the Fibonacci series for a given number by initializing 3 variables and iteratively calculating the next value. 3) A program that checks if a character is a vowel by using a switch statement to compare the character to the vowels. 4) A program that reverses an input number, calculates the sum of its digits, and displays both the reversed number and sum. 5) A program that uses a foreach loop to iterate through and print out elements of a string

Uploaded by

dsdfregthyju
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)
49 views7 pages

Prime No. Code: Using Using Using Using Namespace Class Static Void String Int Int For If

The document contains code examples for several C# programs, including: 1) A program that checks if a number is prime by testing if it is divisible by any number between 2 and its half. 2) A program that calculates the Fibonacci series for a given number by initializing 3 variables and iteratively calculating the next value. 3) A program that checks if a character is a vowel by using a switch statement to compare the character to the vowels. 4) A program that reverses an input number, calculates the sum of its digits, and displays both the reversed number and sum. 5) A program that uses a foreach loop to iterate through and print out elements of a string

Uploaded by

dsdfregthyju
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

Prime no.

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace prime_1
{
class Program
{
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:
fibonacci series:

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace fibonacci710
{
class Program
{
static void Main(string[] args)
{
int n1 = 0, n2 = 1, n3, i, number;
Console.Write("Enter the number : ");
number = int.Parse(Console.ReadLine());
Console.Write(n1 + " " + n2 + " ");
for (i = 2; i < number; ++i)
{
n3 = n1 + n2;
Console.Write(n3 + " ");
n1 = n2;
n2 = n3;
Console.ReadLine();

}
}
}
}

output:
vowel or not:
code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace vowel
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a Alphabet:");
char ch = Convert.ToChar(Console.ReadLine().ToLower());
switch (ch)
{
case 'a':
Console.WriteLine("It is vowel");
break;
case 'i':
Console.WriteLine("It is vowel");
break;
case 'o':
Console.WriteLine("It is vowel");
break;
case 'u':
Console.WriteLine("It is vowel");
break;
case 'e':
Console.WriteLine("It is vowel");
break;
default:
Console.WriteLine("It Is Not Vowel");
break;
}
Console.ReadLine();
}
}

output:
Reverse no. with its sum:
code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace reverse
{
class Program
{
static void Main(string[] args)
{
int number, sum = 0;
Console.WriteLine("Enter a number:");
number = int.Parse(Console.ReadLine());
while (number != 0)
{
int m = number % 10;
number = number / 10;
sum = sum + m;
}
Console.WriteLine("Sum of digits of the number:" + sum);
Console.ReadLine();

int reverse = 0;

while (number != 0)
{
reverse = reverse * 10;
reverse = reverse + number % 10;
number = number / 10;
}
Console.WriteLine("Reversed Number is:" + reverse);
Console.ReadLine();

}
}
}
output:

for each loop:


code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace reverse
{
class Program
{
static void Main(string[] args)
{
string[] fruits = { "ciwi", "mango", "banana", "grapes"};
foreach (string value in fruits)
{
Console.WriteLine(value);
}
Console.ReadLine();

}
}
}
output:

Create a application that receive the (Student id, Student name ,course name ,date of
birth) information from a set of student the application should also display the
information of all the student once the data entered.

You might also like