Sei sulla pagina 1di 127

C# SYNTAX

======================= ===== ======= =========


Using functions
================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
========================
STRING
========================
------------------------Declare string
===============
string h = string("");
count of distinct or unique characters in string
==================================================
int uniqueCharacterCount = input1.Distinct().Count();
count of characters in string
==============================
int CharacterCount = input1.Count();
show only unique chracters in string
=======================================
string[] answer = new String(input1.Distinct().ToArray());
even or odd
=============
(input1 % 2) == 0
convert negative to positive number
===================================
input1 = input*(-1)
integer with point
==================
eg) 3.14
double PI = 3.14

store each letter from a word in array


======================================
char[] chr = input1.ToCharArray();
store to a array from string delimited by space
===============================================
string[] str = input1.Split(' ');
character array to string
==========================
string s = new string(chars);
each word capital
=================
s =
System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(input1.ToLo
wer ());

ARRAY
======
Declaration
============
int[] n=new int[] {1,2,3,5,6,9,7};
Reverse an array - apdiye reverse panum.. ex) ip = {1 5 3}, op = {3 5 1}
=================
Array.Reverse(chr);
SORT in ARRAY
=============
Array.Sort(input1); - ascending order la sort pannum..ex) ip = {1 5 3}, op = {1 3 5}
Average in ARRAY
===================
output1 = input1.Average();
store in a new string
=====================
string temp = new string(chr);
substring
=========
string output = temp.Substring(2, 1);
stringbuilder string builder

