0% found this document useful (0 votes)
878 views

Que1. Print Ascii Value of Characters From A' To Z'.: Using Using Using Namespace Class Public Static Void

The document contains 8 code examples that demonstrate various operations: 1. Printing the ASCII values of characters from A-Z 2. Generating a random number between 0-10 3. Greeting a user with Mr. or Miss based on their gender 4. Checking if a number is an Armstrong number 5. Generating a numerical series with an increasing/decreasing pattern 6. Printing a triangle of stars of a given size 7. Extracting the first 4 characters of a user's name 8. Checking if a string is a palindrome

Uploaded by

bhavnas17
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
878 views

Que1. Print Ascii Value of Characters From A' To Z'.: Using Using Using Namespace Class Public Static Void

The document contains 8 code examples that demonstrate various operations: 1. Printing the ASCII values of characters from A-Z 2. Generating a random number between 0-10 3. Greeting a user with Mr. or Miss based on their gender 4. Checking if a number is an Armstrong number 5. Generating a numerical series with an increasing/decreasing pattern 6. Printing a triangle of stars of a given size 7. Extracting the first 4 characters of a user's name 8. Checking if a string is a palindrome

Uploaded by

bhavnas17
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Que1. Print Ascii value of Characters from ‘A’ to ‘Z’.

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

namespace ConsoleApplication2
{
class ASCII
{
public static void Main()
{
Console.WriteLine("Characters ASCII Value");
for (int i = 65; i <= 90; i++)
{
Console.WriteLine((char)i + " " + i);
}
Console.Read();

}
}
}

Que2. Print Random Number Between 0 to 10.


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

namespace ConsoleApplication2
{
class RandomNumber
{
public static void Main()
{
Console.Write("A random number between 0 to 10 is : ");
Random ob = new Random();
Console.Write(ob.Next(11));
Console.Read();
}
}
}

Que3. Print Mr. or Miss with Name according to the Gender Entered by the User.
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter Your First Name : ");
string aa = Console.ReadLine().ToString();
Console.Write("Enter Your Last Name : ");
string bb = Console.ReadLine().ToString();
Console.Write("Enter Your Gender (M/F) : ");
char gg = Convert.ToChar(Console.ReadLine());
Console.WriteLine();
Console.WriteLine();
if (gg == 'M' || gg == 'm')
Console.WriteLine("Welcome Mr. " + aa + " " + bb);
else if (gg == 'F' || gg == 'f')
Console.WriteLine("Welcome Miss. " + aa + " " + bb);
else
Console.WriteLine("Error : Gender should be M or F. ");

Console.Read();

}
}
}
Que4. Check Number is Armstrong or Not.
(Example : Take 153. Then 1³+5³+3³ = 153. thus Armstrong number.)
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Armstrong
{
public static void Main()
{
Console.Write("Enter any Nubmer to check its Armstrong or not : ");
int aa = Convert.ToInt32(Console.ReadLine());
int n=aa,s=0,t;
while (n > 0)
{
t = n % 10;
n = n / 10;
s = s + (t * t * t);
}
if (s == aa)
Console.WriteLine("The Number {0} is Armstrong.", aa);
else
Console.WriteLine("The Number {0} is not Armstrong.", aa);
Console.Read();
}
}
}

Que5. Generate Series 2,4,3,5,4,6,5,7,6,8,7,9,8,10,9,11,10,…for 20 numbers.


(Help : This Series has a pattern of firstlty increase number by 2 and then decrease next by 1)

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

namespace ConsoleApplication2
{
class Series
{
public static void Main()
{
int i = 2;
Console.Write(i + " ");
for (int a = 1; a <= 10; a++)
{
i=i+2;
Console.Write(i + " ");
i=i-1;
Console.Write(i + " ");
}
Console.Read();
}
}
}

Que6. Generate the Star in form of Equilateral Triangle.


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

namespace ConsoleApplication2
{
class Stars
{
public static void Main()
{
Console.Write("Enter any Number : ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();

for (int i = 1; i <=n; i++) //This loop works for no. of lines
{
for (int j = 1; j <= n-i; j++) //This loop gives the spaces
Console.Write(" ");
for (int k = 1; k <=i; k++) //This loop prints the stars
{
Console.Write("* ");
}
Console.WriteLine();
}
Console.Read();
}
}
}

Que7. Print the First Four Characters of Any Name Entered by the User.
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Substring
{
public static void Main()
{
Console.Write("Enter Your Name : ");
string ss = Console.ReadLine();
Console.WriteLine();
Console.Write("First four character of the Entered name are : " + ss.Substring(0, 4));
Console.Read();
}
}
}

Que8. Find if the entered string is Palindrome or Not.


(Example : Take Malayalam is Palindrome. When read from left to right or right
to left its same)

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

namespace ConsoleApplication2
{
class Palindrone
{
public static void Main()
{
Console.Write("Enter any Sting to Check it's Palindrome or not : ");
char[] ch = new char[30];
ch = Console.ReadLine().ToCharArray();
int a=ch.Length , flag=1;
for (int i = 0,j = a-1 ; i < j ; i++, j--)
{
if (ch[i] != ch[j])
{
flag = 0;
break;
}
}
if (flag == 0)
Console.WriteLine("Sting Not Palindrome.");
else
Console.WriteLine("Sting is Palindrome.");
Console.Read();
}
}
}

You might also like