Академический Документы
Профессиональный Документы
Культура Документы
using System;
namespace palindrome
{
class Program
{
static void Main(string[] args)
{
string s, revs = "";
Console.WriteLine(" Enter string");
s = Console.ReadLine();
for (int i = s.Length - 1; i >= 0; i--) //String Reverse
{
revs += s[i].ToString();
}
if (revs == s) // Checking whether string is palindrome or not
{
Console.WriteLine("String is Palindrome \n Entered String Was {0} and
reverse string is {1}", s, revs);
}
else
{
Console.WriteLine("String is not Palindrome \n Entered String Was {0} and
reverse string is {1}", s, revs);
}
Console.ReadKey();
}
}
}
2. WAP to demonstrate the concepts of properties and indexers.
using System;
namespace IndexerApp
{
class IndexedNames
{
private string[] namelist = new string[size];
static public int size = 10;
public IndexedNames()
{
for (int i = 0; i < size; i++)
namelist[i] = "N. A.";
}
public string this[int index]
{
get
{
string tmp;
return (tmp);
}
set
{
if (index >= 0 && index <= size - 1)
{
namelist[index] = value;
}
}
}
static void Main(string[] args)
{
IndexedNames names = new IndexedNames();
names[0] = "Himanshu";
names[1] = "Kumar";
names[2] = "Vibhav";
names[3] = "Rathore";
names[4] = "Hardik";
using System;
using System.Collections.Generic;
namespace Genericlist
{
public class Program
{
public static void Main(string[] args)
{
//Adding Item
List<string> myList = new List<string>();
myList.Add("Himanshu");
myList.Add("Abhishek");
myList.Add("kamal");
//Printing Item
foreach (string s in myList)
Console.Write(s.ToString() + " ");
//Sorting List
myList.Sort();
Console.WriteLine("\n After Sorting");
foreach (string s in myList)
Console.Write(s.ToString() + " ");
//Removing Items
myList.Remove("Abhishek");
Console.WriteLine("\nRemoving Abhishek");
foreach (string s in myList)
Console.Write(s.ToString() + " ");
4. Write a program to input a string through keyboard and display the number
of vowels.
using System;
namespace vowels
{
public class vowel
{
public static void Main()
{
string str;
int i, len, vowel;
vowel = 0;
len = str.Length;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Date_and_Time
public Form1()
{
InitializeComponent();
timer1.Start();
label1.Text = DateTime.Now.ToLongTimeString();
label2.Text = DateTime.Now.ToLongDateString();
label1.Text = DateTime.Now.ToLongTimeString();
timer1.Start();
using System;
class ReverseString
{
else
{
Console.Write(str[str.Length - 1]);
reverse(str.Substring(0, (str.Length - 1)));
}
}
}
}
8. Create a stack class called stack that can hold characters. Call the methods
that access the stack Push() and POP(). Allow the user to specify the size of
the stack when it is created.
using System;
class Stack
int num;
if(top==size-1)
Console.WriteLine("Stack if full.");
else{
num=int.Parse(Console.ReadLine());
top+=1;
stk[top]=num;
if(top==-1)
Console.WriteLine("Stack if empty.");
else{
top-=1;
Console.WriteLine("Stack is : ");
for(int i=top;i>=0;i--){
Console.WriteLine(stk[i]);
stk=new int[size];
int ch=0;
while(ch!=4){
ch=int.Parse(Console.ReadLine());
switch(ch){
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;