================================
StringBuilder sb = new StringBuilder();
append in stringbuilder
========================
string s = input1.Substring(i, 2);
sb.Append(s[1]);
to take exact input as date via bool flag
=========================================
bool flag = DateTime.TryParseExact(input1, "MM-dd-yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
day of week
============
output = dt.DayOfWeek.ToString();
variable for date time
======================
DateTime dt1, dt2;
difference in date&time
====================
TimeSpan t = dt1 - dt2;
for loop
========
for(int i=0;i<temp.Length-1;i++){}
check the XXX-XXX-XXXX format
==============================
take substring of the input1,
check if ch[3] && ch[7] =='-'
for each statement
==================
foreach(var i in input1)
Lower case or Upper Case
========================
input1=input1.ToLower();
input1=input1.ToUpper();
count of digits in a string
===========================
var count = jobId.Count(Char.IsDigit);
count of alphabets in a character
================================
var count = myString.Count(char.IsLetter);
Check if ALPHABETS only in string
=================================

int strlen = input1.Length;


var totchar = input1.Count(Char.IsLetter);
if( strlen == totchar )
DATE TIME
=========
DateTime dt1 = Convert.ToDateTime(input1);
TimeSpan diff = dt2 - dt1;
Change this to string to display in the console output
LIST
====
DECLARE LIST IN STATIC VOID MAIN
=================================
List<string> input1 = new List<string> { "reading", "write", "edit", "reading1"};
Program.arraylist(input1);
DECLARE LIST IN PUBLIC STATIC VOID MAIN
=======================================
public static void arraylist(List<string> input1)
STRING TO LIST
==============
var names = "Brian,Joe,Chris";
List<string> result = names.Split(',').ToList();
NEW LIST
========
List<string> output1 = new List<string>();
LIST -check if number 2 is present in the "list1"
=================================================
list1.Contains(2)
LIST - remove 2 from the list
=============================
list1.Remove(2);
LIST - Sort the list elements in ascending order
==============================================
list1.Sort();
LIST - - apdiye reverse panum..
=======
list1.Reverse();
LIST - Sort the list elements in ascending order - ACCORDING TO LENGTH
=====================================================
=================

l1 = l1.OrderBy (x => x.Length).ToList();


LIST - Sort the list elements in Descending order - ACCORDING TO LENGTH
=====================================================
=================
l1 = l1.OrderByDescending (x => x.Length).ToList();
LIST - Insert an element in the position 4 of list
===================================================
list1.Insert(4, "Harinath");
LIST to STRING
==============
var result = String.Join(",", names.ToArray());
PARTICULAR ELEMENT IN THE LIST
===============================
list1[0]
ADD TO LIST
===========
output1.Add(input1[i]);
i th element of input1 will be added to output1
ARRAY LIST
==========
DECLARE ArrayList IN STATIC VOID MAIN
=================================
ArrayList input1 = new ArrayList {2,4,5,1,9,3,8};
Program.h(input1);
DECLARE ARRAYLIST IN PUBLIC STATIC VOID MAIN
=======================================
public static void h(ArrayList input1)
NEW ARRAYLIST
=============
ArrayList output1 = new ArrayList();
Array
=====
Sort by Length
---------------

test = (string[])SortStringLength(test);

public static void sumcalc(int input1)


{
int n;
int sum=0;
while (input1 != 0)
{
n = input1 % 10;
if (n % 2 == 0)
{
sum = sum + (n * n);
}
else
{
sum = sum + (n * n * n);
}
input1 = input1 / 10;
}
Console.WriteLine(sum);
}
#########
public static void removeten(int[] input1)
//
{
//
int[] output1=new int[input1.Length];
//
int[] output2=new int[input1.Length];
//
int k=0;
//
for (int i = 0; i < input1.Length; i++)
//
{
//
output2[i] = 0;
//
}
//for (int i = 0; i < input1.Length; i++)
//
{
//
if (input1[i] == 10)
//
{
//
//
//

}
else
{

//
output2[k++] = input1[i];
//
}
////
}
#################
replace with *
==========
public static void usestars(string input1, int input2, string input3)
{
//input1 = HI HOW are you Ram input2 = 3, input3 = *, output= hi how *** you
ram(all in lower case)
string[] str = input1.Split(' ');
int strlen = str[input2 - 1].Length;

string strstarlens = new string('*', strlen);


input1 = input1.Replace(str[input2 - 1], strstarlens);
Console.WriteLine(input1.ToLower());
}
static void Main(String[] args)
{
Program.usestars("HI HOW are you Ram",3,"*");
}
}
############################
Programs
{
class StringsStartingWith
{
public static List<string> output1;
public static void CountStringsStartingWith(List<string> input1, char input2)
{
output1 =
new List<string>();
int count = 0;
foreach (string item in input1)
if (item.StartsWith(input2.ToString(), true, null))
count++;
if(count == 0)
{
output1.Add(
"-1");
}
else
{
foreach (string item in input1)
if (item.StartsWith(input2.ToString(), true, null))
{
string itemWithCount = item + "_" + count;
output1.Add(itemWithCount);
}
}
}
public static void PrintOutput()
{
List<string> input1 = new List<string>() { "Aapti", "Amrita", "Arko", "Pritha", "Ankit",
"Shrri" };
char input2 = 'a';
CountStringsStartingWith(input1, input2);
foreach(string item in output1)
Console.WriteLine(item);
}
}
}
###################################
public static void xmlread()
{
string n =

"<Names><Name><FirstName>John</FirstName><LastName>Smith</LastName></N
ame><Name><FirstName>James</FirstName><LastName>White</LastName></Nam
e></Names>";
string output;
StringBuilder sb1 = new StringBuilder();
//StringBuilder sb2 = new StringBuilder();
using (StringReader rdr=new StringReader(n))
{
using (XmlTextReader xrdr = new XmlTextReader(rdr))
{
while (xrdr.Read())
{
if (xrdr.IsStartElement())
{
switch (xrdr.Name)
{
case "FirstName":
sb1.Append(xrdr.ReadString());
break;
case "LastName":
sb1.Append(xrdr.ReadString());
break;
}
}
sb1.Append(" ");
}
output = sb1.ToString();
Console.WriteLine(output);
}

}
public static void xmlreadfemale()
{
string s = "<Names><Name type='M'>Arun Karthick</Name><Name
type='M'>Vamsee</Name><Name type='F'>Priya</Name></Names>";
XmlDocument xd = new XmlDocument();
xd.LoadXml(s);
XmlNodeList xn = xd.SelectNodes("/Names/Name[@type='F']");
foreach (XmlNode item in xn)
{
// Console.WriteLine(item.Name);
Console.WriteLine(item.InnerText);
// Console.Write(item.Value);
}
}
######################
static void Main(string[] args)
{
string s = "as-df-gh";
string w = "sd-er-tyuhjh-";

char[] ch = s.ToCharArray(); int n = 0, m = 0, count = 0;


char[] ch1 = w.ToCharArray();
List<int> l = new List<int>();
List<int> l1 = new List<int>();
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == '-')
{
n = n + 1;
l.Add(i);
}
}
for (int j = 0; j < ch1.Length; j++)
{
if (ch1[j] == '-')
{
m = m + 1;
l1.Add(j);
}
}
if (m == n)
{
int[] ar = l.ToArray();
int[] a = l1.ToArray();
for (int k = 0; k < n; k++)
{
if (ar[k] == a[k])
count = count + 1;
}
if (count == m)
Console.WriteLine("1");
else
Console.WriteLine("-1");
}
else
Console.WriteLine("-2");
Console.ReadKey();
}
}
}
####################
1. Add Days to date
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace finaladddaystodate
{
class Program
{
public static void adddays (int input1,string input2)
{
int i = 0;

string output1;
char[] result = new char[input2.Length];
DateTime dt = new DateTime();
if (input1 < 0)
{
output1 = "-2";
Console.WriteLine(output1);
}
else
{
Regex eg = new Regex(@"^(0[1-9]|1[012])[/](0[1-9]|1[0-9]|2[0-9]|3[01])[/]
((19|20)\d\d)$");
if (eg.IsMatch(input2))
{
DateTime date = Convert.ToDateTime(input2);
dt = date.AddDays(input1);
string s = Convert.ToString(dt);
while (s[i] != ' ')
{
result[i] = s[i];
i++;
}
output1 = new string(result);
Console.WriteLine(output1);
}
else
{
output1 = "-1";
Console.WriteLine(output1);
}
}
}
static void Main(string[] args)
{
Program.adddays(5, "12/12/2012");
}
}
}
2.Circle
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalareaofcircle
{
class Program
{
public static void circle(char input1,double input2)
{
const double pi = 3.14;
double output1;
if(input2 <0)
{
output1=-1;

Console.WriteLine(output1);
}
else
{
switch (input1)
{
case 'A':
double area = pi * input2 * input2;
output1 = area;
Console.WriteLine(output1);
break;
case 'C':
double circumference = 2 * pi * input2;
output1 = circumference;
Console.WriteLine(output1);
break;
case 'D':
double diameter = 2 * input2;
output1 = diameter;
Console.WriteLine(output1);
break;
default:
output1 = 0;
Console.WriteLine(output1);
break;
}
}
}
static void Main(string[] args)
{
Program.circle('A',2);
}
}
}
3.Ascii Values
A String contain a Character. Find the character entered.
// -> (A-Z) ASCII Value (65-90) ->Output is "The character entered is a CAPITAL
ALPHABET"
// -> (a-z) ASCII Value(97-122) ->Output is "The character entered is a small
ALPHABET"
// -> (0-9) ASCII Value(48-57) ->Output is "The character entered is a Number"
// ->Any special symbol - ASCII Value(0-47,58-64,91-96,123-127) ->Output is "The
character entered is a special symbol"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalAscii
{
class Program
{
public static void ascii(string input1)
{

string output1;
char[] ch = input1.ToCharArray();
int i = 0;
int flag = 0;
for (i = 0; i < ch.Length; i++)
{
if (ch[0] >= 65 && ch[0] <= 90)
{
flag = 0;
}
else if (ch[0] >= 97 && ch[0] <= 122)
{
flag = 1;
}
else if (ch[0] >= 48 && ch[0] <= 57)
{
flag = 2;
}
else if ((ch[0] >= 0 && ch[0] <= 47) || (ch[0] >= 58 && ch[0] <= 64) || (ch[0]
>= 91 && ch[0] <= 96) || (ch[0] >= 123 && ch[0] <= 127))
{
flag = 3;
}
}
if (flag == 0)
{
output1 = "The character entered is a CAPITAL ALPHABET";
Console.WriteLine(output1);
}
else if (flag == 1)
{
output1 = "The character entered is a small ALPHABET";
Console.WriteLine(output1);
}
else if (flag == 2)
{
output1 = "The character entered is a Number";
Console.WriteLine(output1);
}
else if (flag == 3)
{
output1 = "The character entered is a special symbol";
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.ascii("A");
}
}
}
4.Average in list
using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;
namespace finalaverageinlist
{
class Program
{
public static void average(List<int> input1)
{
int count = input1.Count();
int count1=0;
double output1;
foreach (var b in input1)
{
if (b > 0)
{
count1++;
}
}
if (count == count1)
{
output1 = input1.Average();
Console.WriteLine(output1);
}
else
{
output1 = -1;
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
List<int> n = new List<int>() { 1, 2, 3, 4, 5, 6 };
Program.average(n);
}
}
}
5.Count vowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalcountvowel
{
class Program
{
public static void countvowel(string input1)
{
char[] ch = input1.ToCharArray();
int count = input1.Length;
int count1=0;
int count2 = 0;
int output1;
foreach (var b in ch)
{

if ((b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b == ' '))
{
count1++;
}

}
if (count == count1)
{
for (int i = 0; i < input1.Length; i++)
{
if (ch[i] == 'a' || ch[i] == 'A')
{
count2++;
}
else if (ch[i] == 'e' || ch[i] == 'E')
{
count2++;
}
else if (ch[i] == 'i' || ch[i] == 'I')
{
count2++;
}
else if (ch[i] == 'o' || ch[i] == 'O')
{
count2++;
}
else if (ch[i] == 'u' || ch[i] == 'U')
{
count2++;
}
}
output1 = count2;
Console.WriteLine(output1);
}
else
{
output1 = -1;
Console.WriteLine(output1);
}

}
static void Main(string[] args)
{
Program.countvowel("temple");
}
}
}
6.Credit car number or not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace final_credit_card
{
class Program

{
public static void creditcard(string input1)
{
int output1;
Regex eg = new Regex(@"^(([0-9][0-9][0-9][0-9])[-]([0-9][0-9][0-9][0-9])[-]([0-9]
[0-9][0-9][0-9])[-]([0-9][0-9][0-9][0-9]))$");
if (eg.IsMatch(input1))
{
output1 = 1;
Console.WriteLine(output1);
}
else
{
output1 = 0;
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.creditcard("1234-5678-1237-5679");
}
}
}
7.Date format check
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace finalDateformatcheck
{
class Program
{
public static void check(string input1)
{
int output1;
Regex eg = new Regex(@"^(0[1-9]|1[012])[/](0[1-9]|1[0-9]|2[0-9]|3[01])[/]((19|
20)\d\d)$");
if(eg.IsMatch(input1))
{
output1=1;
Console.WriteLine(output1);
}
else
{
output1 = 0;
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.check("12/12/2012");
}

}
}
8.Dice
2,3,6,11 1000
4,7,10 3000
5,8,9,12 5000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalDice
{
class Program
{
public static void dice(int input1, int input2)
{
int output1;
if (input1 < 0 || input2 < 0)
{
output1 = -1;
Console.WriteLine(output1);
}
else
{
int sum = input1 + input2;
if (sum == 2 || sum == 3 || sum == 6 || sum == 11)
{
output1 = 1000;
Console.WriteLine(1000);
}
else if (sum == 4 || sum == 7 || sum == 10)
{
output1 = 3000;
Console.WriteLine(output1);
}
else if (sum == 5 || sum == 8 || sum == 9 || sum == 12)
{
output1 = 5000;
Console.WriteLine(output1);
}
}
}
static void Main(string[] args)
{
Program.dice(3, 2);
}
}
}
9.First letter capital
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace finalFirstletterchoose
{
class Program
{
public static void firstletterchoose(string input1)
{
char[] ch = " ".ToCharArray();
string[] s = input1.Split(ch);
StringBuilder sb = new StringBuilder();
foreach (var f in s)
{
sb.Append(f[0].ToString().ToUpper());
for (int i = 1; i < f.Length; i++)
{
sb.Append(f[i]);
}
sb.Append(' ');
}
string output1 = sb.ToString();
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.firstletterchoose("tarun ananda mohan");
}
}
}
10.monthly wages
Input: No. of hours to be input(double input;)
//Program: If input==200, 1 hr pays u Rs.100
// ---------------> 200, 1hr of overtime pays u Rs. 150
// ---------------< 200, penalty of Rs. 25 per hr is to deducted
//Validation: Salary should nt be greater than Rs. 25000.00;
//Round the salary off to 2 decimal places.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalmonthlywages
{
class Program
{
public static void wages(double input1)
{
double output1 = 0.00d;
double wage = 0.00d;
if (input1 > 200)
{
wage = input1 * 100.00 + ((input1 - 200) * 150.00);
}
else if (input1 < 200)
{
wage = input1 * 100.00 - ((input1 - 200) * 75.00);
}

else
{
wage = input1 * 100.00;
}
if (wage == 25000.00)
{
output1 = 25000.00;
Console.WriteLine(output1);
}
else if (wage > 25000.00)
{
output1 = 25000.00;
Console.WriteLine(output1);
}
else
{
output1=wage;
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.wages(250);
}
}
}
11.Nth largest element in array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalnthlargestelementinarray
{
class Program
{
public static void largestelement(int[] input1,int input2)
{
int count=input1.Length;
int count1=0;
int output1;
foreach (var b in input1)
{
if (b > 0)
{
count1++;
}
}
if (count == count1 && input2>=0)
{
Array.Sort(input1);
Array.Reverse(input1);
foreach (var b in input1)
{

Console.WriteLine(b);
}
output1 = input1[input2 - 1];
Console.WriteLine(output1);

}
else
{
output1 = -1;
Console.WriteLine(output1);
}

}
static void Main(string[] args)
{
int[] n=new int[] {1,2,3,5,6,9,7};
Program.largestelement(n,2);
}

}
}
12.Reverse a string without special character
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalreverse_a_string_without_sc
{
class Program
{
public static void reverse(string input1)
{
char[] ch = input1.ToCharArray();
int count = input1.Length;
int count1 = 0;
char[] sc;
int i=0;
foreach (var b in ch)
{
if ((b>='A' && b<='Z') || (b>='a' && b<='z') || (b==' ') || (b>='1' && b<='9'))
{
count1++;
}
}
sc = new char[count1];
foreach (var b in ch)
{
if ((b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b == ' ') || (b >= '1' && b
<= '9'))
{
sc[i] = b;
i++;
}
}
Array.Reverse(sc);
string output1 = new string(sc);
Console.WriteLine(output1);

}
static void Main(string[] args)
{
Program.reverse("temple22");
}
}
}
.0.69
13. for chennai AC-1800 perday
//HYD AC-1400 perday
//BANGALORE-1900 perday
//and NONAC"s
//C-800 perday
//H-900 perday
//B-1000 perday
//input== location and number of days
//output== number of days * room rent per day
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalroomrentofhotel
{
class Program
{
public static void roomrent(int input1, string input2, char input3)
{
int output1;
int rent;
if (input1 < 0)
{
output1 = 1;
Console.WriteLine(output1);
}
else
{
if (input2 == "AC")
{
switch (input3)
{
case 'C':
rent = 1800 * input1;
output1 = rent;
Console.WriteLine(output1);
break;
case 'H':
rent = 1400 * input1;
output1 = rent;
Console.WriteLine(output1);
break;
case 'B':
rent = 1900 * input1;
output1 = rent;
Console.WriteLine(output1);

break;
default:
output1 = -1;
Console.WriteLine(output1);
break;
}
}
else if (input2 == "NON-AC")
{
switch (input3)
{
case 'C':
rent = 800 * input1;
output1 = rent;
Console.WriteLine(output1);
break;
case 'H':
rent = 900 * input1;
output1 = rent;
Console.WriteLine(output1);
break;
case 'B':
rent = 1000 * input1;
output1 = rent;
Console.WriteLine(output1);
break;
default:
output1 = -2;
Console.WriteLine(output1);
break;
}
}
else
{
output1 = 0;
Console.WriteLine(output1);
}
}
}
static void Main(string[] args)
{
Program.roomrent(5, "AC", 'C');
}
}
}
14.round number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalroundnumber
{
class Program
{

public static void round_number(double input1)


{
double output1;
output1 = Math.Round(input1, 2);
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.round_number(123.3456789);
}

}
}
15.search character in a string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalsearchcharacterinastring
{
class Program
{
public static void search(string input1, char input2)
{
int count = 0;
int output1;
char[] ch = input1.ToCharArray();
foreach (var b in ch)
{
if (b == input2)
{
count++;
}
}
output1 = count;
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.search("swetha", 'e');
}
}
}
16.simple interest
formula=(p * n * r)/100;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalsimpleinterest
{
class Program
{
public static void simpleinterest(double input1, double input2, double input3)
{

double output1;
output1 = (input1 * input2 * input3) / 100;
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.simpleinterest(20000, 2, 5);
}

}
}
17.sort array in ascending
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalsortarrayinascending
{
class Program
{
public static void sort(int[] input1)
{
int[] output1;
int count=input1.Length;
int count1=0;
foreach (var b in input1)
{
if (b > 0)
{
count1++;
}
}
if (count == count1)
{
output1 = new int[count];
Array.Sort(input1);
output1 = input1;
foreach (var b in output1)
{
Console.WriteLine(b);
}
}
else
{
output1 = new int[1];
output1[0] = -1;
Console.WriteLine(output1[0]);
}
}
static void Main(string[] args)
{
int[] n=new int[] {1,4,5,3,7,9};
Program.sort(n);
}
}

}
18.sum of squares
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace squareoffirstNnumber
{
class Program
{
public static void sumofsquare(int input1)
{
int output1=0;
for (int i = 1; i <= input1; i++)
{
output1 = output1 + (i * i);
}
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.sumofsquare(2);
}
}
}
19.sum of cubes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace squareoffirstNnumber
{
class Program
{
public static void sumofsquare(int input1)
{
int output1=0;
for (int i = 1; i <= input1; i++)
{
output1 = output1 + (i * i * i);
}
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.sumofsquare(2);
}
}
}
20.string reverse
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace finalstringreverse
{
class Program
{
public static void reverse(string input1)
{
string output1;
char[] ch = input1.ToCharArray();
Array.Reverse(ch);
output1 = new string(ch);
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.reverse("swetha");
}
}
}
21.student marks
take 5 subject marks and find total nd avg
// if avg >= 60 dn output1 ="First class"
// if avg >=50 and avg<= 59 dn output1= "second class"
// if avg >=40 and avg<= 49 dn output1 = "third class"
// else
//
output1 = "failed"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalstudentmarks
{
class Program
{
public static void marks(int input1, int input2, int input3, int input4, int input5)
{
string output1;
int total = input1 + input2 + input3 + input4 + input5;
int average = total / 5;
if (average >= 60)
{
output1 = "First Class";
Console.WriteLine(output1);
}
else if (average >= 50 && average <= 59)
{
output1 = "Second Class";
Console.WriteLine(output1);
}
else if (average >= 40 && average <= 49)
{
output1 = "Third Class";
Console.WriteLine(output1);
}

else
{
output1 = "Failed";
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.marks(88, 87, 89, 98, 99);
}

}
}
22.take home salary
Take Home Salary=salary-PF-medicalInsurance
PF
for sal<15000---750
sal between 15000 and 22000---850
sal between 22000 to 30000--925
salary above 30000--1000
medical insurance for all the employees is
678
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finaltakehomesalary
{
class Program
{
public static void salary(int input1)
{
int output1;
int pf;
int mi = 678;
if (input1 < 15000)
{
pf = 750;
output1 = input1 - pf - mi;
Console.WriteLine(output1);
}
else if (input1 >= 15000 && input1 <= 22000)
{
pf = 850;
output1 = input1 - pf - mi;
Console.WriteLine(output1);
}
else if (input1 >= 22000 && input1 <= 30000)
{
pf = 925;
output1 = input1 - pf - mi;
Console.WriteLine(output1);
}
else
{

pf = 1000;
output1 = input1 - pf - mi;
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.salary(22000);
}
}
}
23.telephone bill
Telephone bill
if call below 300 cost is 200
after for 50 calls cost is .60
after for 50 calls cost is .50
after for all calls cost is .40
ie 200+(x*.60)+(y*.50)+(z*.40)
calcualte the call cost
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finaltelephonebill
{
class Program
{
public static void bill(int input1)
{
double output1;
if (input1 <= 300)
{
output1 = 200;
Console.WriteLine(output1);
}
else if (input1 > 300 && input1 <= 350)
{
output1 = 200 + ((input1 - 300) * 0.60);
Console.WriteLine(output1);
}
else if (input1 > 350 && input1 <= 400)
{
output1 = 200 + (50 * 0.60) + ((input1 - 350) * 0.50);
Console.WriteLine(output1);
}
else if(input1>400)
{
output1 = 200 + (50 * 0.60) + (50 * 0.50) + ((input1 - 400) * 0.40);
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.bill(305);

}
}

}
24.find the element between the range and count
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalelementbetweentherange
{
class Program
{
public static void elements(int[] input1,int input2,int input3)
{
int count = 0;
int count1 = 0;
int[] output1;
int i = 0;
foreach (var b in input1)
{
if (b >= input2 && b <= input3)
{
count++;
}
}
output1 = new int[count];
foreach (var b in input1)
{
if (b >= input2 && b <= input3)
{
count1++;
output1[i] = b;
i++;
}
}
Console.WriteLine(count1);
foreach (var c in output1)
{
Console.WriteLine(c);
}
}
static void Main(string[] args)
{
int[] n = new int[] { 1, 2, 3, 5, 7, 5, 0, 9 };
Program.elements(n, 2, 7);
}
}
}
25.voting
find age and valid is eliglible for voting or not
input1 as date and input2 as string("MM/dd/yyyy")
date should in the format of input2 otherwise store output1=-1
if age is above 18 store output1=1 or if not valid ouput1=-2
should display only date(not with time)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace final_voting
{
class Program
{
public static void eligibleornot(string input1)
{
int output1;
Regex eg = new Regex(@"^(0[1-9]|1[012])[./-](0[1-9]|1[0-9]|2[0-9]|3[01])[./-]
((19|20)\d\d)$");
if(eg.IsMatch(input1))
{
Console.WriteLine("format is matched");
DateTime dt = Convert.ToDateTime(input1);
if (DateTime.Now.Year - dt.Year > 18)
{
Console.WriteLine("year is greater than 18");
output1 = 1;
Console.WriteLine(output1);
}
else if (DateTime.Now.Year - dt.Year == 18)
{
Console.WriteLine("year is equal to 18");
if(DateTime.Now.Month - dt.Month > 0)
{
Console.WriteLine("month is greater than zero");
output1 = 1;
Console.WriteLine(output1);
}
else if (DateTime.Now.Month - dt.Month == 0)
{
Console.WriteLine("month is equal to zero");
if (DateTime.Now.Day - dt.Day >= 0)
{
Console.WriteLine("day is equal or greater than zero");
output1 = 1;
Console.WriteLine(output1);
}
else
{
output1 = -2;
Console.WriteLine(output1);
}
}
else
{
Console.WriteLine("month is less than zero");
output1 = -2;
Console.WriteLine(output1);
}

}
else
{
Console.WriteLine("year is less than 18");
output1 = -2;
Console.WriteLine(output1);
}

}
else
{
Console.WriteLine("format is wrong");
output1 = -1;
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.eligibleornot("12/12/1995");
}

}
}
26.xmlfemale
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace finalxmlfemale
{
class Program
{
public static void xmlfemale(string input1)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(input1);
XmlNode node = xmldoc.DocumentElement;
StringBuilder sb = new StringBuilder();
foreach (XmlNode b in node.ChildNodes)
{
sb.Append(b.InnerText);
sb.Append(' ');
}
sb.Append("\n");
XmlNodeList list = xmldoc.SelectNodes("/Names/Name[@type='F']");
foreach(XmlNode n in list)
{
sb.Append(n.InnerText);
sb.Append(' ');
}
string output1 = sb.ToString();
Console.WriteLine(output1);
}
static void Main(string[] args)

{
string n = "<Names><Name type='F'>shweta</Name><Name
type='M'>sumit</Name><Name type='F'>pooja</Name></Names>";
Program.xmlfemale(n);
}
}
}
27.xml name
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace finalxmlname
{
class Program
{
public static void xmlname(string input1)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(input1);
XmlNode node=xmldoc.DocumentElement;
StringBuilder sb=new StringBuilder();
XmlNodeList list = xmldoc.SelectNodes("/Names/Name");
foreach (XmlNode n in list)
{
sb.Append(n["FirstName"].InnerText);
sb.Append(' ');
sb.Append(n["LastName"].InnerText);
sb.Append(' ');
}
string output1 = sb.ToString();
Console.WriteLine(output1);
}
static void Main(string[] args)
{
string n =
"<Names><Name><FirstName>John</FirstName><LastName>Smith</LastName></N
ame><Name><FirstName>James</FirstName><LastName>White</LastName></Nam
e></Names>";
Program.xmlname(n);
}
}
}
28.reversed string insert in the middle of another string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalstringinsert
{
class Program
{
public static void insert(string input1, string input2)

{
string output1;
int count = input1.Length;
if (count % 2 == 0)
{
char[] ch = input2.ToCharArray();
Array.Reverse(ch);
string reverse = new string(ch);
int middle=count/2;
output1 = input1.Insert(middle, reverse);
Console.WriteLine(output1);
}
else
{
output1 = "-1";
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.insert("swetha", "sabari");
}

}
}
29.calculate vat
If product =M
Vat= 5%
V
Vat=12%
C
Vat=6.25%
D
Vat=6%
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalcalculate_Vat
{
class Program
{
public static void vat(double input1, char input2)
{
double output1;
double percent;
double vat;
switch (input2)
{
case 'M':
percent = 5;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;

case 'V':
percent = 12;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
case 'C':
percent = 6.25;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
case 'D':
percent = 7;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
default:
output1 = -1;
Console.WriteLine(output1);
break;

}
}
static void Main(string[] args)
{
Program.vat(20000, 'M');
}

}
30.find the position of elements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finallinearsearch
{
class Program
{
public static void linearsearch(List<int> input1,int input2)
{
int output1;
int count = input1.Count();
output1 = input1.BinarySearch(input2);
Console.WriteLine(output1);
}
static void Main(string[] args)
{
List<int> n = new List<int>() { 1, 2, 5, 4, 9, 43 };
Program.linearsearch(n, 43);
}
}
}

31.linear search
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finallinearsearch
{
class Program
{
public static void linearsearch(List<int> input1,int input2)
{
int output1;
int count1 = 0;
int count = input1.Count();
foreach (var i in input1)
{
if (i == input2)
{
count1++;
}
}
output1 = count1;
Console.WriteLine(output1);
}
static void Main(string[] args)
{
List<int> n = new List<int>() { 1, 2, 5, 4, 9, 43 };
Program.linearsearch(n, 43);
}
}
}
32.compound interest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalcompoundinterest
{
class Program
{
public static void compoundinterest(double input1, double input2, double input3)
{
double output1;
double ci;
ci = input1 * Math.Pow(1 + input2 / 100, input3);
output1 = ci-input1;
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.compoundinterest(14500, 15, 2);
}
}
}

33.find hra
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace final_hra
{
class Program
{
public static void hra(double input1)
{
double output1;
double percent = 12;
output1 = input1 * (percent / 100);
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.hra(25000);
}
}
}
34.split cognizant technology solutions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalsplitingword
{
class Program
{
public static void split(string input1)
{
char[] ch = " ".ToCharArray();
string[] s = input1.Split(ch);
StringBuilder sb = new StringBuilder();
foreach (var f in s)
{
sb.Append(f[0].ToString().ToUpper());
sb.Append(' ');// optional
}
string output1 = sb.ToString();
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.split("cognizant technology solutions");
}
}
}
35.common elements in lists
36.armstrong number or not
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace armstrong_no
{
class Program
{
public static void armstrong(int input1)
{
string s = input1.ToString();
int count = s.Length;
int num = 0;
double sum = 0;
for (int i = input1; i > 0; i = i / 10)
{
num = i % 10;
sum = sum + Math.Pow(num, count);
}
int output1;
if (sum == input1)
{
output1 = 1;
Console.WriteLine(output1);
}
else
{
output1 = 0;
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.armstrong(1634);
}
}
}
37.primeno or not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalprime
{
class Program
{
public static void prime(int input1)
{
int output1;
int count = 0;
for (int i = 2; i < input1; i++)
{
if (input1 % i == 0)
{
count++;

}
}
if (count == 0)
{
output1 = 1;
Console.WriteLine(output1);
}
else
{
output1 = 0;
Console.WriteLine(output1);
}

}
static void Main(string[] args)
{
Program.prime(3);
}

}
}
38.sum of digits
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalsumofdigits
{
class Program
{
public static void sum(int input1)
{
int b=0;int c=0;
do{
b=input1%10;
c=c+b;
input1=input1/10;
}while(input1>0);
int output1=c;
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.sum(12343);
}
}
}
39.count the string without special characters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalstringcount
{
class Program
{

public static void count(string input1)


{
char[] ch = input1.ToCharArray();
int count = 0;
foreach (var c in ch)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '1' && c <= '9') || (c
== ' '))
{
count++;
}
}
int output1 = count;
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.count("welcome to c#");
}
}
}
40.swap two numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace final_swap
{
class Program
{
public static void swap(int input1, int input2)
{
int output1;
int output2;
input1 = input1 + input2;
input2 = input1 - input2;
input1 = input1 - input2;
output1 = input1;
output2 = input2;
Console.WriteLine(output1);
Console.WriteLine(output2);
}
static void Main(string[] args)
{
Program.swap(2, 3);
}
}
}
41.reverse a string in a string array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalindividualstringreverse

{
class Program
{
public static void reverse(string[] input1)
{
string[] output1=new string[input1.Length];
int i=0;
foreach (var f in input1)
{
int count=f.Length;
char[] ch = f.ToCharArray();
Array.Reverse(ch);
string s = new string(ch);
output1[i] = s;
i++;
}
foreach (var g in output1)
{
Console.WriteLine(g);
}
}
static void Main(string[] args)
{
string[] n = { "swetha", "iswarya", "hema" };
Program.reverse(n);
}
}
}
42.display last letter in a string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace final_last
{
class Program
{
public static void last(string input1)
{
char[] ch = " ".ToCharArray();
string[] s = input1.Split(ch);
StringBuilder sb = new StringBuilder();
foreach (var f in s)
{
int count = f.Length;
sb.Append(f[count - 1].ToString());
sb.Append(' ');
}
string output1 = sb.ToString();
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.last("anu sha");

}
}

}
43.difference in date and time
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace final_difference
{
class Program
{
public static void diff1(string input1,string input2)
{
DateTime dt1 = Convert.ToDateTime(input1);
DateTime dt2 = Convert.ToDateTime(input2);
TimeSpan diff = dt2 - dt1;
string output1 = diff.ToString();
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.diff1("12/12/2000", "12/12/2012");
}
}
}
44.factorial number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalfactorial
{
class Program
{
public static void factorial(int input1)
{
int fact = 1;
for (int i = 1; i <= input1; i++)
{
fact = fact * i;
}
int output1 = fact;
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.factorial(5);
}
}
}
45.odd and even(count)
using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;
namespace finaloddoreven
{
class Program
{
public static void oddoreven(int[] input1)
{
int count = 0; int count1 = 0;
foreach (var c in input1)
{
if (c % 2 == 0)
{
count++;
}
else
{
count1++;
}
}
int output1 = count;
Console.WriteLine(output1);
int output2 = count1;
Console.WriteLine(output2);
}
static void Main(string[] args)
{
int[] n = new int[] { 1, 2, 3, 4, 5, 7 };
Program.oddoreven(n);
}
}
}
46.display string having maximum character in string array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace final_max_character
{
class Program
{
public static void maximum(string[] input1)
{
int f=0;
int i;
int e=0;
for(i=0;i<input1.Length;i++)
{
if (input1[i].Length > f)
{
f = input1[i].Length;
e = i;
}

}
string output1 = input1[e];
Console.WriteLine(output1);
}
static void Main(string[] args)
{
string[] n=new string[] {"swetha","iswarya","hema"};
Program.maximum(n);
}
}
}
47.increasing number or not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace increasingnumber
{
class Program
{
public static void increasingnumber(int input1)
{
string s=input1.ToString();
int count=s.Length;
int count1=0;
int f=0;
int output1;
foreach (var c in s)
{
if (c > f)
{
f = c;
count1++;
}
}
if (count == count1)
{
output1 = 1;
Console.WriteLine(output1);
}
else
{
output1 = 0;
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.increasingnumber(12345);
}
}
}
48.first and last special character

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace hmstringspecialcharacter
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter The String");
string input = Console.ReadLine();
int count = input.Length;
int count1 = 0;
int count2 = 0;
int output;
char[] ch = input.ToCharArray();
if (!(ch[0] >= 'a' && ch[0] <= 'z'))
{
if (!(ch[0] >= 'A' && ch[0] <= 'Z'))
{
if (!(ch[0] >= '1' && ch[0] <= '9'))
{
if (!(ch[0] == ' '))
{
Console.WriteLine("First Character Is A Special Character");
}
else
{
Console.WriteLine("First Character Is A Space");
count1++;
}
}
else
{
Console.WriteLine("First Character Is A Number");
count1++;
}
}
else
{
Console.WriteLine("First Character Is A Capital Character");
count1++;
}
}
else
{
Console.WriteLine("First Character Is A Small Character");
count1++;
}
if (!(ch[count - 1] >= 'a' && ch[count - 1] <= 'z'))
{

if (!(ch[count - 1] >= 'A' && ch[count - 1] <= 'Z'))


{
if (!(ch[count - 1] >= '1' && ch[count - 1] <= '9'))
{
if (!(ch[count - 1] == ' '))
{
Console.WriteLine("Last Character Is A Special Character");
}
else
{
Console.WriteLine("Last Character Is A Space");
count2++;
}
}
else
{
Console.WriteLine("Last Character Is A Number");
count2++;
}
}
else
{
Console.WriteLine("Last Character Is A Capital Character");
count2++;
}
}
else
{
Console.WriteLine("Last Character Is A Small Character");
count2++;
}
if (count1 == 0 && count2 == 0)
{
output = 1;
Console.WriteLine("First And Last Characters Are Special Character So Output
Is 1");

Console.WriteLine(output);
}
else if (count1 != 0 && count2 != 0)
{
output = 0;
Console.WriteLine("First And Last Characters Are Not Special Character So
Output Is 0");
Console.WriteLine(output);
}
else if (count1 == 0 && count2 != 0)
{
output = -1;
Console.WriteLine("First Is A Special Character And Last Character Is Not A
Special Character So Output Is -1");

Console.WriteLine(output);
}
else if (count1 != 0 && count2 == 0)
{
output = -2;
Console.WriteLine("First Is A Not A Special Character And Last Character Is A
Special Character So Output Is -2");
Console.WriteLine(output);
}
}
}
}
###########
1.//counting the charachters int hte given string array
public void councharinstring(string[] inpit1)
{
int count = 0;
foreach (var c in inpit1)
{
count = count + c.Length;
}
Console.WriteLine(count);
}
2.//finding the smallest string in the given string array
public void smalllengthstring(string[] input1)
{
string output1=input1[0];
int min = input1[0].Length;
foreach (var c in input1)
{
if (min > c.Length)
output1 = c;
}
Console.WriteLine(output1);
}
3.//convertinh roman to integer
public void inttoroman(string input1)
{
NameValueCollection c = new NameValueCollection();
c.Add("I","1");
c.Add("V","5");
c.Add("X", "10");
c.Add("L", "50");
c.Add("C","100");
c.Add("D","500");
c.Add("M","1000");
int output1=0;
for (int i = 0; i < input1.Length-1; i++)
{
if (Convert.ToInt32(c.Get(input1[i].ToString())) >=
Convert.ToInt32(c.Get(input1[i + 1].ToString())))
{
output1 = output1 + Convert.ToInt32(c.Get(input1[i].ToString()));

}
else
{
output1 = output1 - Convert.ToInt32(c.Get(input1[i].ToString()));
}
}
output1 = output1 + Convert.ToInt32(c.Get(input1[input1.Length-1].ToString()));
Console.WriteLine(output1);

}
4.//comparing to lists and returning a list
public List<int> comlists(List<int> input1, List<int> input2)
{
List<int> l1 = new List<int>(input1.Count());
l1 = input1.Intersect(input2).ToList();
return l1;
}

//main function
string[] s = {"hello","hi","chandana"};
Program p = new Program();
//p.councharinstring(s);
//p.smalllengthstring(s);
//p.inttoroman("CCCXCVII");
List<int> l1 = new List<int>(5);
l1.Add(2);
l1.Add(4);
l1.Add(6);
l1.Add(5);
List<int> l2 = new List<int>(5);
l2.Add(6);
l2.Add(5);
l2.Add(1);
l2.Add(9);
List<int> l3 = p.comlists(l1, l2);
foreach (var c in l3)
Console.WriteLine(c);
5.//printing output based on the input sum
public void dice(int input1,int input2)
{
int sum = 0;
int output1=0;
if (input1 < 0 || input2 < 0)
{
output1 = -1;
Console.WriteLine(output1);
}
else
{
sum = input1 + input2;
if (sum == 2 || sum == 3 || sum == 6 || sum == 11)
output1 = 1000;
else if (sum == 4 || sum == 7 || sum == 10)
output1 = 3000;
else if (sum == 5 || sum == 8 || sum == 9 || sum == 12)

output1 = 5000;
Console.WriteLine(output1);

}
}
6.//change the first letter to uppercase in each word of a string
public static void firstletterchoose(string input1)
{
char[] c = " ".ToCharArray();
string[] s = input1.Split(c);
StringBuilder sb = new StringBuilder();
foreach (var f in s)
{
sb.Append(f[0].ToString().ToUpper());
for (int i = 1; i < f.Length; i++)
{
sb.Append(f[i]);
}
sb.Append(" ");
}
string output1 = sb.ToString();
Console.WriteLine(output1);
}
7.//check whether the first and last character of a string is special character or not
public void frstlast(string input1)
{
char[] c=new char[input1.Length];
c = input1.ToCharArray();
int output1;
int c1=input1.Length-1;
//Console.WriteLine(c1);
int count1 = 0, count2 = 0;
if (!((c[0] >= 'a' && c[0] <= 'z') || (c[0] >= 'A' && c[0] <= 'Z')||(c[0]>='0' &&
c[0]<='9')|| (c[0]==' ' )))
{
count1 = count1 + 1;
}
// Console.WriteLine(c[c1-2]);
if (!((c[c1] >= 'a' && c[c1] <= 'z') || (c[c1] >= 'A' && c[c1] <= 'Z') || (c[c1] >= '0'
&& c[c1] <= '9') || (c[c1] == ' ')))
{
count2 = count2 + 1;
}
if (count1 != 0 && count2 != 0)
{
output1 = 1;
Console.WriteLine(output1);
}
else if(count1!=0 && count2==0)
{
output1=-2;
Console.WriteLine(output1);
}
else if(count1==0 && count2==0)
{

output1=-1;
Console.WriteLine(output1);

}
else if (count1 == 0 && count2 != 0)
{
output1 = -3;
Console.WriteLine(output1);
}

}
8.//calculationg the salary on scenario passin no of days as a input
public void salary(int input1)
{
double output1 = 0.00;
double wage = 0.00;
if (input1 == 200)
wage = 200 * 100.2233;
else if (input1 > 200)
{
int x = input1 - 200;
wage = 200 * 100.2233;
wage= wage + (x * 150.00);
}
else if (input1 < 200)
{
int x = 200 - input1;
wage = input1 * 100.2233;
wage = wage -( x * 25);
}
Math.Round(wage,2);
if (output1 <= 25000)
{
output1 = wage;
Console.WriteLine(output1);
}
else if (output1 > 25000)
{
Console.WriteLine(output1);
}
else
{
output1 = wage;
Console.WriteLine(output1);
}
}
9.//reversing a string by removing special characters
public void revstring(string input1)
{
StringBuilder sb = new StringBuilder();
foreach (char c in input1)
{
if ((c <= 'Z' && c >= 'A') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')||
(c==' '))
{

sb.Append(c);
}

}
string s = sb.ToString();
Console.WriteLine(s);
char[] ch = new char[s.Length];
ch=s.ToCharArray();
Array.Reverse(ch);
string output1= new string(ch);
Console.WriteLine(output1);

}
10.//check whether the numbers in the input increasing order or not
public void incrsngorder(int input1)
{
string s = input1.ToString();
int f = Convert.ToInt32(s[0]);
int count = 0,count1,output1;
count1=s.Length-1;
foreach (var b in s)
{
if (b > f)
{
f = b;
count++;
}
}
if (count == count1)
{
output1 = 1;
Console.WriteLine(output1);
}
else
{
output1 = 0;
Console.WriteLine(output1);
}
}
//main function
Program p =new Program();
//p.dice(1,4);
//Program.firstletterchoose("tarun ananda mohan");
//p.salary(200);
//p.revstring("hello @ chandu % nammu");
//p.frstlast("hello chandana");
//p.incrsngorder(0134);
11.//finding the nth largest element in an array
public void nlargest(int[] input1, int input2)
{
Array.Sort(input1);
Array.Reverse(input1);
int[] a = input1.Distinct().ToArray();
int output1 = a[input2 - 1];
Console.WriteLine(output1);

}
12.//finding the voting eligibility of a member by passing DOB and date format as a input
public static void votingelegibility(String input1, String input2)
{
int age = 0, output1 = 0;
DateTime dt;
if ((DateTime.TryParseExact(input1, input2, null,
System.Globalization.DateTimeStyles.None, out dt)))
{
Console.WriteLine(dt);
DateTime dt1 = DateTime.Today;
age = dt1.Year - dt.Year;
if (dt1.Month < dt.Month || (dt1.Month == dt.Month && dt1.Day < dt.Day))
{
age--;
}
if (age >= 18)
output1 = 1;
else
output1 = -2;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
}
13.//finding redundant elements in an array and sort them in ascending order
public void redelements(int[] input1)
{
int[] a = new int[input1.Length];
ArrayList l1 = new ArrayList(10);
input1.CopyTo(a,0);
Array.Sort(a);
for (int i = 0; i < a.Length; i++)
{
for(int j=i+1;j<input1.Length;j++)
{
if (a[i] == a[j] && a[i]!=0 && !(l1.Contains(a[i])))
{
//x[k] = a[i];
l1.Add(a[j]);
a[j] = 0;
// break;
//k++;
}
}

}
l1.Sort();
Console.WriteLine("output");
foreach (var c in l1)
Console.WriteLine(c);
}

14.//main functio
try
{

votingelegibility("30/12/1989", "dd/MM/yyyy");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
//int[] a = new int[]{6,6,4,6,4,3};
//Program p = new Program();
//p.redelements(a);
15.//calculating car parking chargers by passing check in time and check out time as a
inputs and have to check whether they are in
"yyyy-MM-dd:H:mm:ss" format or not
public void car(string input1,string input2)
{
DateTime dt1;
DateTime dt2;
//DateTime d3 ;
//string format = "yyyy-MM-dd:H:mm:ss";
//string s1 = (DateTime.Now).ToString(format);
bool res1 = DateTime.TryParseExact(input1, "yyyy-MM-dd:H:mm:ss", null,
System.Globalization.DateTimeStyles.None, out dt1);
bool res2 = DateTime.TryParseExact(input2, "yyyy-MM-dd:H:mm:ss", null,
System.Globalization.DateTimeStyles.None, out dt2);
Console.WriteLine(dt2);
Console.WriteLine(dt1);
if (res1 && res2)
{
double hours = Convert.ToDouble((dt2 - dt1).TotalHours);
Console.WriteLine(hours);
double charge = 0;
double h = Math.Ceiling(hours);
if (h > 24)
{
charge = -2;
}
else if (h <= 3)
{
charge = 2;
}
else
{
charge = 2 + (h - 3) * 0.5;
}
Console.WriteLine(charge);
}
else
{
Console.WriteLine(-1);
}
}

16.//adding days to a given date


public static void adddays(string input1, int input2)
{
DateTime dt;
bool r = DateTime.TryParseExact(input1, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (r)
{
DateTime d = dt.AddDays(input2);
string F = "dd/MM/yyyy";
string s = d.ToString(F);
Console.WriteLine(s);
}
}
//main function
//Program p = new Program();
//p.car("2013-11-07:03:30:00","2013-11-07:15:00:00");
adddays("12/23/2000", 29);
17.//extracting nonrepeated charactyers in the given string
public static void norepchar(string input1)
{
int count=0;
char[] c = new char[input1.Length];
c = input1.ToCharArray();
List<char> l1 = new List<char>();
for(int i=0;i<input1.Length;i++)
{
count = 0;
for(int j=0;j<input1.Length;j++)
{
if(c[i]==c[j] && i!=j)
{
count++;
}
}
if (count == 0)
l1.Add(c[i]);
}
foreach (var c1 in l1)
Console.WriteLine(c1);
}
static void Main(string[] args)
{
norepchar("chandana");
}
18.//program to find the cubes of natural numbers upto n
public void nanturalcubes(int n)
{
int cube = 0;
for (int i = 1; i <= n; i++)
{

cube = cube + (i * i * i);


Console.WriteLine(cube);

}
Console.WriteLine(cube);

}
19.//findin sum of even numbers in array
public void sumeven(int[] a)
{
int[] x = a.Distinct().ToArray();
int sum = 0;
foreach (var i in x)
{
if (i % 2 == 0)
sum = sum + i;
}
Console.WriteLine(sum);
}
20.//finding the day of week of given date
public void day(string input1)
{
DateTime dt;
bool res = DateTime.TryParseExact(input1, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res)
{
DayOfWeek d1 = dt.DayOfWeek;
Console.WriteLine(d1);
int date = dt.Day;
Console.WriteLine(date);
}
}
21.//replacing the location with given input
public static void CTS_Hyd_123(string input1, string input2)
{
int i, j;
int cnt = 0;
for (i = 0; i < input1.Length; i++)
{
if (input1[i] == '-')
break;
}
for (j = i + 1; j < input1.Length; j++)
{
if (input1[j] == '-')
{
break;
}
else
cnt++;
}
string op = input1.Replace(input1.Substring(i + 1, cnt), input2);
Console.WriteLine(op);
}
22.//keep the cTS- as constant and replace the 123 with given input

public static void cts_123(string input1,string input2)


{
int i = 0;
for (i = 0; i < input1.Length; i++)
{
if (input1[i] == '-')
{
break;
}
}
string output1 = input1.Replace(input1.Substring(i + 1), input2);
Console.WriteLine(output1);
}
23.//finding the odd numbers in an array using linq
public static void oddnum(int[] input1)
{
IEnumerable<int> a = from i in input1 where i%2==1 select i;
foreach (var i in a)
Console.WriteLine(i);
}
static void Main(string[] args)
{
//Program p = new Program();
//p.nanturalcubes(5);
//int[] a = new int[] {3,5,82,8,0,4,5 };
//p.sumeven(a);
//p.day("12/14/1989");
//CTS_Hyd_123("CTS-CHN-123", "HYD");
//cts_123("cts-234", "123");
//oddnum(a);
//string input = "#76fa54";
24.//color format
//string pattern = @"^[#][a-f A-F 0-9]{6}$";
//string input ="aeiioouu";
//string pattern = @"^[a]+[e]+[i]+[o]+[u]+$";
//string input = @"\b([a-z]{2})[-][a-z]{3}[-][a-z]{3}[-]([a-z]{3})\b";
//string pattern = "hello chandu bi-how-dkb-hgi it's me";
//string pt1 = @"^a*e*i*o*u*$";
25.//email id checking
string pattern = @"^[a-z]+[a-z0-9]+[\- \.][a-z 0-9]+@[a-z]{4,5}\.([a-z]{2,3}|[a-z]
{2}[\.][a-z]{2})$";
string input1 = "jyot9sna-k92@gmail.com";
Regex reg = new Regex(pattern);

}
}

if (reg.IsMatch(input1))
{
Console.WriteLine("right");
}
else
{
Console.WriteLine("not ");
}

}
26.//to find whether the input2 and input 3 in input1 in an order
public static void strcontains(string input1,string input2,string input3)
{
int i = -1, j = -1;
i = input1.IndexOf(input2);
j = input1.LastIndexOf(input3);
if (j > i && i != -1 && j != -1)
{
Console.WriteLine("1");
}
else if (i == -1 || j == -1)
{
Console.WriteLine("it does not contaions two strings");
}
else if (j < i)
{
Console.WriteLine("strin2 occur before string1 ");
}
//Console.WriteLine(i);
}
27.//password validation
public static void validatepassword(string input1)
{
string pattern = @"^[a-z](?=.*[0-9])(?=.*[@#_])[a-z0-9#@_l]{6}[a-z 0-9]$";
Regex reg = new Regex(pattern);
if (reg.IsMatch(input1))
{
Console.WriteLine("right");
}
else
{
Console.WriteLine("wrong");
}
//int count = 0;
//foreach (var i in input1)
//{
// if (char.IsDigit(i))
//
count = 1;
//}
//if (input1.Length >= 8 && input1.Length<=10)
//{
// if (input1.First() >= 'a' && input1.First() <= 'z')
// {
//
if ((input1.Last() >= '0' && input1.Last() <= '9') || (input1.Last() >= 'a' &&
input1.Last() <= 'z'))
//
{
//
if (input1.Contains('#') || input1.Contains('_') || input1.Contains('@'))
//
{
//
if (count == 1)
//
Console.WriteLine("1");
//
else
//
Console.WriteLine("-1");
//
}

//
else
//
Console.WriteLine("-1");
//
}
//
else
//
Console.WriteLine("-1");
// }
// else
//
Console.WriteLine("-1");
//}
//else
//{
// Console.WriteLine("-1");
//}
}
28.//checking whether all the given strings in the string array valid number or not
public static void checknumber(string[] input1)
{
int flag = 0;
string pattern = @"^([\d]+[\.]?[\d]+)$";
Regex ex = new Regex(pattern);
foreach (var i in input1)
{
if ((ex.IsMatch(i)))
{
flag = 1;
}
else
{
flag = -1;
}
}
if (flag == 1)
{
Console.WriteLine("all numbers");
}
else
{
Console.WriteLine("all are not numbers");
}
}
29.//checking whether the each element in the string array is proper number or not
public static void checknumber(string[] input1)
{
int flag = 0;
string pattern = @"^([\d]+[\.]?[\d]+)$";
Regex ex = new Regex(pattern);
foreach (var i in input1)
{
if ((ex.IsMatch(i)))
{
flag = 1;
}
else
{

flag = -1;
}

}
if (flag == 1)
{
Console.WriteLine("all numbers");
}
else
{
Console.WriteLine("all are not numbers");
}
}
30.reverseing each word in a string
public static void reversewords(string input1)
{
StringBuilder sb = new StringBuilder();
string[] s = input1.Split(' ');
foreach (var i in s)
{
char[] c = i.ToCharArray();
Array.Reverse(c);
foreach (var k in c)
{
sb.Append(k);
}
sb.Append(' ');
}
string output = sb.ToString();
Console.WriteLine(output);
}
31.//finding the motns btwn two dates and the foramt of the dates are "yyyy-MM-dd"
public static void monthdiff(string input1,string input2)
{
DateTime dt1,dt2;
bool res = DateTime.TryParseExact(input1,"yyyy-MMdd",null,System.Globalization.DateTimeStyles.None,out dt1);
bool res1 = DateTime.TryParseExact(input2, "yyyy-MM-dd", null,
System.Globalization.DateTimeStyles.None, out dt2);
int days = Convert.ToInt32((dt2 - dt1).TotalDays);
int months = days / 30;
Console.WriteLine("total months "+months);
}
32.//function to reverse 2 letter substring
public static void twoletterrev(string input1)
{
StringBuilder sb = new StringBuilder();
int count = 0, count1 = input1.Length;
foreach (var i in input1)
{
if (char.IsLetter(i))
count = count + 1;
}
if (count == count1)
{

if (input1.Length / 2 == 0)
{
for (int i = 0; i < input1.Length; i += 2)
{
string s = input1.Substring(i, 2);
sb.Append(s.Last());
sb.Append(s.First());
}
}
else
{
for (int i = 0; i < input1.Length - 1; i += 2)
{
string s = input1.Substring(i, 2);
//Console.WriteLine(s);
sb.Append(s.Last());
sb.Append(s.First());
}
sb.Append(input1.Last());
}
string output = sb.ToString();
Console.WriteLine(output);

}
else
{
Console.WriteLine("-1");
}

}
33.//check whether the string contains all the ovwels and they should be in increasing
order or not
public static void alphabet(string input1)
{
string s = "";
foreach (var i in input1)
{
if (i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'u')
{
s += i;
}
}
string pattern = @"^aeiou$";
Regex ex = new Regex(pattern);
char[] c = {'a','e','i','o','u'};
if (input1.Contains('a') && input1.Contains('e') && input1.Contains('i') &&
input1.Contains('o') && input1.Contains('u') && s.Length == 5 && ex.IsMatch(s))
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("-1");
}
}

34.//taking the redundant elements ans sorting them in ascending order


public static void redelements(int[] input1)
{
int[] a = new int[input1.Length];
List<int> l1 = new List<int>();
input1.CopyTo(a, 0);
Array.Sort(a);
for (int i = 0; i < a.Length; i++)
{
for (int j = i + 1; j < a.Length; j++)
{
if (a[i] == a[j] && !(l1.Contains(a[i])))
{
l1.Add(a[j]);
//a[j] = 0;
// break;
//k++;
}
}
}
foreach (var i in l1)
Console.WriteLine(i);
}
35.//checking phine number format
public static void phonenumformat(string input1)
{
string pattern = @"^[\d]{10}$";
Regex ex = new Regex(pattern);
if (ex.IsMatch(input1))
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("-1");
}
}
36.//checking ipaddress format(for this add system.net)
public static void ipaddressformat(string input1)
{
IPAddress address;
if (IPAddress.TryParse(input1, out address))
{
Console.WriteLine(address);
Console.WriteLine("Valid IPv4 string in X.X.X.X format");
}
else
{
Console.WriteLine("not a IPv4 string in X.X.X.X format");
}
}
37.//checking whether all the elements in the sting array in number format or not(either
integer or double)
public static void checknumber(string[] input1)

{
int flag = 0;
string pattern = @"^([\d]+[\.]?[\d]+)$";
Regex ex = new Regex(pattern);
foreach (var i in input1)
{
if ((ex.IsMatch(i)))
{
flag = 1;
}
else
{
flag = -1;
}
}
if (flag == 1)
{
Console.WriteLine("all numbers");
}
else
{
Console.WriteLine("all are not numbers");
}
}
38.//reversing the each word in the given string
public static void reversewords(string input1)
{
StringBuilder sb = new StringBuilder();
string[] s = input1.Split(' ');
foreach (var i in s)
{
char[] c = i.ToCharArray();
Array.Reverse(c);
foreach (var k in c)
{
sb.Append(k);
}
sb.Append(' ');
}
string output = sb.ToString();
Console.WriteLine(output);
}
39.//finding the months difference btwn two inputs
public static void monthdiff(string input1,string input2)
{
DateTime dt1,dt2;
bool res = DateTime.TryParseExact(input1,"yyyy-MMdd",null,System.Globalization.DateTimeStyles.None,out dt1);
bool res1 = DateTime.TryParseExact(input2, "yyyy-MM-dd", null,
System.Globalization.DateTimeStyles.None, out dt2);
int days = Convert.ToInt32((dt2 - dt1).TotalDays);
int months = days / 30;
Console.WriteLine("total months "+months);
}

40.//reversing two letters in a given word(word=>owdr)


public static void twoletterrev(string input1)
{
StringBuilder sb = new StringBuilder();
int count = 0, count1 = input1.Length;
foreach (var i in input1)
{
if (char.IsLetter(i))
count = count + 1;
}
if (count == count1)
{
if (input1.Length / 2 == 0)
{
for (int i = 0; i < input1.Length; i += 2)
{
string s = input1.Substring(i, 2);
sb.Append(s.Last());
sb.Append(s.First());
}
}
else
{
for (int i = 0; i < input1.Length - 1; i += 2)
{
string s = input1.Substring(i, 2);
//Console.WriteLine(s);
sb.Append(s.Last());
sb.Append(s.First());
}
sb.Append(input1.Last());
}
string output = sb.ToString();
Console.WriteLine(output);
}
else
{
Console.WriteLine("-1");
}
}
41.//check whether all the vowels r ther in the given string and they can't repeat
public static void alphabet(string input1)
{
string s = "";
foreach (var i in input1)
{
if (i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'u')
{
s += i;
}
}
string pattern = @"^aeiou$";
Regex ex = new Regex(pattern);

char[] c = {'a','e','i','o','u'};
if (input1.Contains('a') && input1.Contains('e') && input1.Contains('i') &&
input1.Contains('o') && input1.Contains('u') && s.Length == 5 && ex.IsMatch(s))
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("-1");
}
}
42.//9th question in 2nd column in the PDF file
public static void stringarraysort(string[] input1, char input2)
{
List<string> output = new List<string>();
int k = 0;
foreach (var i in input1)
{
if (i.Contains(input2))
{
if (i.First() != input2)
{
output.Add(i);
}
}
else
{
k = 1;
Console.WriteLine("-1");
break;
}
}
if (k == 0)
{
output.Sort();
foreach (var i in output)
{
Console.WriteLine(i);
}
}
}
43.//checking for the phone number format
public static void phonenumformat(string input1)
{
string pattern = @"^[\d]{10}$";
Regex ex = new Regex(pattern);
if (ex.IsMatch(input1))
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("-1");
}

}
43.//fib series
public static void fibseries(int input1)
{
int f1 = 0, f2 = 1, f3;
f3 = f1 + f2;
Console.WriteLine(f1);
Console.WriteLine(f2);
f
or (int i = 1; i < input1-1;i++ )
{
Console.WriteLine(f3);
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
}
44.//reverse the second input and insert in the mid of frst string
public static void revinsert(string input1, string input2)
{
int mid = input1.Length / 2;
char[] c = input2.ToCharArray();
Array.Reverse(c);
string s1 = "";
string s = new string(c);
if (input1.Length % 2 == 0)
{
s1 = input1.Insert(mid, s);
}
else
{
s1 = input1.Insert(mid+1,s);
}
Console.WriteLine(s1);
}
45.//concatinating the last and frst letters for a particular length (calfornia,3 =>
calnia )
public static void conctaestringletters(string input1, int input2)
{
string output = "";
output =output+ input1.Substring(0,input2);
output = output + input1.Substring(input1.Length - input2, 3);
Console.WriteLine(output);
}
###########
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace c_examquestions
{
class Program
{

//1.Find sum of squires of n natural numbers using formula n(n+1)(2n+1)/6


//BR:input1 is not natural no then output=-1
public static void sum_of_squires(int input1)
{
int output;
if (input1 > 0)
{
output = input1 * (input1 + 1) * (2 * input1 + 1) / 6;
}
else
output = -1;
Console.WriteLine(output);
}
//2.some scenario to find area they gave formula Area=PI*R*R
//BR:input1<0
public static void find_Area(double input1)
{
double output;
if (input1 > 0)
{
double PI = 3.14;
output = PI * input1 * input1;
}
else
output=-1;
Console.WriteLine(Math.Round(output));
}
//3.input1 is string Assume that string index start at 0 from last character..extract
substring starting at input2 with input3 chars and reverse it.
//ex:input1:Rajasthan
//input2=2
//input3=3
//output=hts
public static void str_reverse(string input1,int input2,int input3)
{
char[] chr = input1.ToCharArray();
Array.Reverse(chr);
string temp = new string(chr);
string output = temp.Substring(input2, input3);
Console.WriteLine(output);
}
//4.find day of week of given date
public static void find_day(string input1)
{
string output="";
DateTime dt;
bool flag = DateTime.TryParseExact(input1, "MM-dd-yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (flag == true)
{
output = dt.DayOfWeek.ToString();
}

Console.WriteLine(output);
}
//5.find difference b/w two dates in yyyy-mm-dd format
public static void date_diff(string input1, string input2)
{
DateTime dt1, dt2;
bool f1 = DateTime.TryParseExact(input1, "yyyy-MM-dd", null,
System.Globalization.DateTimeStyles.None, out dt1);
bool f2 = DateTime.TryParseExact(input2, "yyyy-MM-dd", null,
System.Globalization.DateTimeStyles.None, out dt2);
if(f1==true && f2==true)
{
TimeSpan t = dt1 - dt2;
int output = (int)t.TotalDays;
Console.WriteLine(output);
}
}
//6.check the string should contain five vowels and in alphabetical order if it is in
that order output is 1 otherwise 2
//BR:if string contains repeated vowels then output is -1
public static void check_vowel(string input1)
{
int output=0;
StringBuilder sb = new StringBuilder();
foreach (char ch in input1)
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
{
sb.Append(ch);
}
}
int flag = 0;
string temp = sb.ToString();
if (temp.Contains('a') && temp.Contains('e') && temp.Contains('i') &&
temp.Contains('o') && temp.Contains('u') && temp.Length == 5)
{
flag = 1;
}
else
output = 2;
for(int i=0;i<temp.Length-1;i++)
for (int j = i + 1; j < temp.Length; j++)
{
if (temp[i] == temp[j])
output = -1;
}
if (flag == 1)
{
Regex ex = new Regex(@"aeiou");
if (ex.IsMatch(temp))
output = 1;
else
output = 2;
}

Console.WriteLine(output);
}
static void Main(string[] args)
{
sum_of_squires(3);
find_Area(2.3);
str_reverse("rajasthan",2,3);
find_day("02-05-2013");
date_diff("2013-09-07", "2013-09-09");
check_vowel("abeciholu");
}
}
}
#############
1.check the XXX-XXX-XXXX format if mathes print 1 else -1
-----------------------------------------------------------------public static void phone_number(string input1)
{
int output1;
Regex re = new Regex(@"^[\d]{3}-[\d]{3}-[\d]{4}$");
if (re.IsMatch(input1))
{
output1 = 1;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
}
2.sort the array in asce order array should contain only positive nos
----------------------------------------------------------------------public static void arraySort(int[] input1)
{
int[] output1;
int count = 0;
foreach(var i in input1)
{
if (i <= 0)
count++;
}
if(count==0)
{
Array.Sort(input1);
output1=input1;
}
else
{
output1=new int[]{-1};
}
foreach(var ele in output1)
Console.WriteLine(ele);
}

3.print the word which has maximum no.of vowels. if two or more words having same
no.of vowels print first occurance
----------------------------------------------------------------------------------------------------------------------public static void maxVowels(string input1)
{
string output1="";
input1=input1.ToLower();
int max = 0;
string[] str = input1.Split(' ');
foreach (var s in str)
{
int count = 0;
foreach (var ch in s)
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
{
count++;
}
}
if (count > max)
{
max = count;
output1 = s;
}
}
Console.WriteLine(output1);
}
4.capitalize first character of each word in a given string. remaining all chars should be
small
--------------------------------------------------------------------------------------------------public static void Capitalizewords(string input1)
{
int i = 0;
string output1 = "";
input1 = input1.ToLower();
string[] str = input1.Split(' ');
string[] arr=new string[str.Length];
foreach (var s in str)
{
char ch = char.ToUpper(s[0]);
string s1 = ch + s.Substring(1);
arr[i]=s1;
i++;
}
output1 = string.Join(" ", arr);
Console.WriteLine(output1);
}
5.count the digits in a given string. string shouldcontain whitespaces and alphanumerics
otherwise print -1
-----------------------------------------------------------------------------------------------------------public static void countdigits(string input1)
{
int c = 0, count = 0,output1, n = input1.Length;
foreach (var ch in input1)

{
if (char.IsLetterOrDigit(ch) || char.IsWhiteSpace(ch))
c++;

}
if (n == c)
{
foreach (var ch in input1)
{
if (char.IsDigit(ch))
count++;
}
output1 = count;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);

//. Delete the elements in an array list at the position of multiples of 3


-----------------------------------------------------------------------------------------public static void Remove3multipleindexvalues(ArrayList input1)
{
int n=input1.Count;
List<object> l1 = new List<object>();
l1.Add(input1[0]);
for (int i = 2; i < n; i++)
{
if (i % 3 == 0)
{
object h =input1[i];
l1.Add(h);
+
}
}
foreach (var j in l1)
Console.WriteLine(j);
Console.WriteLine();
foreach (var k in input1)
{
if(!l1.Contains(k))
Console.WriteLine(k);
}
}
//. Remove the vowels from the even positions of the sting.
(Assume first letter of string is in 1st position )
Ex:- input : commitment
output : cmmitmnt
--------------------------------------------------------------------------------------------------------public static void vowelsateven(string input1)
{
int n = input1.Length;

StringBuilder sb=new StringBuilder();


for (int i = 0; i < n; i++)
{
if ((i % 2 == 1) && (input1[i] == 'a' || input1[i] == 'e' || input1[i] == 'i' ||
input1[i] == 'o' || input1[i] == 'u'))
{
}
else
{
sb.Append(input1[i]);
}
}
string s = sb.ToString();
Console.WriteLine(s);
}
.// Check whether the given input string is palindrome or not. And also check whether at
least 2 different
vowels are there in the string. If so return 1 else return -1
--------------------------------------------------------------------------------------------------------------------------public static void palindrome(string input1)
{
char[] a1 = input1.ToCharArray();
int count=0;
foreach (var c in a1)
{
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
count++;
}
string s1 = input1;
Array.Reverse(a1);
foreach (var l in a1)
Console.Write(l);
Console.WriteLine();
string s2 = new string(a1);
if(s1.Equals(s2) && count>=2 )
Console.WriteLine("1");
else
Console.WriteLine("-1");
}
Input1={"ab","a","abc","abcd"};
Input2=3
Delete al elements with the size 3 ("abc" in this example);
=> output1= 3(no.of elements after deleting "abc")
------------------------------------------------------------------------------------public static void deletsize3(string[] input1,int output1)
{
int n = input1.Length;
int count = 0;
foreach (var i in input1)

{
if (i.Length == output1)
{
}
else
{
count++;
}
}
Console.WriteLine(count);
}
Count Words
Input1="this is Cognizant academy"
Input2="hi this is a trainee";
How many times the second word of input2 ("this" in this xample) is repeated in input1.
Note: Consider Case
Output1=1.
--------------------------------------------------------------------------------------------public static void twoStrings(string input1, string input2)
{
string[] a1 = input1.Split(' ');
string[] a2 = input2.Split(' ');
int c=0;
foreach(var i in a1)
{
if(i.Equals(a2[1]))
c++;
}
Console.WriteLine(c);
}
////////pancard
public static void pancard(string input1)
{
Regex re = new Regex(@"^[A-Z]{3}[0-9]{4}[A-Z]{1}$");
if (re.IsMatch(input1))
Console.WriteLine(input1);
else
Console.WriteLine("wrong");
}
////////
public static void input1contains2n3(string ip1, string ip2, string ip3)
{
int ind1 = ip1.IndexOf(ip2);
Console.WriteLine(ind1);
int ind2 = ip1.IndexOf(ip3);
Console.WriteLine(ind2);
if (ind1 < ind2)
Console.WriteLine("1");
else
Console.WriteLine("-1");

}
//Validate Password
validate based on following criteria:
minimum length is 6-20
should contain any of these @/_/#
should not start with number/special chars(@/#/_)
should not end with special chars
can contain numbers,letters,special char
---------------------------------------------------------------------------public static void password(string input1)
{
int n = input1.Length;
int c = 0,count=0;
foreach (var i in input1)
{
if (char.IsLetterOrDigit(i) || char.IsWhiteSpace(i) || i == '@' || i == "#" || i ==
"_")
count++;
}
if (n == count)
{

'Z'))

if (input1.Length >= 6 && input1.Length <= 20)


{
if ((input1[0] >= 'a' && input1[0] <= 'z') || (input1[0] >= 'A' && input1[0] <=
{

if ((input1[n - 1] >= 'a' && input1[n - 1] <= 'z') || (input1[n - 1] >= 'A' &&
input1[n - 1] <= 'Z') || (input1[n - 1] >= '0' && input1[n - 1] <= '9'))
{
if (input1.Contains('@') || input1.Contains('#') || input1.Contains('_'))
{
for (int i = 0; i < n; i++)
{
if (input1[i] >= '0' && input1[i] <= '9')
c++;
}
if (c > 0 )
{
Console.WriteLine("correct");
}
else
Console.WriteLine("wrong");
}
else
Console.WriteLine("wrong");
}
else
Console.WriteLine("wrong");
}
else
Console.WriteLine("wrong");
}

else
Console.WriteLine("wrong");

}
//In an array, find the largest difference b/w adjascent elements and return the index of
largest difference.
eg: input: {2,4,5,1,9,3,8}
output:4
-------------------------------------------------------------------------------------------------------------public static void maxdiffmaxnum(int[] input1)
{
List<int> l1 = new List<int>();
for (int i = 0; i < input1.Length - 1; i++)
{
l1.Add(Math.Abs(input1[i] - input1[i + 1]));
}
int max = l1.Max();
int index = l1.IndexOf(max);
if (input1[index] > input1[index + 1])
Console.WriteLine(input1[index]);
else
Console.WriteLine(input1[index + 1]);
foreach (var i in l1)
Console.WriteLine(i);
}
//Another method
public static void findlarge(int[] input1)
{
int d=0,t;
int op = 0;
for (int i = 0; i < input1.Length - 1; i++)
{
int dis =Math.Abs(input1[i] - input1[i + 1]);
if (dis > d)
{
d = dis;
op = i;
}
}
if (input1[op] > input1[op + 1])
t = op;
else
t = op + 1;
Console.WriteLine ;
}
//5. First ArrayList:1 5 6 8 9
Second ArrayList: 5 6 7 9
output ArrayList:5 5 7 8
-------------------------------------------------------------logic: iterate the first array list find odd index elements and keep it in a new Array list
without changing its index
Iterate the second array list find the even index elements and keep it in a new Array list

without changing its index.


public static void evenoddpositions(int[] input1, int[] input2)
{
List<int> l1 = new List<int>();
int i;
if (input1.Length < input2.Length)
{
min = input1.Length;
}
else
{
min = input2.Length;
}
for (i = 0; i < min; i++)
{
if (i % 2 == 0)
l1.Add(input2[i]);
else
l1.Add(input1[i]);
}
foreach(var k in l1)
Console.WriteLine(k);
}
// Two i/p strings Count the common unique characters in both the strings
Ex:Input1:a back up cow
Input2:battle ship
O/p:2
i/ps are case sensitive
public static void commonunique(string input1, string input2)
{
int output1;
char[] arr1 = input1.ToCharArray();
char[] arr2 = input2.ToCharArray();
List<char> l1 = new List<char>();
List<char> l2 = new List<char>();
foreach (var ch in arr2)
l1.Add(ch);
foreach (var ch in arr1)
{
if (l1.Contains(ch) && !l2.Contains(ch))
l2.Add(ch);
}
output1 = l2.Count;
Console.WriteLine(output1);
}
###########
//input will be two lists and we have to sum the elements in both the lists which are not
common
if any list1 having -ve elements store -1 to output if list2 have the -ve numbers store -2
to the output if both the lists are having -ve nubers store -3 to output
ex: l1={1,2,3,4},l2={2,3,4,5,6} output=1+5+6=12
public static void sumofdistinctelements(List<Int32> input1,List<Int32> input2)
{

int flag1 = 0, flag2 = 0;


Int32 output1 = 0;
foreach(var i in input1)
{
if (i < 0)
flag1 = -1;
}
foreach (var i in input2)
{
if (i < 0)
flag2 = -1;
}
if (flag1 == -1 && flag2==-1)
{
output1 = -3;
}
else if (flag1 == -1)
{
output1 = -1;
}
else if (flag2 == -1)
{
output1 = -2;
}
else
{
List<Int32> l1 = new List<Int32>();
List<Int32> l2 = new List<Int32>();
l1 = input1.Except(input2).ToList();
l2 = input2.Except(input1).ToList();
output1 = l1.Sum() + l2.Sum();
}
Console.WriteLine(output1);
}
//two inputs one is string and another one is character reverse the input one and
separate each character with input 2
ex: rabbit,output:t-i-b-b-a-r
public static void reverse(string input1,char input2)
{
char[] c = input1.ToCharArray();
string output1 = "";
int i;
Array.Reverse(c);
StringBuilder sb = new StringBuilder();
for (i = 0; i < c.Length - 1; i++)
{
sb.Append(c[i]);
sb.Append(input2);
}
sb.Append(c[i]);
output1 = sb.ToString();
Console.WriteLine(output1);
}

//two inputs one is string and another one is delimiter we have to split the input1 with
the delimiter then have to find the longest word if two are
having the same length store the first word with the alphabetical order
ex: input: delhi-mumbai-kanpor
output : kanpoor
public static void laongstring(string input1,string input2)
{
char[] c = input2.ToCharArray();
string output1 = "";
string[] s = input1.Split(c);
List<string> l1 = new List<string>();
int count = 0, max = 0;
foreach (var i in s)
{
count = i.Length;
if (max < count)
max = count;
}
foreach (var i in s)
{
if (i.Length == max)
l1.Add(i);
}
if (l1.Count > 1)
{
l1.Sort();
output1 = l1[0];
}
else
{
output1 = l1[0];
}
Console.WriteLine(output1);
}
//input will string which is -ve numebr and we have to check whether the given input is in
given format or not if it in number format then store the positive value
to the string output else store -1 to output
ex: input1 : "-9876"
output:"9876"
public static void numformar(string input1)
{
string pattern = @"^[-][\d]+[\.]?[\d]*$";
Regex ex = new Regex(pattern);
string output1="";
if (ex.IsMatch(input1))
{
output1 = input1.Substring(1);
}
else
{
output1 = "-1";
}
Console.WriteLine(output1);

}
//input is an integer array if there is norepeated element in the array then store -1 to the
output else find the max span to the output
input: {1,2,3,4,5,1}
output:6
the span betwen two 1's is 6.
input:{1,2,3,2,1,2}
output:5 if two numbers are repeated then take the first element only
public static void maxspan(int[] input1)
{
int output = 0,flag=0;
for (int i = 0; i < input1.Length; i++)
{
for (int j = i + 1; j < input1.Length; j++)
{
if (input1[i] == input1[j])
{
flag = 1;
}
}
}
if (flag == 1)
{
List<int> l1 = new List<int>();
l1 = input1.ToList();
int span = 0;
for (int i = 0; i < l1.Count; i++)
{
span = l1.LastIndexOf(l1[i]) - l1.IndexOf(l1[i]);
if (span > 1)
{
output = span + 1;
break;
}
}
}
else
{
output = -1;
}
Console.WriteLine(output);
}
//shipping scenario
public static void shipping(Single input1, char input2)
{
Single diff;
Single output1 = 0;
switch (input2)
{
case 'R': if (input1 > 2000)
{
diff = input1 - 2000;
output1 = Convert.ToSingle(diff * 0.35);
output1 = output1 + Convert.ToSingle(2000 * 0.25);

}
else
{
output1 = Convert.ToSingle(input1*0.25);

break;
case 'X': output1 = 50;
if (input1 > 2000)
{
diff = input1 - 2000;
output1 =output1+Convert.ToSingle(diff * 0.35);
output1 = output1 + Convert.ToSingle(2000 * 0.25);
}
else
{
output1 =output1+Convert.ToSingle(input1 * 0.25);
}
break;

}
Console.WriteLine(output1);

}
//check whether given input string having only characters if it contains only characters
then find the longest word if it contains any digit
and special character store -1 to output if it contains wither digit or special character
store -2 to output
public static void checkstring(string input1)
{
string output = "";
int flag1 = 0, flag2 = 0;
foreach (var i in input1)
{
if (char.IsDigit(i))
flag1 = -1;
if (!(char.IsLetterOrDigit(i))&&(i!=' '))
flag2 = -1;
}
if (flag1 == -1 && flag2 == -1)
{
output = "-1";
}
else if (flag1 == -1)
{
output = "-2";
}
else if (flag2 == -1)
{
output = "-2";
}
else
{
string[] s = input1.Split(' ');
int count = 0, max = 0;
foreach (var i in s)
{

count = i.Length;
if (max < count)
{
max = count;
output = i;
}

}
}
Console.WriteLine(output);
}
static void Main(string[] args)
{
//sumofdistinctelements(new List<Int32> { 1, 2, 3, 4 }, new List<Int32>
{1,2,3,4,5});
//reverse("rabbit",'-');
//laongstring("delhi-India-arama", "-");
//numformar("-9876");
//maxspan(new int[] {1,4,2,6,7,1,2,3});
//shipping(4500, 'R');
checkstring("i am123 $^chandu");
}
}
//remove the repeated elements in the string except space
ex: input : this isre hai
output: this re ha
public static void remreptdcharexceptspace(string input1)
{
List<char> l1 = new List<char>();
foreach (var i in input1)
{
if (!(l1.Contains(i)) || i == ' ')
l1.Add(i);
}
char[] c = l1.ToArray();
string s = new string(c);
Console.WriteLine(s);
}
#################
=====================================================
=====================================================
=====
2. String format : CTS-LLL-XXXX
ip1: CTS-hyd-1234
ip2: hyderabad
=====================================================
=====================================================
=====
class Program
{
public static void concatenate(string input1, string input2)

{
string firstthree = input2.Substring(0,3);
string one = input1.Substring(0,3);
string two = input1.Substring(8,4);
string all = one + "-" + firstthree + "-" + two;
Console.WriteLine(all);
}
static void Main(string[] args)
{
concatenate("CTS-hyd-1234","madurai");
}
=====================================================
=====================================================
=====
1. Get the middle chars(2 characters) in a string (only even length).
input1: this
output1:hi
=====================================================
=====================================================
=====
int count = 0;
int middle = 0;
count = input1.Length;
if (count % 2 == 0)
{
middle = ((count) / 2);
string strResultValue1 = input1.Substring(middle-1,2);
Console.WriteLine(strResultValue1);
}
}
=====================================================
=====================================================
=====
1. Check whether the input number is negative. If so return the positive number
Else return -1.The number is read as string and output is also string
=====================================================
=====================================================
public static void checknegative(string input1)
{
int output = Int32.Parse(input1);
if (output < 0)
{
output = output * (-1);
Console.WriteLine(output);
}
else
{
Console.WriteLine("-1");
}
}

###############
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication23
{
class Program
{
public static void liststrng(List<string> input1, char input2)
{
List<string> output1 = new List<string>();
List<string> l1 = new List<string>();
List<string> l2 = new List<string>();
bool flag = false;
foreach (var i in input1)
{
l2.Add(i.ToLower());
}
foreach (var i in l2)
{
for (int j = 0; j < i.Length; j++)
{
if (!(char.IsLetter(i[j])))
{
flag = true;
}
}
}
if (input1.Count == 0)
{
output1.Add("-1");
}
else if (flag)
{
output1.Add("-2");
}
else
{
foreach (var i in l2)
{
if (!(i[0] == input2)&&i.Contains(input2))
{
l1.Add(i);
}
}
string t = "";
for (int i = 0; i < l1.Count;i++ )
{
for (int j = i + 1; j < l1.Count; j++)
{
if (l1[i].Length > l1[j].Length)

t = l1[j];
l1[j] = l1[i];
l1[i] = t;

}
output1 = l2;

}
foreach (var i in output1)
{
Console.WriteLine(i);
}
}
public static void maxele(List<string> input1, char input2)
{
List<string> l1 = new List<string>();
List<string> output1 = new List<string>();
foreach (var i in input1)
{
l1.Add(i.ToLower());
}
char c = char.ToLower(input2);
bool flag = false;
foreach (var i in l1)
{
for (int j = 0; j < i.Length; j++)
{
if (!(char.IsLetter(i[j])))
{
flag = true;
}
}
}
if (input1.Count == 0)
{
output1.Add("-1");
}
else if (flag)
{
output1.Add("-2");
}
else
{
string s = "";
string max = "";
foreach (var i in l1)
{
if (i[0] == c)
{
s = i;
}
if (max.Length < s.Length)
max = s;

}
output1.Add(max);

}
foreach (var i in output1)
Console.WriteLine(i);
}
public static void twoletterrev(string input1)
{
StringBuilder sb = new StringBuilder();
int count = 0, count1 = input1.Length;
foreach (var i in input1)
{
if (char.IsLetter(i))
count = count + 1;
}
if (count == count1)
{
if (input1.Length % 2 == 0)
{
for (int i = 0; i < input1.Length; i += 2)
{
string s = input1.Substring(i, 2);
sb.Append(s[1]);
sb.Append(s[0]);
}
}
else
{
for (int i = 0; i < input1.Length - 1; i += 2)
{
string s = input1.Substring(i, 2);
//Console.WriteLine(s);
sb.Append(s[1]);
sb.Append(s[0]);
}
sb.Append(input1[input1.Length-1]);
}
string output = sb.ToString();
Console.WriteLine(output);
}
else
{
Console.WriteLine("-1");
}
}
static void Main(string[] args)
{
List<string> l1 = new List<string>(){"READYU","write","edit"};
//liststrng(l1, 'e');
List<string> l2 = new List<string>(){"read","elegant","Edit"};
//maxele(l2, 'e');
twoletterrev("NewYorK");
}
}

}
=========
public static void SortList(List<string> input1, char input2)
{
string[] input1arr = new string[input1.Count];
input1.CopyTo(input1arr);
List<string> reducedInput1 = input1arr.ToList<string>();
foreach(string item in input1)
if (item.StartsWith(input2.ToString(), true, null))
reducedInput1.Remove(item);
int i, j, listLength = reducedInput1.Count;
string tempString;
for (i = 0; i < listLength; i++)
{
for(j = i + 1; j < listLength; j++)
{
if (reducedInput1[j].Length < reducedInput1[i].Length)
{
tempString = reducedInput1[i];
reducedInput1[i] = reducedInput1[j];
reducedInput1[j] = tempString;
}
}
}
output1 = reducedInput1;
}
public static void PrintOutput()
{
List<string> input1 = new List<string>() {"READhghgh", "write", "Edit"};
char input2='e';
SortList(input1, input2);
foreach (string item in output1)
Console.WriteLine(item);
}
###########

//raising array index to its power


public static void arraypow(int[] arr)
{
double sum=0;
for (int i = 0; i < arr.Length; i++)
{
sum = sum + Math.Pow(arr[i], i);
}
Console.WriteLine(sum);
}
//highest number in an integer
public static void highest(int n)
{
string s = n.ToString();
Console.WriteLine(s);

char[] c=s.ToCharArray();
char max=c[0];
foreach (var i in c)
{
if (i > max)
max = i;
}
int output1;
output1 = Convert.ToInt32(max.ToString());
Console.WriteLine(output1);

}
//Consecutively add upto n like 1+3-5+7-9
public static void consecadd(int n)
{
List<int> l1 = new List<int>();
int i;
int sum;
for (i = 1; i <= n; i++)
{
if (i % 2 == 1)
{
l1.Add(i);
}
}
sum = l1[0];
for (int k = 1; k < l1.Count; k++)
{
if (k % 2 == 1)
sum = sum + l1[k];
else
sum = sum - l1[k];
}
Console.WriteLine(sum);

}
//count consecutive 3 alphabets without repitition
public static void consecutive3(string input1)
{
List<string> l1=new List<string>();
for (int i = 0; i <=input1.Length-3; i++)
{
string str = input1.Substring(i, 3);
if (str[0] == str[1] && str[1] == str[2] && !l1.Contains(str))
{
l1.Add(str);
}
}
int output1 = l1.Count;
Console.WriteLine(output1);
}
//1.Find sum of squires of n natural numbers using formula n(n+1)(2n+1)/6
//BR:input1 is not natural no then output=-1
public static void sum_of_squires(int input1)
{

int output;
if (input1 > 0)
{
output = input1 * (input1 + 1) * (2 * input1 + 1) / 6;
}
else
output = -1;
Console.WriteLine(output);
}
//2.some scenario to find area they gave formula Area=PI*R*R
//BR:input1<0
public static void find_Area(double input1)
{
double output;
if (input1 > 0)
{
double PI = 3.14;
output = PI * input1 * input1;
}
else
output=-1;
Console.WriteLine(Math.Round(output));
}
//3.input1 is string Assume that string index start at 0 from last character..extract
substring starting at input2 with input3 chars and reverse it.
//ex:input1:Rajasthan
//input2=2
//input3=3
//output=hts
public static void str_reverse(string input1,int input2,int input3)
{
char[] chr = input1.ToCharArray();
Array.Reverse(chr);
string temp = new string(chr);
string output = temp.Substring(input2, input3);
Console.WriteLine(output);
}
//4.find day of week of given date
public static void find_day(string input1)
{
string output="";
DateTime dt;
bool flag = DateTime.TryParseExact(input1, "MM-dd-yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (flag == true)
{
output = dt.DayOfWeek.ToString();
}
Console.WriteLine(output);
}
//5.find difference b/w two dates in yyyy-mm-dd format
public static void date_diff(string input1, string input2)

{
DateTime dt1, dt2;
bool f1 = DateTime.TryParseExact(input1, "yyyy-MM-dd", null,
System.Globalization.DateTimeStyles.None, out dt1);
bool f2 = DateTime.TryParseExact(input2, "yyyy-MM-dd", null,
System.Globalization.DateTimeStyles.None, out dt2);
if(f1==true && f2==true)
{
TimeSpan t = dt1 - dt2;
int output = (int)t.TotalDays;
Console.WriteLine(output);
}
}
//6.check the string should contain five vowels and in alphabetical order if it is in
that order output is 1 otherwise 2
//BR:if string contains repeated vowels then output is -1
public static void check_vowel(string input1)
{
int output=0;
StringBuilder sb = new StringBuilder();
foreach (char ch in input1)
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
{
sb.Append(ch);
}
}
int flag = 0;
string temp = sb.ToString();
if (temp.Contains('a') && temp.Contains('e') && temp.Contains('i') &&
temp.Contains('o') && temp.Contains('u') && temp.Length == 5)
{
flag = 1;
}
else
output = 2;
for(int i=0;i<temp.Length-1;i++)
for (int j = i + 1; j < temp.Length; j++)
{
if (temp[i] == temp[j])
output = -1;
}
if (flag == 1)
{
Regex ex = new Regex(@"aeiou");
if (ex.IsMatch(temp))
output = 1;
else
output = 2;
}
Console.WriteLine(output);
}
//input will be two lists and we have to sum the elements in both the lists which are not
common

if any list1 having -ve elements store -1 to output if list2 have the -ve numbers store -2
to the output if both the lists are having -ve nubers store -3 to output
ex: l1={1,2,3,4},l2={2,3,4,5,6} output=1+5+6=12
public static void sumofdistinctelements(List<Int32> input1,List<Int32> input2)
{
int flag1 = 0, flag2 = 0;
Int32 output1 = 0;
foreach(var i in input1)
{
if (i < 0)
flag1 = -1;
}
foreach (var i in input2)
{
if (i < 0)
flag2 = -1;
}
if (flag1 == -1 && flag2==-1)
{
output1 = -3;
}
else if (flag1 == -1)
{
output1 = -1;
}
else if (flag2 == -1)
{
output1 = -2;
}
else
{
List<Int32> l1 = new List<Int32>();
List<Int32> l2 = new List<Int32>();
l1 = input1.Except(input2).ToList();
l2 = input2.Except(input1).ToList();
output1 = l1.Sum() + l2.Sum();
}
Console.WriteLine(output1);
}
//two inputs one is string and another one is character reverse the input one and
separate each character with input 2
ex: rabbit,output:t-i-b-b-a-r
public static void reverse(string input1,char input2)
{
char[] c = input1.ToCharArray();
string output1 = "";
int i;
Array.Reverse(c);
StringBuilder sb = new StringBuilder();
for (i = 0; i < c.Length - 1; i++)
{
sb.Append(c[i]);
sb.Append(input2);

}
sb.Append(c[i]);
output1 = sb.ToString();
Console.WriteLine(output1);

}
//two inputs one is string and another one is delimiter we have to split the input1 with
the delimiter then have to find the longest word if two are
having the same length store the first word with the alphabetical order
ex: input: delhi-mumbai-kanpor
output : kanpoor
public static void laongstring(string input1,string input2)
{
char[] c = input2.ToCharArray();
string output1 = "";
string[] s = input1.Split(c);
List<string> l1 = new List<string>();
int count = 0, max = 0;
foreach (var i in s)
{
count = i.Length;
if (max < count)
max = count;
}
foreach (var i in s)
{
if (i.Length == max)
l1.Add(i);
}
if (l1.Count > 1)
{
l1.Sort();
output1 = l1[0];
}
else
{
output1 = l1[0];
}
Console.WriteLine(output1);
}
//input will string which is -ve numebr and we have to check whether the given input is in
given format or not if it in number format then store the positive value
to the string output else store -1 to output
ex: input1 : "-9876"
output:"9876"
public static void numformar(string input1)
{
string pattern = @"^[-][\d]+[\.]?[\d]*$";
Regex ex = new Regex(pattern);
string output1="";
if (ex.IsMatch(input1))
{
output1 = input1.Substring(1);
}
else

{
output1 = "-1";
}
Console.WriteLine(output1);
}
//input is an integer array if there is norepeated element in the array then store -1 to the
output else find the max span to the output
input: {1,2,3,4,5,1}
output:6
the span betwen two 1's is 6.
input:{1,2,3,2,1,2}
output:5 if two numbers are repeated then take the first element only
public static void maxspan(int[] input1)
{
int output = 0,flag=0;
for (int i = 0; i < input1.Length; i++)
{
for (int j = i + 1; j < input1.Length; j++)
{
if (input1[i] == input1[j])
{
flag = 1;
}
}
}
if (flag == 1)
{
List<int> l1 = new List<int>();
l1 = input1.ToList();
int span = 0;
for (int i = 0; i < l1.Count; i++)
{
span = l1.LastIndexOf(l1[i]) - l1.IndexOf(l1[i]);
if (span > 1)
{
output = span + 1;
break;
}
}
}
else
{
output = -1;
}
Console.WriteLine(output);
}
//shipping scenario
public static void shipping(Single input1, char input2)
{
Single diff;
Single output1 = 0;
switch (input2)
{

case 'R': if (input1 > 2000)


{
diff = input1 - 2000;
output1 = Convert.ToSingle(diff * 0.35);
output1 = output1 + Convert.ToSingle(2000 * 0.25);
}
else
{
output1 = Convert.ToSingle(input1*0.25);
}
break;
case 'X': output1 = 50;
if (input1 > 2000)
{
diff = input1 - 2000;
output1 =output1+Convert.ToSingle(diff * 0.35);
output1 = output1 + Convert.ToSingle(2000 * 0.25);
}
else
{
output1 =output1+Convert.ToSingle(input1 * 0.25);
}
break;
}
Console.WriteLine(output1);
}
//check whether given input string having only characters if it contains only characters
then find the longest word if it contains any digit
and special character store -1 to output if it contains wither digit or special character
store -2 to output
public static void checkstring(string input1)
{
string output = "";
int flag1 = 0, flag2 = 0;
foreach (var i in input1)
{
if (char.IsDigit(i))
flag1 = -1;
if (!(char.IsLetterOrDigit(i))&&(i!=' '))
flag2 = -1;
}
if (flag1 == -1 && flag2 == -1)
{
output = "-1";
}
else if (flag1 == -1)
{
output = "-2";
}
else if (flag2 == -1)
{
output = "-2";
}
else

{
string[] s = input1.Split(' ');
int count = 0, max = 0;
foreach (var i in s)
{
count = i.Length;
if (max < count)
{
max = count;
output = i;
}
}

}
Console.WriteLine(output);

}
static void Main(string[] args)
{
//sumofdistinctelements(new List<Int32> { 1, 2, 3, 4 }, new List<Int32>
{1,2,3,4,5});
//reverse("rabbit",'-');
//laongstring("delhi-India-arama", "-");
//numformar("-9876");
//maxspan(new int[] {1,4,2,6,7,1,2,3});
//shipping(4500, 'R');
checkstring("i am123 $^chandu");
}
}
//remove the repeated elements in the string except space
ex: input : this isre hai
output: this re ha
public static void remreptdcharexceptspace(string input1)
{
List<char> l1 = new List<char>();
foreach (var i in input1)
{
if (!(l1.Contains(i)) || i == ' ')
l1.Add(i);
}
char[] c = l1.ToArray();
string s = new string(c);
Console.WriteLine(s);
}
1.check the XXX-XXX-XXXX format if mathes print 1 else -1
-----------------------------------------------------------------public static void phone_number(string input1)
{
int output1;
Regex re = new Regex(@"^[\d]{3}-[\d]{3}-[\d]{4}$");
if (re.IsMatch(input1))
{
output1 = 1;
}

else
{
output1 = -1;
}
Console.WriteLine(output1);
}
2.sort the array in asce order array should contain only positive nos
----------------------------------------------------------------------public static void arraySort(int[] input1)
{
int[] output1;
int count = 0;
foreach(var i in input1)
{
if (i <= 0)
count++;
}
if(count==0)
{
Array.Sort(input1);
output1=input1;
}
else
{
output1=new int[]{-1};
}
foreach(var ele in output1)
Console.WriteLine(ele);
}
3.print the word which has maximum no.of vowels. if two or more words having same
no.of vowels print first occurance
----------------------------------------------------------------------------------------------------------------------public static void maxVowels(string input1)
{
string output1="";
input1=input1.ToLower();
int max = 0;
string[] str = input1.Split(' ');
foreach (var s in str)
{
int count = 0;
foreach (var ch in s)
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
{
count++;
}
}
if (count > max)
{
max = count;
output1 = s;
}

}
Console.WriteLine(output1);

}
4.capitalize first character of each word in a given string. remaining all chars should be
small
--------------------------------------------------------------------------------------------------public static void Capitalizewords(string input1)
{
int i = 0;
string output1 = "";
input1 = input1.ToLower();
string[] str = input1.Split(' ');
string[] arr=new string[str.Length];
foreach (var s in str)
{
char ch = char.ToUpper(s[0]);
string s1 = ch + s.Substring(1);
arr[i]=s1;
i++;
}
output1 = string.Join(" ", arr);
Console.WriteLine(output1);
}
5.count the digits in a given string. string shouldcontain whitespaces and alphanumerics
otherwise print -1
-----------------------------------------------------------------------------------------------------------public static void countdigits(string input1)
{
int c = 0, count = 0,output1, n = input1.Length;
foreach (var ch in input1)
{
if (char.IsLetterOrDigit(ch) || char.IsWhiteSpace(ch))
c++;
}
if (n == c)
{
foreach (var ch in input1)
{
if (char.IsDigit(ch))
count++;
}
output1 = count;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
}
//. Delete the elements in an array list at the position of multiples of 3
-----------------------------------------------------------------------------------------public static void Remove3multipleindexvalues(ArrayList input1)

int n=input1.Count;
List<object> l1 = new List<object>();
l1.Add(input1[0]);
for (int i = 2; i < n; i++)
{
if (i % 3 == 0)
{
object h =input1[i];
l1.Add(h);
}
}
foreach (var j in l1)
Console.WriteLine(j);
Console.WriteLine();
foreach (var k in input1)
{
if(!l1.Contains(k))
Console.WriteLine(k);
}

//. Remove the vowels from the even positions of the sting.
(Assume first letter of string is in 1st position )
Ex:- input : commitment
output : cmmitmnt
--------------------------------------------------------------------------------------------------------public static void vowelsateven(string input1)
{
int n = input1.Length;
StringBuilder sb=new StringBuilder();
for (int i = 0; i < n; i++)
{
if ((i % 2 == 1) && (input1[i] == 'a' || input1[i] == 'e' || input1[i] == 'i' ||
input1[i] == 'o' || input1[i] == 'u'))
{
}
else
{
sb.Append(input1[i]);
}
}
string s = sb.ToString();
Console.WriteLine(s);
}
.// Check whether the given input string is palindrome or not. And also check whether at
least 2 different
vowels are there in the string. If so return 1 else return -1
--------------------------------------------------------------------------------------------------------------------------public static void palindrome(string input1)
{
char[] a1 = input1.ToCharArray();

int count=0;
foreach (var c in a1)
{
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
count++;
}
string s1 = input1;
Array.Reverse(a1);
foreach (var l in a1)
Console.Write(l);
Console.WriteLine();
string s2 = new string(a1);
if(s1.Equals(s2) && count>=2 )
Console.WriteLine("1");
else
Console.WriteLine("-1");
}
Input1={"ab","a","abc","abcd"};
Input2=3
Delete al elements with the size 3 ("abc" in this example);
=> output1= 3(no.of elements after deleting "abc")
------------------------------------------------------------------------------------public static void deletsize3(string[] input1,int output1)
{
int n = input1.Length;
int count = 0;
foreach (var i in input1)
{
if (i.Length == output1)
{
}
else
{
count++;
}
}
Console.WriteLine(count);
}
Count Words
Input1="this is Cognizant academy"
Input2="hi this is a trainee";
How many times the second word of input2 ("this" in this xample) is repeated in input1.
Note: Consider Case
Output1=1.
--------------------------------------------------------------------------------------------public static void twoStrings(string input1, string input2)
{

string[] a1 = input1.Split(' ');


string[] a2 = input2.Split(' ');
int c=0;
foreach(var i in a1)
{
if(i.Equals(a2[1]))
c++;
}
Console.WriteLine(c);
}
public static void pancard(string input1)
{
Regex re = new Regex(@"^[A-Z]{3}[0-9]{4}[A-Z]{1}$");
if (re.IsMatch(input1))
Console.WriteLine(input1);
else
Console.WriteLine("wrong");
}
public static void input1contains2n3(string ip1, string ip2, string ip3)
{
int ind1 = ip1.IndexOf(ip2);
Console.WriteLine(ind1);
int ind2 = ip1.IndexOf(ip3);
Console.WriteLine(ind2);
if (ind1 < ind2)
Console.WriteLine("1");
else
Console.WriteLine("-1");
}
//Validate Password
validate based on following criteria:
minimum length is 6-20
should contain any of these @/_/#
should not start with number/special chars(@/#/_)
should not end with special chars
can contain numbers,letters,special char
---------------------------------------------------------------------------public static void password(string input1)
{
int n = input1.Length;
int c = 0,count=0;
foreach (var i in input1)
{
if (char.IsLetterOrDigit(i) || char.IsWhiteSpace(i) || i == '@' || i == "#" || i ==
"_")
count++;
}
if (n == count)
{
if (input1.Length >= 6 && input1.Length <= 20)
{
if ((input1[0] >= 'a' && input1[0] <= 'z') || (input1[0] >= 'A' && input1[0] <=

'Z'))
{

if ((input1[n - 1] >= 'a' && input1[n - 1] <= 'z') || (input1[n - 1] >= 'A' &&
input1[n - 1] <= 'Z') || (input1[n - 1] >= '0' && input1[n - 1] <= '9'))
{
if (input1.Contains('@') || input1.Contains('#') || input1.Contains('_'))
{
for (int i = 0; i < n; i++)
{
if (input1[i] >= '0' && input1[i] <= '9')
c++;
}
if (c > 0 )
{
Console.WriteLine("correct");
}
else
Console.WriteLine("wrong");
}
else
Console.WriteLine("wrong");
}
else
Console.WriteLine("wrong");
}
else
Console.WriteLine("wrong");
}
else
Console.WriteLine("wrong");
}
}
//In an array, find the largest difference b/w adjascent elements and return the index of
largest difference.
eg: input: {2,4,5,1,9,3,8}
output:4
-------------------------------------------------------------------------------------------------------------public static void maxdiffmaxnum(int[] input1)
{
List<int> l1 = new List<int>();
for (int i = 0; i < input1.Length - 1; i++)
{
l1.Add(Math.Abs(input1[i] - input1[i + 1]));
}
int max = l1.Max();
int index = l1.IndexOf(max);
if (input1[index] > input1[index + 1])
Console.WriteLine(input1[index]);
else
Console.WriteLine(input1[index + 1]);
foreach (var i in l1)
Console.WriteLine(i);
}
//5. First ArrayList:1 5 6 8 9

Second ArrayList: 5 6 7 9
output ArrayList:5 5 7 8
-------------------------------------------------------------logic: iterate the first array list find odd index elements and keep it in a new Array list
without changing its index
Iterate the second array list find the even index elements and keep it in a new Array list
without changing its index.
public static void evenoddpositions(int[] input1, int[] input2)
{
List<int> l1 = new List<int>();
int i;
//string s="";
for (i = 0; i < input1.Length; i++)
{
if (i % 2 == 0)
l1.Add(input1[i]);
else
l1.Add(input2[i]);
}
if (i % 2 == 1)
{
l1.Add(input2[i]);
}
foreach(var k in l1)
Console.WriteLine(k);
}
//Longest string in a list
List<string> input=new List<string>{"read","write","edit"};
List<string> output = new List<string>();
List<int> l = new List<int>();
//char ch = 'e';
foreach (var g in input)
{
l.Add(g.Length);
}
int n=l.IndexOf(l.Max());
output.Add(input[n]);
//checking whether '_' is present at same place in both strings of varying length
int flag = 0, c = 0;
string s = Console.ReadLine();
string p = Console.ReadLine();
int j = 0;
char[] s1 = s.ToCharArray();
char[] p1 = p.ToCharArray();
int[] x = new int[s1.Length];
int[] y = new int[p1.Length];
for (int z = 0; z < s1.Length; z++)
{
if (s1[z] == '-')
{
x[j++] = z;
}

}
//y walla
j = 0;
for (int z = 0; z < p1.Length; z++)
{
if (p1[z] == '-')
{
y[j++] = z;
}

for (int z = 0; z < y.Length; z++)


{
if(x[z]==y[z])
{
flag = 1;
}
else
{
flag = 0;
break;
}

if (flag == 1)
{
Console.WriteLine(1);
}
else
{
Console.WriteLine(-1);
}
Console.ReadKey(true);
//checking whether given character is not present as first letter in the list elements
List<string> input=new List<string>{"read","write","edit"};
List<string> output = new List<string>();
List<string> l = new List<string>();
char ch = 'e';
foreach (var g in input)
{
if (g.First() != ch)
{
l.Add ;
}
}
string[] ch1 = l.ToArray();
Array.Sort(ch1);
output = ch1.ToList();
foreach (var g in output)
{
Console.WriteLine ;
}

Console.ReadKey();
//add to list only those containing 1st letter as given char and sort them.
public static void countfirstchar(List<string> input1, char c)
{
List<string> l1 = new List<string>();
foreach (string s in input1)
{
if (s[0].Equals(c))
{
l1.Add(s);
}
}
int count = l1.Count();
l1.Sort();
foreach (string s in l1)
{
Console.WriteLine(s + "_" + count);
}
}
//finding largest difference index
public static void findlarge(int[] input1)
{
int d=0,t;
int op = 0;
for (int i = 0; i < input1.Length - 1; i++)
{
int dis =Math.Abs(input1[i] - input1[i + 1]);
if (dis > d)
{
d = dis;
op = i;
}
}
if (input1[op] > input1[op + 1])
t = op;
else
t = op + 1;
Console.WriteLine ;
}
//replace a word with a given word in a sentence
public static void replace(string word,string rep,string rep1)
{
//List<string> l1 = new List<string>();
if (word.Contains(rep))
{
string p=word.Replace(rep, rep1);
Console.WriteLine(p);
}
//Console.WriteLine(word);

}
//take alternative index position elements from two arrays

public static void evenoddpositions(int[] input1, int[] input2)


{
List<int> l1 = new List<int>();
int i, min;
//string s="";
if (input1.Length < input2.Length)
{
min = input1.Length;
}
else
{
min = input2.Length;
}
for (i = 0; i < min; i++)
{
if (i % 2 == 0)
l1.Add(input2[i]);
else
l1.Add(input1[i]);
}
//if (i % 2 == 1)
//{
// l1.Add(input2[i]);
//}
foreach (var k in l1)
Console.WriteLine(k);
}
#############

//count unique characters in string


class CountUniqueChar
{
public static int output1;
public static void countUnique(String str)
{
int i;
int j;
int count = 0;
Boolean f = true;
for (i = 0; i < str.Length; i++)
{
f = true;
for (j = 0; j < str.Length; j++)
{
if (str[i] == str[j] && i != j)
{
f = false;
break;

}
}
if (f)
{
count++;
}
}
if (count>0)
{
output1 = count;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
}
}
//color codes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
//color code... start with # ...6 letter is dere. dat means total 7 digits shld b dere.. no
digit no other special char
class ColourCode
{
public static int output1;
public static void colorCodeCheck(String input1)
{
Boolean f=true;
if(input1.Length==7)
{
if (input1.First() == '#')
{
for (int i = 1; i < input1.Length; i++)
{
if(!Char.IsLetter(input1[i]))
{
output1=-1;
f=false;
break;
}
}
if(f)
{
output1=0;
}
}
else
{

output1=-1;
}
}
else
{
output1=-1;
}
Console.WriteLine(output1);
}

}
////Write a program which contains a method which takes two strings and checks
//if the two string has same elements in terms of number and content. If the
condition is satisfied return 0 else -1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
class CompareString
{
//Write a program which contains a method which takes two strings and checks
//if the two string has same elements in terms of number and content. If the
condition is satisfied return 0 else -1.
//Hint :- "i was" and "i saw" are same.
public static int output1;
public static void compare2strings(String str, String str1)
{
Char[] ch = str.ToCharArray();
Char[] ch1 = str1.ToCharArray();
if (str.Length == str1.Length)
{
Array.Sort(ch);
Array.Sort(ch1);
String temp = new String(ch);
String temp1 = new String(ch1);
if (temp.CompareTo(temp1) == 0)
{
output1 = 0;
}
else
{
output1 = -1;
}
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
}

}
}
//count characters in string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
class CountTotalNoChar
{
// count toal no of character in a string array
public static int output1;
public static void countCharInArray(String[] input1)
{
output1 = input1.Sum(w => w.Length);
Console.WriteLine(output1);
}
}
}
//remove duplicates in a string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
// Write a method that will take a string and will remove duplicate characters keeping
only the first occurance.
//Input:- Kolkata Output:- Kolat
class Duplicate_Removal
{
public static String output1;
public static void duplicateRemoval(String input1)
{
Char[] temp = input1.Distinct().ToArray();
output1 = new String(temp);
Console.WriteLine(output1);
}
}

}
///find String of max length which contain a given char in a list.... if dere is no string wid
dat char... -1 to th
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
class List
{
//find String of max length which contain a given char in a list.... if dere is no string

wid dat char... -1 to the output ... if list contains number den -2 to output
public static String output1;
public static void findMaximumLengthString(List<String> input1, Char input2)
{
//StringBuilder temp = new StringBuilder();
int max = 0;
int count = 0;
for (int i = 1; i < input1.Count; i++)
{
foreach (Char c in input1[i])
{
if (Char.IsNumber(c))
{
count++;
}
}
if (!(count == input1[i].Length))
{
if (input1[i].Contains(input2))
{
if (max < input1[i].Length)
{
max = input1[i].Length;
output1 = input1[i];
}
}
if (max == 0)
{
output1 = "-1";
}
}
else
{
output1 = "-2";
break;
}
}
Console.WriteLine(output1);
}

}
}
//longest word
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
class LongestWord
{
public static String output1;
public static void findLongestWord(String input1)
{

String[] str = input1.Split(' ');


int len = str.Max(w => w.Length);
foreach (String s in str)
{
if (s.Length == len)
{
output1 = s;
}
}
Console.WriteLine(output1);

}
}
//print repeated element in array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
// print the repeated element in an array....................
class PrintRepeatative
{
public static int[] output1;
public static void printRepeatativeElement(int[] input1)
{
List<int> temp = new List<int>();
int i;
int j;
for (i = 0; i < input1.Length; i++)
{
for (j = 0; j < input1.Length; j++)
{
if (input1[i] == input1[j] && i != j)
{
if(!temp.Contains(input1[i]))
{
temp.Add(input1[i]);
}
}

}
output1 = new int[temp.Count];
for (i = 0; i < temp.Count;i++ )
{
output1[i] = temp[i];
}
foreach (int s in output1)
{
Console.WriteLine(s);
}

}
}

}
//vowels shd not b repeated
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
//vowels should nt b repeated .... if its nt repeated den 0 in output1 else -1
class VowelRepeatation
{
public static int output1;
public static void repeatation(String str)
{
int i;
int j;
Boolean f = true;
for (i = 0; i < str.Length; i++)
{
for (j = 0; j < str.Length; j++)
{
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
{
if (str[i] == str[j] && i != j)
{
f = false;
break;
}
}
}
if (f == false)
{
break;
}
}
if(f)
{
output1=0;
}
else
{
output1=-1;
}
Console.WriteLine(output1);
}
}
}
//vowels in alphabetic order
using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;
namespace test
{
class Class2
{
public static void check(String str)
{
bool f=true;
int i=0;
int j;
String arr="" ;
str=str.ToLower();
foreach (char c in str)
{
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
{
arr+= c;
}
}
for (j = 0; j < arr.Length-1; j++)
{
if (arr[j] > arr[j + 1])
{
f = false;
break;
}
}
if (f)
{
Console.WriteLine(1);
}
else
{
Console.WriteLine(-1);
}
}
}

}
//reverse each word
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
class ReverseEachWord
{
public static String output1;
public static void reverseWords(String input1)

{
String St = "";
String St1;
String[] str = input1.Split(' ');
Char[] temp;
foreach (String s in str)
{
temp = s.ToCharArray();
Array.Reverse(temp);
St1 = new String(temp);
St = St + St1;
St = St + " ";

}
output1 = St;
Console.WriteLine(output1);

}
//reverse substring as pair
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
class ReverseSubstring
{
public static String output1;
public static void reverseSubstringInPair(String input1)
{
int i;
Char temp;
Char[] str = input1.ToCharArray();
for (i = 0; i < str.Length; i = i + 2)
{
if (i + 1 != str.Length)
{
temp = str[i];
str[i] = str[i + 1];
str[i + 1] = temp;
}

}
}

}
output1 = new String(str);
Console.WriteLine(output1);

}
//string name print
using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;
namespace Final
{
//inptut = John Miler output Miler,J
class StringPlay
{
public static String output1;
public static void nameChange(String input1)
{
String[] arr = input1.Split(' ');
output1 = arr[1] + "," + arr[0].Substring(0, 1);
Console.WriteLine(output1);
}
}
}
//string rev and insert in mid
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Final
{
//input1 ="saikat" input2 ="saha" output="saiahaskat"
class StringPlay3
{
public static String output1;
public static void insertReverseString(String input1, String input2)
{
int n;
Char[] temp = input2.ToCharArray();
Array.Reverse(temp);
String str=new String(temp);
if (input1.Length % 2 == 0)
{
n = input1.Length / 2 + 1;
}
else
{
n = input1.Length / 2;
}
output1 = input1.Insert(n, str);
Console.WriteLine(output1);
}
}

}
//arraylist types
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Test1

{
class ArrayListType
{
public static void arrayListType(ArrayList al)
{
foreach( var c in al)
{
switch(c.GetType().Name)
{
case "Int32":
Console.WriteLine("Integer");
break;
case "Char":
Console.WriteLine("Character");
break;
case "String":
Console.WriteLine("String");
break;
}
}
}

}
//check num is increasing or not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test1
{
class IncreaseNO
{
public int checkIncreasing(int newNumber)
{
if (newNumber != 0)
{
string a = newNumber.ToString();
for(int i = 1; i < a.Length; i++)
{
int input1 = Convert.ToInt32(a[i-1]);
int input2 = Convert.ToInt32(a[i]);
if (input1 >= input2) //Note the reversed condition
{
return 0; //Gives the false result
}
}
return 1; //Computation finished, so the number is increasing
}
}
}

return 1;

//occurance of a char in string print hw many times


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test1
{
class OccuranceCh
{
public static SortedList<char, int> CountOccurance(String s)
{
var occurances = new SortedList<char, int>();
foreach (char c in s)
{
if (occurances.ContainsKey(c))
occurances[c] = occurances[c] + 1;
else
occurances[c] = 1;
}
return occurances;
}
}

}
//password validation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
class Class1
{
public static void validatepassword(string input1)
{
int count = 0;
input1 = input1.ToLower();
foreach (char i in input1)
{
if (char.IsDigit(i))
count = 1;
}
if (input1.Length >= 8)
{
if (input1.First() >= 'a' && input1.First() <= 'z')
{
if ((input1.Last() >= '0' && input1.Last() <= '9') || (input1.First() >= 'a' &&
input1.First() <= 'z'))
{
if (input1.Contains('#') || input1.Contains('_') || input1.Contains('@'))
{
if (count == 1)
Console.WriteLine("1");

else
Console.WriteLine("-1");

}
else
Console.WriteLine("-1");
}
else
Console.WriteLine("-1");

}
else
Console.WriteLine("-1");

}
}

}
else
{
Console.WriteLine("-1");
}

}
//roman to number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class RomanToNumber
{
public static void ConvertRomanToNumeral(string s)
{
int[] count = new int[s.Length];
int d;
s = s.ToUpper();
char[] cc = s.ToCharArray();
for (int i = 0; i < cc.Length; i++)
{
switch (cc[i])
{
case 'M':
case 'm':
{
count[i] = 1000;
break;
}
case 'D':
{
count[i] = 500;
break;
}
case 'C':
{
count[i] = 100;
break;
}

case 'L':
{
count[i]
break;
}
case 'X':
{
count[i]
break;
}
case 'V':
{
count[i]
break;
}
case 'I':
{
count[i]
break;
}

= 50;

= 10;

= 5;

= 1;

}
}
d = count[count.Length - 1];
for (int i = 0; i < count.Length - 1; i++)
{
if (count[i] >= count[i + 1])
{
d = d + count[i];
}
else
{
d = d - count[i];
}
}
Console.WriteLine(d);
}

}
//telephone bill
23.telephone bill
Telephone bill
if call below 300 cost is 200
after for 50 calls cost is .60
after for 50 calls cost is .50
after for all calls cost is .40
ie 200+(x*.60)+(y*.50)+(z*.40)
calcualte the call cost
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finaltelephonebill
{
class Program

{
public static void bill(int input1)
{
double output1;
if (input1 <= 300)
{
output1 = 200;
Console.WriteLine(output1);
}
else if (input1 > 300 && input1 <= 350)
{
output1 = 200 + ((input1 - 300) * 0.60);
Console.WriteLine(output1);
}
else if (input1 > 350 && input1 <= 400)
{
output1 = 200 + (50 * 0.60) + ((input1 - 350) * 0.50);
Console.WriteLine(output1);
}
else if(input1>400)
{
output1 = 200 + (50 * 0.60) + (50 * 0.50) + ((input1 - 400) * 0.40);
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.bill(305);
}
}
}
//calc vat
29.calculate vat
If product =?M?
Vat= 5%
?V?
Vat=12%
?C?
Vat=6.25%
?D?
Vat=6%
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalcalculate_Vat
{
class Program
{
public static void vat(double input1, char input2)
{
double output1;
double percent;
double vat;

switch (input2)
{
case 'M':
percent = 5;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
case 'V':
percent = 12;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
case 'C':
percent = 6.25;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
case 'D':
percent = 7;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
default:
output1 = -1;
Console.WriteLine(output1);
break;
}
}
static void Main(string[] args)
{
Program.vat(20000, 'M');
}

}
}
//
18.sum of squares
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace squareoffirstNnumber
{
class Program
{
public static void sumofsquare(int input1)
{
int output1=0;
for (int i = 1; i <= input1; i++)
{
output1 = output1 + (i * i);

}
Console.WriteLine(output1);

}
static void Main(string[] args)
{
Program.sumofsquare(2);
}

}
}
19.sum of cubes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace squareoffirstNnumber
{
class Program
{
public static void sumofsquare(int input1)
{
int output1=0;
for (int i = 1; i <= input1; i++)
{
output1 = output1 + (i * i * i);
}
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.sumofsquare(2);
}
}
}
20.string reverse
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalstringreverse
{
class Program
{
public static void reverse(string input1)
{
string output1;
char[] ch = input1.ToCharArray();
Array.Reverse(ch);
output1 = new string(ch);
Console.WriteLine(output1);
}
static void Main(string[] args)
{
Program.reverse("swetha");
}

}
}
21.student marks
take 5 subject marks and find total nd avg
// if avg >= 60 dn output1 ="First class"
// if avg >=50 and avg<= 59 dn output1= "second class"
// if avg >=40 and avg<= 49 dn output1 = "third class"
// else
//
output1 = "failed"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalstudentmarks
{
class Program
{
public static void marks(int input1, int input2, int input3, int input4, int input5)
{
string output1;
int total = input1 + input2 + input3 + input4 + input5;
int average = total / 5;
if (average >= 60)
{
output1 = "First Class";
Console.WriteLine(output1);
}
else if (average >= 50 && average <= 59)
{
output1 = "Second Class";
Console.WriteLine(output1);
}
else if (average >= 40 && average <= 49)
{
output1 = "Third Class";
Console.WriteLine(output1);
}
else
{
output1 = "Failed";
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.marks(88, 87, 89, 98, 99);
}
}
}
//xml
using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;
using System.Xml;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
// String output="";
string myXmlString =
"<Names><Name><FirstName>John</FirstName><LastName>Smith</LastName></N
ame><Name><FirstName>James</FirstName><LastName>White</LastName></Nam
e></Names>";
XmlDocument xd = new XmlDocument();
xd.LoadXml(myXmlString);
//XmlNodeList xn = xd.SelectNodes("/Names/Name");
XmlNodeList xn= xd.GetElementsByTagName("Name");
foreach (XmlNode item in xn)
{
Console.WriteLine(item["FirstName"].InnerText);
}
}
}

}
//xml2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace xml1
{
class Program
{
static void Main(string[] args)
{
string s = "<Names><Name type='M'>Arun Karthick</Name><Name
type='M'>Vamsee</Name><Name type='F'>Priya</Name></Names>";
XmlDocument xd = new XmlDocument();
xd.LoadXml(s);
XmlNodeList xn = xd.SelectNodes("/Names/Name[@type='F']");
foreach (XmlNode item in xn)
{
// Console.WriteLine(item.Name);
Console.WriteLine(item.InnerText);
// Console.Write(item.Value);
}
}
}
}
//xml3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
namespace xml3
{
class Program
{
static void Main(string[] args)
{
string s = "<Names><Name type='M'>Arun Karthick</Name><Name
type='M'>Vamsee</Name><Name type='F'>Priya</Name></Names>";
XmlReader reader = XmlReader.Create(new StringReader(s));
while (reader.Read())
{
if (reader.HasAttributes)
{
Console.WriteLine(reader.Name + "Attribute");
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
Console.WriteLine("Name: " + reader.Name + ", value: " + reader.Value);
}
reader.MoveToElement();
}
}
}
}
}
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
namespace xml6
{
class Program
{
static void Main(string[] args)
{
String xmlString =
@"<bookstore>
<book genre='autobiography' publicationdate='1981-03-22' ISBN='1-861003-110'>
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>

</book>
</bookstore>";
// Create an XmlReader
XmlReader reader = XmlReader.Create(new StringReader(xmlString));
// XmlTextReader reader = new XmlTextReader(@"C:\books.Xml");
reader.MoveToContent();
reader.MoveToFirstAttribute();
Console.WriteLine("First Element Name" + reader.Name);
while (reader.Read())
{
if (reader.HasAttributes)
{
Console.WriteLine(reader.Name + "Attribute");
for (int i = 0; i < reader.AttributeCount; i++)
{
// reader.MoveToAttribute(i);
reader.MoveToNextAttribute();
Console.WriteLine("Name: " + reader.Name + ", value: " + reader.Value);
}
reader.MoveToElement();
}
}
}

}
//
using
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Xml;
System.IO;

namespace ConsoleApplication2
{
class Program
{
public static void readXml()
{
string input=@"<?xml version=""1.0"" encoding=""utf-8""?
><books><novel><name>Harry
potter</name><author>J.K.Rowling</author></novel></books>";
using (StringReader rdr=new StringReader(input))
{
using (XmlTextReader xrdr = new XmlTextReader(rdr))
{
while (xrdr.Read())
{
if (xrdr.IsStartElement())
{
switch (xrdr.Name)
{
case "books":

Console.WriteLine();
break;
case "novel":
Console.WriteLine();
break;
case "name":
Console.WriteLine(xrdr.ReadString());
break;
case "author":
Console.WriteLine(xrdr.ReadString());
break;
}
}
}

}
}
public static void readXml1()
{
XmlReader xr = XmlReader.Create("myxml.xml");
while (xr.Read())
{
if (xr.IsStartElement())
{
switch (xr.Name)
{
case "book":
Console.WriteLine();
break;
case "novel":
Console.WriteLine();
break;
case "title":
string attr1 = xr["name"];
string attr2 = xr["author"];
if (attr1 != null)
{
Console.WriteLine(attr1);
}
if (attr2 != null)
{
Console.WriteLine(attr2);
}
break;
case "price":
if (xr.Read())
{
Console.WriteLine(xr.Value);
}
break;
}
}
}

}
public static void readXml2()
{
XmlDocument xd = new XmlDocument();
xd.Load("myxml.xml");
XmlNodeList nl = xd.SelectNodes("//book/novel/price");
foreach (XmlNode n in nl)
{
Console.WriteLine(n.InnerText);
}
XmlNodeList nl1 = xd.SelectNodes("//book/novel/title");
foreach (XmlNode n1 in nl1)
{
Console.WriteLine(n1.Attributes["name"].Value);
}
xd.Save("myxml.xml");

}
static void Main(string[] args)
{
Program.readXml2();
}

}
}
//list must not contain char as first letter and sort based on length
public static void liststrng(List<string> input1, char input2)
{
List<string> output1 = new List<string>();
List<string> l1 = new List<string>();
List<string> l2 = new List<string>();
bool flag = false;
foreach (var i in input1)
{
l2.Add(i.ToLower());
}
foreach (var i in l2)
{
for (int j = 0; j < i.Length; j++)
{
if (!(char.IsLetter(i[j])))
{
flag = true;
}
}
}
if (input1.Count == 0)
{
output1.Add("-1");
}
else if (flag)
{
output1.Add("-2");
}

else
{
foreach (var i in l2)
{
if (!(i[0] == input2)&&i.Contains(input2))
{
l1.Add(i);
}
}
string t = "";
for (int i = 0; i < l1.Count;i++ )
{
for (int j = i + 1; j < l1.Count; j++)
{
if (l1[i].Length > l1[j].Length)
{
t = l1[j];
l1[j] = l1[i];
l1[i] = t;
}
}
}
output1 = l2;

}
foreach (var i in output1)
{
Console.WriteLine(i);
}
}

//replace word with *


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReplacingString
{
class StringPlay1
{
public static string output1;
public static void replaceString(string input1,int input2,char input3)
{
string[] arr=input1.Split(' ');
int i;
int j;
bool f = true;
foreach (char c in input1)
{
if(!Char.IsLetter(c)&&(c!=' '))
{
f=false;

break;
}

}
if (!Char.IsLetterOrDigit(input3) && !Char.IsWhiteSpace(input3))
{
if (f)
{
if (input2 > 0)
{
for (i = 0; i < arr.Length; i++)
{
if (i == input2 - 1)
{
for (j = 0; j < arr[i].Length; j++)
{
output1 += input3;
}
}
else
{
output1 += arr[i];
}
output1 += " ";
}
output1.TrimEnd();
}
else
{
output1 = "-2";
}
}
else
{
output1 = "-1";
}
}
else
{
output1 = "-3";
}
Console.WriteLine(output1);
}
}

##############
28.reversed string insert in the middle of another string
=====================================================
==========================================
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finalstringinsert
{
class Program
{
public static void insert(string input1, string input2)
{
string output1;
int count = input1.Length;
if (count % 2 == 0)
{
char[] ch = input2.ToCharArray();
Array.Reverse(ch);
string reverse = new string(ch);
int middle=count/2;
output1 = input1.Insert(middle, reverse);
Console.WriteLine(output1);
}
else
{
output1 = "-1";
Console.WriteLine(output1);
}
}
static void Main(string[] args)
{
Program.insert("swetha", "sabari");
}
}
}
##############
string s3 = "my name is jd";
string[] s1 = s3.Split(' ');
// var k = s1.Max(s => s.Length);
var d = s1.Select(m => m.Count(c => c == 'a' |c=='e'|c=='i'|c=='o'|c=='u'));
var t = d.Select((name, index) => new { word = name, indexer = index });
int f = d.Max();
foreach (var i in t)
{
if (i.word == f)
{
Console.WriteLine(s1[i.indexer]);
}
}

-You received this message because you are subscribed to the Google Groups "chn_dj" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
chn_dj+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Potrebbero piacerti anche