Académique Documents
Professionnel Documents
Culture Documents
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int AddReverse(int[] ar,int k)
{
int sum = 0,rem,rev=0;
for (int i = 0; i < ar.Length; i++)
{
if (ar[i] > k)
{
sum = sum + ar[i];
}
}
while (sum > 0)
{
rem = sum % 10;
rev = rev * 10 + rem;
sum = sum / 10;
}
return rev;
}
}
2. ADDDAYS
using System;
class Program
{
public static void Main(string[] args)
{
string inputDate = Console.ReadLine();
int day = Convert.ToInt32(Console.ReadLine());
string output = UserProgramCode.addDays(inputDate, day);
if (output.Equals("-1"))
Console.WriteLine("n value is negative");
else if (output.Equals("-2"))
Console.WriteLine("Invalid date format");
else
Console.WriteLine(output);
}
}
using System;
using System.Globalization;
class UserProgramCode
{
public static string addDays(string date, int day)
{
//Fill your code here
DateTime dt;
string output;
if (day < 0)
{
return "-1";
}
else
{
bool res = DateTime.TryParseExact(date, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt = dt.AddDays(day);
output = dt.ToString("MM/dd/yyyy");
return output;
}
else
{
return "-2";
}
// return output;
}
}
}
3.ADDNON COMMON
using System;
class Program
{
public static void Main(string[] args)
{
int i;
int size1 = Convert.ToInt32(Console.ReadLine());
int size2 = Convert.ToInt32(Console.ReadLine());
int[] arr1 = new int[size1];
int[] arr2 = new int[size2];
for (i = 0; i < size1; i++)
{
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
for (i = 0; i < size2; i++)
{
arr2[i] = Convert.ToInt32(Console.ReadLine());
}
using System;
class UserProgramCode
{
public static int validateNumber(int[] arr1,int size1,int[] arr2,int size2)
{
// fill your code here
int check1=0, check2=0, flag=0,sum=0;
for (int i = 0; i < arr1.Length;i++ )
{
if (arr1[i] < 0)
{
check1 = -1;
}
}
if (arr2[i] < 0)
{
check2 = -2;
}
}
if (check1 == (-1) && check2 == (-2))
return -3;
else if(check1==(-1) && check2 ==0)
{
return -1;
}
else if (check2 == (-2) && check1 == 0)
{
return -2;
}
else
{
for (int i = 0; i < size1;i++ )
{
flag = 0;
for (int j = 0; j < size2;j++ )
{
if (arr1[i] == arr2[j])
{
flag = 1;
}
}
if(flag==0)
{
sum = sum + arr1[i];
}
for (int i = 0; i < size2; i++)
{
flag = 0;
for (int j = 0; j < size1; j++)
{
if (arr2[i] == arr1[j])
{
flag = 1;
}
}
if (flag == 0)
{
sum = sum + arr2[i];
}
return sum;
}
}
}
4.ADJASCENTCHARS
using System;
public class Program {
public static void Main() {
string s = Console.ReadLine();
Console.WriteLine(UserMainCode.ProcessString(s));
Console.Read();
}
}
using System;
public class UserMainCode {
public static string ProcessString(string s) {
string str = "";
int i;
for (i = 0; i < s.Length - 1; i++)
{
if (s[i] == s[i + 1])
{
str = str + s[i] + '*' + s[i + 1];
i += 1;
}
else
str = str + s[i];
}
if (i == s.Length - 1)
str += s[i];
return str;
}
}
5.ANAGRAM
using System;
class Program
{
public static void Main(string[] args)
{
string input1 = Console.ReadLine();
string input2 = Console.ReadLine();
bool result = UserProgramCode.checkAnagram(input1, input2);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class UserProgramCode
{
public static bool checkAnagram(string input1, string input2)
{
string in1 = input1.ToLower();
char[] charin = in1.ToCharArray();
Array.Sort(charin);
6.ANAGRAMS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Anagrams
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
s.ToLower();
byte[] ASCIIValues = Encoding.ASCII.GetBytes(s);
int sum = 0;
foreach (byte b in ASCIIValues)
{
sum = sum + b;
}
string s1 = Console.ReadLine();
s1.ToLower();
int sum1 = 0;
byte[] ASCIIValues1 = Encoding.ASCII.GetBytes(s1);
foreach (byte b in ASCIIValues1)
{
sum1 = sum1 + b;
}
if( sum==sum1)
Console.WriteLine("True");
else
Console.WriteLine("False");
Console.ReadLine();
//string s = Console.ReadLine();
//string s1 = Console.ReadLine();
//Array.Sort(array);
//Array.Sort(array1);
//if (b.Equals(c))
//{
//
Console.WriteLine("TRUE");
//}
//else
//{
//
//}
Console.WriteLine("FALSE");
//Console.ReadLine();
}
}
}
7.ARRANGEINASCENDINGORDEROFVOWELS-DOUBT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication26
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string[] a = s.Split(' ');
int[] count = new int[a.Length];
string s1 = "aeiou";
count[i]++;
}
}
}
Console.ReadLine();
}
}
}
8.ARRAY MEDIAN
using System;
class Program
{
public static void Main( string[] args )
{
int size;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for(int i=0;i<size;i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
int result = UserProgramCode.calculateMedian(arr);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class UserProgramCode
{
public static int calculateMedian(int[] arr)
{
// fill your code here
int n = arr.Length;
Array.Sort(arr);
if (n % 2 == 0)
{
int b = (arr[n / 2] + arr((n / 2) + 1)) / 2;
return b;
}
else
return arr[n / 2];
Console.ReadLine();
}
}
9.ARRAYMEDIAN
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace quest
{
class Program
{
static void Main(string[] args)
{
int n, i;
n = Convert.ToInt32(Console.ReadLine());
int[] arr=new int[n];
for (i = 0; i < n; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Array.Sort(arr);
string d="";
for (i=0; i < n; i++)
{
if (arr[i] > 0)
{
if (arr.Length % 2 == 0)
{
double a = (arr[(arr.Length / 2) - 1]);
double b = (arr[arr.Length / 2]);
double c = (a + b) / 2;
d = "" + Math.Ceiling(c);
}
else
{
d = "" + arr[arr.Length / 2];
}
}
else if (arr[i] == 0)
{
d="-2";
break;
}
else if(arr[i]<0)
{
d = "-1";
break;
}
}
Console.WriteLine(d);
Console.ReadLine();
}
}
}
10.BILL AMOUNT
using System;
class Program
{
public static void Main( string[] args )
{
char input1;
string input2;
int input3;
input1 = Convert.ToChar(Console.ReadLine());
input2 = Console.ReadLine();
input3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.calculateBillAmount(input1,input2,input3));
}
}
using System;
class UserProgramCode
{
public static int calculateBillAmount(char input1,string input2,int input3)
{
if(input3>0)
{
if(input1=='C' && input2.Equals("NAC"))
return input3*1000;
else if(input1=='C' && input2.Equals("AC"))
return input3*1300;
else if(input1=='H' && input2.Equals("NAC"))
return input3*800;
else if(input1=='H' && input2.Equals("AC"))
return input3*1100;
else if(input1=='B' && input2.Equals("NAC"))
return input3*1100;
else if(input1=='B' && input2.Equals("AC"))
return input3*1400;
else
return -1;
}
else
return -1;
Console.ReadLine();
}
}
11.BATCH CODE
using System;
class Program
{
public static void Main( string[] args )
{
string input1,output;
input1 = Console.ReadLine();
output = UserProgramCode.checkBatch(input1);
Console.WriteLine(output);
Console.ReadKey();
}
}
using System;
class UserProgramCode {
public static string checkBatch(string input1)
{
int len,i;
string x=input1,loc,bb,bc,cc;
}
else
return "-1";
bb = x.Substring(3, 2);
if (int.Parse(bb) >= 0 && int.Parse(bb) < 99)
{
}
else
return "-2";
bc = x.Substring(7, 3);
cc = x.Substring(5, 2);
if (cc.Equals("DN"))
{
}
else
return "-3";
if (int.Parse(bc) >= 0 && int.Parse(bc) < 999)
{
}
else
return "-2";
if (loc.Equals("CHN"))
return "DotNet batch " + bc + " has joined in 20" + bb + " year and is at
Chennai Location";
else if (loc.Equals("CBE"))
return "DotNet batch " + bc + " has joined in 20" + bb + " year and is at
Coimbatore Location";
else if (loc.Equals("KOC"))
return "DotNet batch " + bc + " has joined in 20" + bb + " year and is at
Kochi Location";
else if (loc.Equals("PUN"))
return "DotNet batch " + bc + " has joined in 20" + bb + " year and is at
Pune Location";
else if (loc.Equals("BGL"))
return "DotNet batch " + bc + " has joined in 20" + bb + " year and is at
Bangalore Location";
else if (loc.Equals("HYD"))
return "DotNet batch " + bc + " has joined in 20" + bb + " year and is at
Hyderabad Location";
else if (loc.Equals("KOL"))
return "DotNet batch " + bc + " has joined in 20" + bb + " year and is at
Kolkata Location";
else
return "";
}
}
12.BMI CALC
using System;
namespace myprograms
{
class Program
{
public static void Main(){
float input1;
float input2;
float.TryParse(Console.ReadLine(),out input1);
float.TryParse(Console.ReadLine(),out input2);
Console.WriteLine(UserProgramCode.BMICalc(input1,input2));
Console.ReadLine();
}
}
}
using System;
namespace myprograms
{
class UserProgramCode{
string str;
if (input1 > 0 && input2 > 0)
{
}
else if (bmi >= 18.5 && bmi <= 24.9)
{
str = "Normalweight";
}
else if (bmi >= 25 && bmi <= 29.9)
{
str = "Overweight";
}
else
{
str = "Obesity ";
}
}
else
{
str = "InvalidInput";
return str;
}
}
}
13.Boundary average
using System;
class Program
{
public static void Main( string[] args )
{
int num=Convert.ToInt32(Console.ReadLine());
using System;
class UserProgramCode
{
public static string getBoundaryAverage(int[] num)
{
double max = 0;
double min;
min = num[0];
for (int i = 0; i < num.Length; i++)
{
if (num[i] > max)
{
max = num[i];
{
min = num[i];
}
}
double ans = (max + min) / 2;
}
}
14.boundary avg
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace boundary_avg
{
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] array = new int[size];
for (int i = 0; i < size; i++)
{
array[i] = Convert.ToInt32(Console.ReadLine());
}
float output =((array.Max() + array.Min())/2.0f);
Console.WriteLine(output.ToString("0.0"));
Console.ReadLine();
}
}
}
15.BoundayAverage
using System;
class Program
{
public static void Main( string[] args )
{
int num=Convert.ToInt32(Console.ReadLine());
int[] input = new int[num];
for(int i = 0;i<num;i++)
{
input[i] = Convert.ToInt32(Console.ReadLine());
}
string output = UserProgramCode.getBoundaryAverage(input);
Console.WriteLine(output);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static string getBoundaryAverage(int[] num)
{
//fill your code here
double max = 0;
double min;
min=num[0];
for (int i = 0; i < num.Length; i++)
{
if (num[i] > max)
{
max = num[i];
}
return ans1;
}
}
16.CALC SALARY
using System;
class Program
{
public static void Main( string[] args )
{
int experience,oldSalary,salary;
string expertise;
experience = Convert.ToInt32(Console.ReadLine());
expertise = Console.ReadLine();
oldSalary = Convert.ToInt32(Console.ReadLine());
salary = UserProgramCode.calculateNewSalary(experience,expertise,oldSalary);
if(salary == -1)
Console.WriteLine("Invalid Experience");
else if(salary == -2)
Console.WriteLine("Invalid Technology expertise classification");
else if(salary == -3)
Console.WriteLine("Invalid Salary");
else
Console.WriteLine("Your Salary is fixed as Rs {0}",salary);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
}
if (expertise != "RS" && expertise != "CS")
{
sa = -2;
ctr++;
}
if (oldSalary > 100000 || oldSalary < 0)
{
sa = -3;
ctr++;
}
if(ctr==0)
{
sal = sal + (oldSalary * 0.3);
if (experience > 3 && experience <= 5)
{
sal = sal + (oldSalary * 0.05);
}
else if (experience > 5 && experience <= 8)
{
sal = sal + (oldSalary * 0.10);
}
else if (experience > 8)
{
sal = sal + (oldSalary * 0.15);
}
if(expertise=="RS")
{
sal=sal+(oldSalary*0.05);
}
sal = sal + oldSalary;
sa = Math.Round(sal);
}
return (int)sa;
}
}
17.Calculate Grade
using System;
class Program
{
public static void Main( string[] args )
{
int size;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for(int i = 0;i<size;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
string result = UserProgramCode.getGrade(arr);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static string getGrade(int[] arr)
{
int max = arr[1], i;
int id=arr[0];
string grade="";
}
else if(arr[i]<0||arr[i-1]<0)
{
grade = "Invalid Input";
return grade;
}
else if (arr.Length<= 2)
{
grade = "Grading is not possible";
return grade;
}
else if (arr.Length % 2 != 0)
{
grade = "Scores not provided for all Students";
return grade;
}
}
if (max >= 80)
{
grade = "Student_ID "+id+" has passsed in DISTINCTION";
}
else if (max >= 60 && max < 80)
{
grade = "Student_ID "+id+" has passed in FIRST CLASS";
}
else if (max >= 45 && max < 60)
{
grade = "Student_ID "+id+" has passed SECOND CLASS";
}
namespace dumpsMaking
{
class NewSalary
{
static void Main(string[] args)
{
int x=calculateNewSalary(int.Parse(Console.ReadLine()), Console.ReadLine(),
int.Parse(Console.ReadLine()));
if (x == -1)
{
Console.WriteLine("Invalid Technology expertise classification");
}
else if (x == -2)
{
Console.WriteLine("Invalid Experience");
}
else if (x == -3)
{
Console.WriteLine("Invalid Salary");
}
else
{
Console.WriteLine("Your Salary is fixed as Rs " + x);
}
Console.ReadLine();
}
public static int calculateNewSalary(int exp,string talent,int salary)
{
if (talent.Equals("CS")||talent.Equals("RS"))
{
if (exp < 0 || exp > 25)
{
return -2;
}
else if (salary < 0 || salary > 100000)
{
return -3;
}
else
{
double newSalary=salary;
int rate=30;
//double newSalary = salary + 0.3 * salary;
if (exp < 5)
rate = rate + 5;
//newSalary = newSalary + 0.05 * newSalary;
else if (exp < 8)
}
}
}
19.CALCULATE RESULT
using System;
class Program
{
public static void Main(string[] args)
{
int m1 = Convert.ToInt32(Console.ReadLine());
int m2 = Convert.ToInt32(Console.ReadLine());
int m3 = Convert.ToInt32(Console.ReadLine());
int m4 = Convert.ToInt32(Console.ReadLine());
int m5 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.calculateResult(m1, m2, m3, m4, m5));
}
}
using System;
class UserProgramCode
{
public static String calculateResult(int m1, int m2, int m3, int m4, int m5)
{
//Fill your code here
float c;
c = (float)(m1 + m2 + m3 + m4 + m5);
float d;
d = (float)(c / 5);
//d = d * (100);
if (d > 60)
return "First Class";
else if (d >= 50 && d <= 59)
return "Second Class";
else if (d >= 40 && d <= 49)
return "Third Class";
else
return "Failed";
}
}
20.CALCULATE TAKE HOME SALARY
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace takehomesalary
{
class Program
{
static void Main(string[] args)
{
int rslt;
Console.WriteLine("enter the salary");
int Salary= Convert.ToInt32(Console.ReadLine());
rslt=UserProgramCode.calculateHomeSalary(Salary);
if (rslt == -1)
{
Console.WriteLine("Invalid Input");
}
else
{
Console.WriteLine(rslt);
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace takehomesalary
{
class UserProgramCode
{
public static int calculateHomeSalary(int Salary)
{
int PF=0;
int MedicalInsurance=678;
int HomeSal=0;
if (Salary > 0)
{
if (Salary < 15000)
{
PF = 750;
HomeSal = (Salary - PF - MedicalInsurance);
}
else if (Salary >= 15001 && Salary <= 22000)
{
PF = 850;
HomeSal = Salary - PF - MedicalInsurance;
}
else if (Salary >= 22001 && Salary <= 30000)
{
PF = 925;
HomeSal = Salary - PF - MedicalInsurance;
}
else if (Salary > 30000)
{
PF = 1000;
HomeSal = Salary - PF - MedicalInsurance;
}
return HomeSal;
}
else
{
return -1;
}
}
}
}
21.CALCULATE BILL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateBill
{
class Program
{
static void Main(string[] args)
{
string input1, input2;
int perUnitCharges, bill;
input1 = Console.ReadLine();
input2 = Console.ReadLine();
perUnitCharges = Convert.ToInt32(Console.ReadLine());
bill = UserProgramCode.calculateBill(input1, input2, perUnitCharges);
Console.WriteLine(bill);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateBill
{
class UserProgramCode
{
public static int calculateBill(string prevRead, string curRead, int
perUnitCharges)
{
int billAmount=0, i=0;
string i1 = prev.ToString();
string i2 = cur.ToString();
int p = int.Parse(i1);
int cr = int.Parse(i2);
return billAmount;
}
}
}
22.CALUCLATE BILL AMOUNT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dumps
{
class UserMainCode
{
static void Main(string[] args)
{
int x=calculateBillAmount(double.Parse(Console.ReadLine()),
(char)Console.Read());
if (x == -1)
{
Console.WriteLine("Negative Values");
}
else if (x == -2)
{
Console.WriteLine("No Items");
}
else
Console.WriteLine(x);
Console.ReadKey();
return (int)amount;
}
}
else
return -2;
}
}
}
23.CALCULATE CHARGE PARKING
using System;
class Program
{
public static void Main( string[] args )
{
string date1 = Console.ReadLine();
string date2 = Console.ReadLine();
class UserProgramCode
{
class Program
{
public static void Main(string[] args)
{
int cost = Convert.ToInt32(Console.ReadLine());
char fltype = Convert.ToChar(Console.ReadLine());
char dctype = Convert.ToChar(Console.ReadLine());
int result = UserProgramCode.calculateCost(cost, fltype, dctype);
if (result == -1)
Console.WriteLine("Too low cost");
else if (result == -2)
class UserProgramCode
{
public static int calculateCost(int cost, char fltype, char dctype)
{
if (dctype != 'S' && dctype != 'C')
return (-3);
if (fltype != 'N' && fltype != 'E')
return (-2);
int value = 0;
if (dctype == 'S')
value = value + 15000;
if (dctype == 'C')
value = value + 25000;
if (fltype == 'N')
value = value + (cost * 400);
if (fltype == 'E')
value = value + (cost * 700);
if (value < 20000)
return -1;
else
return (value);
}
}
25.CALCULATE TAKE HOME SALARY
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateTakeHomeSalary
{
class Program
{
static void Main(string[] args)
{
int a = Convert.ToInt32(Console.ReadLine());
int t = UserProgramCode.calculateHomeSalary(a);
if (t == -1)
{
Console.WriteLine("Invalid Input");
}
else
{
Console.WriteLine(t);
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateTakeHomeSalary
{
class UserProgramCode
{
public static int calculateHomeSalary(int a)
{
int mi=678;
int pf=0;
if (a > 0)
{
if (a < 15000)
{
pf = 750;
}
else if (a > 15000 && a <= 22000)
{
pf = 850;
}
else if (a > 22000 && a <= 30000)
{
pf = 925;
}
else if (a > 30000)
{
pf = 1000;
}
int ths = (a -pf - mi);
return ths;
}
else
{
return -1;
}
}
}
}
26.CAPITAL
using System;
class Program
{
public static void Main()
{
Console.WriteLine(UserProgramCode.printCapitalized(Console.ReadLine()));
}
}
using System;
using System.Linq;
class UserProgramCode
{
public static String printCapitalized(String input1)
{
// string input = "Features Of JAVA2 ";
input1 = input1.ToLower();
char a;
int count = 0;
string[] str = input1.Split(' ');
string output = "";
foreach (string s in str)
{
count = 0;
foreach (char ch in s)
{
a = ch;
if (count == 0)
{
if (char.IsLetter(ch))
{
a = (char)((int)ch - 32);
}
}
output = output + a;
count++;
}
output = output + " ";
}
return output;
}
}
27.CAPITALIZED
using System;
class Program
{
public static void Main()
{
Console.WriteLine(UserProgramCode.printCapitalized(Console.ReadLine()));
Console.ReadLine();
}
}
using System;
using System.Linq;
class UserProgramCode
{
public static String printCapitalized(String input1)
{
// string input = "Features Of JAVA2 ";
input1 = input1.ToLower();
char a;
int count = 0;
string[] str = input1.Split(' ');
string output = "";
foreach (string s in str)
{
count = 0;
foreach (char ch in s)
{
a = ch;
if (count == 0)
{
if (char.IsLetter(ch))
{
a = (char)((int)ch - 32);
}
}
output = output + a;
count++;
}
output = output + " ";
}
return output;
}
}
28. CAPITALIZED STRING
using System;
}
}
29.CHARGECALCULATE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace chargecalculate
{
class Program
{
static void Main(string[] args)
{
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace chargecalculate
{
class UserProgramCode
{
public static int chargeCalculation(string checkin, string checkout)
{
int charge=0;
string format="yyyy-MM-dd:HH:mm:ss";
DateTime dtin ;
DateTime dtout ;
}
}
else
{
charge=-1;
}
return charge;
}
}
}
30.CHECK SUPPLY
using System;
class Program
{
public static void Main(string[] args)
{
int stock = Convert.ToInt32(Console.ReadLine());
int quantity = Convert.ToInt32(Console.ReadLine());
bool credit = Boolean.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.CheckSupply(stock, quantity, credit));
}
}
using System;
class UserProgramCode
{
}
else if (credit == false)
{
s = "Cannot Supply";
}
else if ((quantity > stock) && (credit == true) && (stock != 0))
{
s = "Balance Will Be Shipped Later";
}
else if ((credit == true) && (stock == 0))
{
s = "Out Of Stock";
}
return s;
}
}
31.CHECK ANAGRAMS
using System;
class Program
{
using System;
class UserProgramCode
{
public static bool checkAnagram(string str1, string str2)
{
// fill your code here
str1 = str1.ToLower();
str1 = str1.Replace(" ", "");
str2 = str2.ToLower();
str2 = str2.Replace(" ", "");
if (!char.IsLetter(item))
{
return false;
}
}
if (ix == -1)
return false;
}
return true;
}
}
32.CHECK CHARACTER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
public static void Main(string[] args)
{
String word = Console.ReadLine();
int result = UserProgramCode.checkCharacters(word);
if (result == 1)
{
Console.WriteLine("The characters are same");
}
else
{
Console.WriteLine("The characters are different");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int checkCharacters(String word)
{
char[] ch = word.ToCharArray();
if (ch[0] == ch[word.Length - 1])
{
return 1;
}
else
return 0;
}
}
33.CHECK_PALLINDROME
using System;
class Program
{
public static void Main(string[] args)
{
string str = Console.ReadLine();
int output = UserProgramCode.checkPalindrome(str);
if (output == 1)
Console.WriteLine("Palindrome");
else
Console.WriteLine("Not Palindrome");
}
}
using System;
using System.Globalization;
using System.Text;
char[] d = str.ToCharArray();
foreach (char item in stra)
{
if (item == 'a' || item == 'A' || item == 'e' || item == 'E' || item == 'i' ||
item == 'I' || item == 'o' || item == 'O' || item == 'u' || item == 'U')
{
class Program
{
class UserProgramCode
{
public static int checkSum(int number)
{
int rem,sum=0;
while(number>0)
{
rem=number%10;
if(rem%2!=0)
{
sum=sum+rem;
}
number=number/10;
}
if(sum%2==0)
return -1;
else
return 1;
}
}
35.CHECK DIVISION PROBLEM
using System;
class Program
{
public static void Main()
{
int m1 = Convert.ToInt32(Console.ReadLine());
int m2 = Convert.ToInt32(Console.ReadLine());
int m3 = Convert.ToInt32(Console.ReadLine());
int m4 = Convert.ToInt32(Console.ReadLine());
int m5 = Convert.ToInt32(Console.ReadLine());
string result=UserProgramCode.calculateResult(m1,m2,m3,m4,m5);
Console.WriteLine(result);
Console.Read();
}
}
using System;
using System.Linq;
class UserProgramCode
{
public static String calculateResult(int m1,int m2,int m3,int m4,int m5)
{
string result="";
}
}
36.COMMON CHARS
using System;
class Program
{
public static void Main()
{
String input1 = Console.ReadLine();
String input2 = Console.ReadLine();
Console.WriteLine(UserProgramCode.commonChars(input1, input2));
}
}
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class UserProgramCode
{
public static int commonChars(String input1, String input2)
{
char[] s1a = input1.ToCharArray();
int l1 = input1.Length;
int l2 = input2.Length;
Array.Sort(s1a);
Array.Sort(s2a);
else if (!s1c.Contains(s1a[i]))
{
s1c.Add(s1a[i]);
}
}
else if (!s2c.Contains(s2a[i]))
{
s2c.Add(s2a[i]);
}
}
int c = 0;
// Console.WriteLine(c);
return c;
}
37.COMMON ELEMENTS IN LIST
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ebox
{
class UserProgramCode
{
static public List<int> FindCommonElements(List<int> arr1, List<int> arr2,
List<int> arr3)
{
List<int> l=new List<int>();
int flag=0,j=0;
foreach (int item in arr1)
{
foreach (var item1 in arr2)
{
foreach (var item2 in arr3)
{
if (item < 0 || item1 < 0 || item2 < 0)
{
l.Add(-1);
break;
}
else if (item > 500 || item1 > 500 || item2 > 500)
{
l.Add(-2);
break;
}
else
{
if ((item == item1 && item == item2 && item2 == item1) &&
item % 3 == 0)
{
flag++;
l.Add(item);
j++;
}
}
}
}
}
if (flag == 0)
{
l.Add( 0 );
}
return l;
}
class Program
{
static void Main(string[] args)
{
int a,b,c;
commonElements=UserProgramCode.FindCommonElements(arr1, arr2,
arr3);
commonElements.Sort();
commonElements.Reverse();
foreach (var item in commonElements)
{
if (item == 0)
{ Console.WriteLine("No match found"); break; }
else if (item == -1)
Console.WriteLine(item);
}
}
Console.ReadLine();
}
}
}
38.CONVERT FORMAT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
string inputString = Console.ReadLine();
string value = UserProgramCode.convertFormat(inputString);
Console.WriteLine(value);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
char[] c1 = a[0].ToCharArray();
char[] c2 = a[1].ToCharArray();
char[] c3 = a[2].ToCharArray();
{
len2++;
}
}
foreach (var ch in c3)
{
if (char.IsDigit(ch))
{
len3++;
}
}
// Console.WriteLine(output);
return output;
}
else
{
return " ";
}
}
}
39.CONVERTFORMAT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
string inputString = Console.ReadLine();
string value = UserProgramCode.convertFormat(inputString);
Console.WriteLine(value);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
strnew = strnew.Insert(5,"-");
strnew = strnew.Insert(9,"-");
return strnew;
}
}
40.CONVERT ROMAN TO DECIMAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
static void Main(string[] args)
{
String rom = Console.ReadLine();
Console.WriteLine(UserProgramCode.convertRomanToDecimal(rom));
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int convertRomanToDecimal(String s)
{
//fill your code here
char[] ch = s.ToCharArray();
int flag = 0, c = 0, sum = 0;
int[] a = new int[20];
foreach (char i in ch)
{
//Console.Write(i);
if (!(i == 'I' || i == 'V' || i == 'X' || i == 'L' || i == 'C' || i == 'D' || i == 'M'))
{
flag = 1;
}
}
if (flag == 1)
{
return -1;
}
else
{
foreach (char i in ch)
{
switch (i)
{
case 'I':
a[c] = 1;
c++;
break;
case 'V':
a[c] = 5;
c++;
break;
case 'X':
a[c] = 10;
c++;
break;
case 'L':
a[c] = 50;
c++;
break;
case 'C':
a[c] = 100;
c++;
break;
case 'D':
a[c] = 500;
c++;
break;
case 'M':
a[c] = 1000;
c++;
break;
}
}
}
for (int i = 0; i < c; i++)
{
if (a[i] >= a[i + 1])
{
sum = sum + a[i];
}
else
{
sum = sum - a[i];
}
}
return sum;
//Console.WriteLine(sum);
//Console.ReadKey();
}
}
41.COUNT BETWEEN NUMBERS
using System;
using System.Linq;
using System.Text;
if (inputElements[i] < 0)
{
t = -1;
return t;
}
}
}
return t;
}
}
42.COUNT MAXVOWLSTRING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace count_maxvowlstring
{
class Program
{
static void Main(string[] args)
{
c++;
}
}
if (c > max)
{
max = c;
strmax = str1[i];
a=strmax;
}
}
Console.WriteLine(a);
Console.ReadLine();
}
}
}
43.COUNT NO.CHARACTERS IN STRING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program1
{
class program
{
static void Main(string[] args)
{
string s = Convert.ToString(Console.ReadLine());
Console.WriteLine(UserMainCode.countCharacters(s));
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int countCharacters(String s)
{
int n=0;
foreach (var a in s)
{
n++;
}
return n;
}
}
44.Count Of Elements
using System;
class Program
{
public static void Main( string[] args )
{
int size=0,i;
char ch;
size=Convert.ToInt32(Console.ReadLine());
string[] arr = new string[size];
for(i=0;i<size;i++){
arr[i] = Console.ReadLine();
}
ch=Convert.ToChar(Console.ReadLine());
int f = UserProgramCode.GetCount(size,arr,ch);
if(f == -1){
Console.WriteLine("No elements Found");
}
else if(f == -2){
Console.WriteLine("Only alphabets should be given");
}
else{
Console.WriteLine(f);
}
}
}
using System;
class UserProgramCode
{
public static int GetCount(int size,string[] arr,char ch)
{
//Fill your code here
int count = 0;
return -2;
}
if (count > 0)
return count;
if (count == 0)
return -1;
return 0;
}
}
45.Count sequential_updated
class Program
{
public static void Main( string[] args )
{
string inputValue=Console.ReadLine();
int k = UserProgramCode.countSequentialChars(inputValue);
if(k == -1)
Console.WriteLine("No Repeated Words Found");
else
Console.WriteLine(k);
Console.ReadKey();
}
}
using System;
class UserProgramCode
{
public static int countSequentialChars(string input1)
{
string x = input1;
int i,c=0;
for (i = 0; i <= x.Length-3; i++)
{
if (x[i] == x[i + 1] && x[i + 1] == x[i+2])
c++;
else
continue;
}
if (c >0)
return c;
else
return -1;
}
}
46.Count Vowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
static void Main(string[] args)
{
int n;
string sentence = Console.ReadLine();
n=(UserProgramCode.countVowels(sentence));
if (n == -1)
Console.WriteLine("Other characters found");
else
Console.WriteLine(n);
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int countVowels(String sentence)
{
char[] ch = sentence.ToCharArray();
int count = 0;
foreach (var i in ch)
{
if (i < 'a' || i > 'z')
return -1;
}
}
}
return count;
}
}
47.countbetweenNos
using System;
using System.Linq;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
int count = 0;
for (i = 0; i < inputElements.Length; i++)
{
if (inputElements[i] < 0 ||n1<0||n2<0)
{
flag = 1;
}
}
if (flag == 1)
{
return -1;
}
else
{
count++;
}
}
return count;
}
48.countcharacters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
static void Main(string[] args)
{
string s = Convert.ToString(Console.ReadLine());
Console.WriteLine(UserMainCode.countCharacters(s));
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int countCharacters(String s)
{
char[] ch = s.ToCharArray();
int l = ch.Length;
return l;
}
}
49.countDigits
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace count
{
class Program
{
public static void Main()
{
namespace count
{
class UserProgramCode
{
public static int countDigits(String input1)
{
//Fill Your Code Here
int count = 0,output=0;
int count1 = 0;
char[] ch = input1.ToCharArray();
foreach (char c in ch)
{
if (char.IsLetterOrDigit(c) || char.IsWhiteSpace(c))
{
count++;
}
}
if (count == ch.Length)
{
foreach (char c1 in ch)
{
if (char.IsDigit(c1))
{
count1++;
}
}
output = count1;
}
else
{
output = -1;
}
return output;
}
}
}
50.countlargestvowelword
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication48
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
}
}
int maxcount = count.Max();
51.countoddintegers
using System;
namespace myprograms
{
class Program
{
public static void Main()
{
int size = int.Parse(Console.ReadLine());
int[] array = new int[size];
for (int i = 0; i < size; i++)
{
array[i] = int.Parse(Console.ReadLine());
}
int result = UserProgramCode.countOddIntegers(array);
if (result == -1)
{
Console.WriteLine("The Array consists non-positive value(s)");
}
else
{
Console.WriteLine(result);
Console.ReadLine();
}
}
}
}
using System;
namespace myprograms
{
class UserProgramCode
{
public static int countOddIntegers(int[] array)
{
int i, count = 0;
for (i = 0; i < array.Length; i++)
{
if (array[i] < 0)
{
return -1;
}
}
return (count);
}
}
}
52.CountSubsets
using System;
class Program
{
public static void Main( string[] args )
{
int arrSize,output;
arrSize = Convert.ToInt32(Console.ReadLine());
int[] input = new int[arrSize];
for(int i=0;i<arrSize;i++)
{
input[i] = Convert.ToInt32(Console.ReadLine());
}
output = UserProgramCode.countSubsets(input);
Console.WriteLine(output);
Console.Read();
}
}
using System;
class UserProgramCode {
public static int countSubsets(int[] input1)
{
int count = 0,flag=0;
if (count == 0)
return -1;
else
return count;
}
}
53.CountVowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CountVowels
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
int rslt = UserProgramCode.countVowels(str);
if (rslt == -1)
Console.WriteLine("Other character found");
else
Console.WriteLine(rslt);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace CountVowels
{
class UserProgramCode
{
else
{
rs = -1;
}
return rs;
}
}
}
54.ctem
using System;
class Program
{
public static void Main( string[] args )
{
String str=Console.ReadLine();
Console.WriteLine(UserProgramCode.negativeString(str));
}
}
using System;
class UserProgramCode
{
public static string negativeString (string str)
{
//Fill your code here
}
}
55.Dash check
class Program
{
public static void Main(string[] args)
{
string input1, input2;
input1 = Console.ReadLine();
input2 = Console.ReadLine();
int value = UserProgramCode.compareDashes(input1, input2);
if (value == 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
Console.ReadLine();
}
}
class UserProgramCode
{
public static int compareDashes(string input1, string input2)
{
// fill your code here
char[] s1 = input1.ToCharArray();
char[] st1 = input2.ToCharArray();
int len, count = 0;
if (s1.Length > st1.Length)
{
len = s1.Length;
}
else
{
len = st1.Length;
}
for (int i = 0; i < len; i++)
{
if (s1[i] == '-')
{
if (st1[i] != '-')
{
count++;
break;
}
}
}
if (count > 0)
return 2;
else
return 1;
56.datedifference inmonths
using System;
class Program
{
public static void Main( string[] args )
{
string date1=Console.ReadLine();
string date2=Console.ReadLine();
int result = UserProgramCode.getMonthDifference(date1,date2);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
using System.Globalization;
class UserProgramCode
{
public static int getMonthDifference(string inputDate1,string inputDate2)
{
string format = "yyyy-MM-dd";
DateTime small = DateTime.ParseExact(inputDate1, format,
CultureInfo.InvariantCulture);
int month = 0;
DateTime big = DateTime.ParseExact(inputDate2, format,
CultureInfo.InvariantCulture);
if (big > small )
{
int days = (big - small).Days;
double months = (days / 365.25) * 12;
month = Convert.ToInt32(Math.Floor(months));
}
else if(small>big)
{
int days = (small - big).Days;
}
else if (big.Month ==small.Month && big.Day==small.Day)
{
month = (big.Year - small.Year) * 12;
}
return month;
}
}
57.dates diference
using System;
class Program
{
public static void Main( string[] args )
{
string date1=Console.ReadLine();
string date2=Console.ReadLine();
int result = UserProgramCode.getMonthDifference(date1,date2);
Console.WriteLine(result);
}
}
using System;
class UserProgramCode
{
58.DaysDifference
using System;
class Program
{
public static void Main( string[] args )
{
string date1 = Console.ReadLine();
string date2 = Console.ReadLine();
int result = UserProgramCode.getDateDifference(date1, date2);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static int getDateDifference(string date1,string date2)
{
int days;
DateTime dt;
DateTime dt1;
59.daysofweek
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace days
{
class Program
{
public static void Main(string[] args)
{
string s;
s = Console.ReadLine();
Console.WriteLine(UserProgramCode.getDay(s));
}
}
}
using System;
using System.Globalization;
// string str=(string)dateValue.DayOfWeek;
//str.DayOfWeek.ToString();
return str;
// var birthDate = new DateTime(y, m, d);
// var thisYear = new DateTime(DateTime.Today.Year, birthDate.Month,
birthDate.Day);
}
}
60.decimal toroman
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace decimal_toroman
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number between 0-4999");
int num = Convert.ToInt32(Console.ReadLine());
int a = 0, b = 0, c = 0,d=0;
string str = "";
if (num > 0 && num < 4999)
{
a = (num / 1000)*1000;
b = ((num / 100) % 10) * 100;
c = ((num / 10) % 10) * 10;
d = num % 10;
switch (a)
{
case 1000: str = str + "M";
break;
case 2000: str = str + "MM";
break;
case 3000: str = str + "MMM";
break;
case 4000: str = str + "MMMM";
break;
}
switch (b)
{
case 100: str = str + "C";
break;
case 200: str = str + "CC";
break;
case 300: str = str + "CCC";
break;
case 400: str = str + "CD";
break;
case 500: str = str + "D";
break;
case 600: str = str + "DC";
break;
}
switch (c)
{
case 10: str = str + "X";
break;
case 20: str = str + "XX";
break;
case 30: str = str + "XXX";
break;
case 40: str = str + "XL";
break;
case 50: str = str + "L";
break;
case 60: str = str + "LX";
break;
case 70: str = str + "LXX";
break;
case 80: str = str + "LXXX";
break;
case 90: str = str + "XC";
break;
switch (d)
{
case 1: str = str + "I";
break;
case 2: str = str + "II";
break;
case 3: str = str + "III";
break;
case 4: str = str + "IV";
break;
case 5: str = str + "V";
break;
case 6: str = str + "VI";
break;
case 7: str = str + "VII";
break;
case 8: str = str + "VIII";
break;
case 9: str = str + "IX";
break;
}
Console.WriteLine(str);
}
else
{
Console.WriteLine("Invalid input");
}
Console.ReadLine();
}
}
}
61.developer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace developer
{
class Program
{
static void Main(string[] args)
{
int size=Convert.ToInt32(Console.ReadLine());
string [] array=new string[size];
}
}
}
62. longestWordLength
using System;
namespace myprograms
{
class Program
{
public static void Main(){
int size = int.Parse(Console.ReadLine());
String[] array = new String[size];
for(int i=0;i<size;i++){
array[i] = Console.ReadLine();
}
Console.WriteLine(UserProgramCode.longestWordLength(array));
Console.ReadKey();
}
}
}
using System;
namespace myprograms
{
class UserProgramCode{
public static int longestWordLength(String[] array)
{
int max = 0, len = 0;
foreach (string s in array)
{
len = s.Length;
if (max < len)
max = len;
}
return max;
}
}
}
63. validateTime
using System;
namespace myprograms
{
class Program
{
public static void Main(){
String input1 = Console.ReadLine();
int valid = UserProgramCode.validateTime(input1);
if(valid == 1){
Console.WriteLine("Valid time format");
}
else if(valid == -1){
Console.WriteLine("Invalid time format");
}
}
}
}
using System;
namespace myprograms
{
class UserProgramCode
{
}
}
}
64. validatePassword
using System;
class Program
{
public static void Main( string[] args )
{
String password=Console.ReadLine();
int result=UserProgramCode.validatePassword(password);
if(result==1)
Console.WriteLine("Valid password");
else
Console.WriteLine("Invalid password");
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int validatePassword(string input1)
{
int result = 0;
if (input1.Length >= 6 && input1.Length<=20)
{
char[] ch = input1.ToCharArray();
int splchar = 0;
for (int i = 0; i < ch.Length ; i++)
{
if (char.IsLetterOrDigit(ch.ElementAt(i)))
{
}
else if (ch.ElementAt(i) == '#' || ch.ElementAt(i) == '$' ||
ch.ElementAt(i) == '@')
splchar++;
}
if (splchar >= 1)
{
result = 1;
}
}
return result;
;
}
}
65. validatePassword
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main( string[] args )
{
String password=Console.ReadLine();
int result=UserProgramCode.validatePassword(password);
if(result==1)
Console.WriteLine("Valid password");
else
Console.WriteLine("Invalid password");
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int validatePassword(String input)
{
int output1 = 0;
if (input.Length >= 8)
{
char[] ch = input.ToCharArray();
if (char.IsLetter(ch.ElementAt(0)) &&
char.IsLetterOrDigit(ch.ElementAt(ch.Length - 1)))
{
int splchar = 0;
for (int i = 0; i < ch.Length - 2; i++)
{
if (char.IsLetterOrDigit(ch.ElementAt(i)))
{
}
else if (ch.ElementAt(i) == '#' || ch.ElementAt(i) == '_' || ch.ElementAt(i)
== '@')
splchar++;
}
if (splchar >= 1)
{
output1 = 1;
}
}
else
output1 = -1;
}
return output1;
}
}
66. nextYearDay
using System;
class Program
{
public static void Main( string[] args )
{
string date=Console.ReadLine();
string output=UserProgramCode.nextYearDay(date);
if(output.Equals("-1"))
Console.WriteLine("Invalid Date format");
else
Console.WriteLine(output);
}
}
using System;
using System.Globalization;
class UserProgramCode
{
public static string nextYearDay(string date)
{
string op;
string op1;
bool res = DateTime.TryParseExact(date, "dd/MM/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt1 = dt.AddDays(365);
op1 = dt1.DayOfWeek.ToString();
op = op1.ToString().ToLower();
}
else
{
op = "-1";
}
return op;
}
}
67. removeDuplicates
using System;
class Program
{
public static void Main( string[] args )
{
string input;
input=Console.ReadLine();
Console.WriteLine(UserProgramCode.removeDuplicates(input));
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
class UserProgramCode
{
public static string removeDuplicates(string input1)
{
int i;
string str = input1, str1="" ;
ArrayList al=new ArrayList();
al.Add(str[0]);
for (i = 0; i < str.Length; i++)
{
if (str[i] == ' ')
al.Add(str[i]);
if (!al.Contains(str[i]))
al.Add(str[i]);
}
for (i = 0; i < al.Count; i++)
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace time_validation
{
class Program
{
public static void Main()
{
String input1 = Console.ReadLine();
int valid = UserProgramCode.validateTime(input1);
if (valid == 1)
{
Console.WriteLine("Valid time format");
}
else if (valid == -1)
{
Console.WriteLine("Invalid time format");
}
}
}
}
class UserProgramCode
{
public static int validateTime(String input1)
{
string[] t = input1.Split(':');
string[] ex = t[1].Split(' ');
ex[1] = ex[1].ToLower();
char[] hh = t[0].ToCharArray();
char[] mm = ex[0].ToCharArray();
char[] x = ex[1].ToCharArray();
else
{
return -1;
}
}
else
{
return -1;
}
return 1;
}
return -1;
}
}
69. validatePassword
class Program
{
public static void Main( string[] args )
{
string input1;
input1 = Console.ReadLine();
int value = UserProgramCode.validatePassword(input1);
if(value == 1)
Console.WriteLine("Valid Password");
else if(value == -1)
Console.WriteLine("Invalid Password");
}
}
class UserProgramCode
{
public static int validatePassword(string input1)
{
int output1 = 0;
if (input1.Length >= 8)
{
char[] ch = input1.ToCharArray();
if (char.IsLetter(ch.ElementAt(0)) &&
char.IsLetterOrDigit(ch.ElementAt(ch.Length - 1)))
{
int splchar = 0;
for (int i = 0; i < ch.Length - 2; i++)
{
if (char.IsLetterOrDigit(ch.ElementAt(i)))
{
}
else if (ch.ElementAt(i) == '#' || ch.ElementAt(i) == '_' ||
ch.ElementAt(i) == '@')
splchar++;
}
if (splchar >= 1)
{
output1 = 1;
}
}
else
output1 = -1;
}
return output1;
}
}
70. longestWordLength
using System;
namespace myprograms
{
class Program
{
public static void Main()
{
int size = int.Parse(Console.ReadLine());
String[] array = new String[size];
for (int i = 0; i < size; i++)
{
array[i] = Console.ReadLine();
}
Console.WriteLine(UserProgramCode.longestWordLength(array));
}
}
}
71.remove duplicates
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int[] input1={1,2,3,4,5,6,5,3,1,9,1,2};
int output1 = 0,f=0;
StringBuilder sb=new StringBuilder();
for (int i = 0; i < input1.Length; i++)
{
for (int j = 0; j < input1.Length; j++)
{
if (input1[i] == input1[j])
{
f = 1;
}
if (f == 0)
{
sb.Append(input1[i]);
}
}
}
string r = sb.ToString();
Console.WriteLine(a);
Console.Read();
}
}
}
namespace ConsoleApplication27
{
class UserProgramCode
{
public static string nextYearDay(string date)
{
string output = "";
DateTime day;
class Program
{
static void Main(string[] args)
{
string input, output;
input = Console.ReadLine();
output = UserProgramCode.nextYearDay(input);
if (output == null)
{
Console.WriteLine("Invalid date");
}
Console.WriteLine(output);
Console.ReadKey();
}
}
}
}
73.dice
using System;
class Program
{
public static void Main(string[] args)
{
int dice1 = Convert.ToInt32(Console.ReadLine());
int dice2 = Convert.ToInt32(Console.ReadLine());
int result = UserProgramCode.findGiftVoucher(dice1, dice2);
if (result == -1)
Console.WriteLine("Invalid Input");
else
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static int findGiftVoucher(int dice1, int dice2)
{
int result;
if ((dice1 < 1 || dice1 > 6) || (dice2 < 1 || dice2 > 6))
{
result = -1;
return result;
}
else
{
int c = dice1 + dice2;
if (c == 2 || c == 3 || c == 6 || c == 11)
{
result = 1000;
}
else if (c == 4 || c == 7 || c == 10)
{
result = 3000;
}
else if (c == 5 || c == 8 || c == 9 || c == 12)
{
result = 5000;
}
else
{
result = -1;
return result;
}
return result;
}
}
}
74.diffbetweendatesinmonths
using System;
class Program
{
public static void Main( string[] args )
{
string date1=Console.ReadLine();
string date2=Console.ReadLine();
int result = UserProgramCode.getMonthDifference(date1,date2);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
using System.Globalization;
class UserProgramCode
{
public static int getMonthDifference(string inputDate1,string inputDate2)
{
}
return diff;
}
}
75.EfficiencyChecker
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EfficiencyChecker
{
class Program
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EfficiencyChecker
{
class UserProgramCode
{
public static string EfficiencyChecker(float f)
{
string s="";
if (f > 3.0 && f <= 4.0)
{
s = "Improve speed";
}
else if (f > 4.0 && f <= 5.0)
{
s = "Need Training";
}
else if (f > 5.0)
{
s = "Leave the company";
}
else
{
s = "Invalid Input";
}
return s;
}
}
}
76. ElectricityBill
using System;
class Program
{
public static void Main( string[] args )
{
int size;
size = Convert.ToInt32(Console.ReadLine());
string[] arr = new string[size];
for(int i=0;i<size;i++){
arr[i] = Console.ReadLine();
}
double result = UserProgramCode.calcElectricityBill(arr);
if(result == -1)
Console.WriteLine("Invalid Meter Reading");
using System;
class UserProgramCode
{
public static double calcElectricityBill(string[] arr)
{
double charge = 0;
int count = 0;
int[] reading = new int[arr.Length];
char[] type = new char[arr.Length];
for (int i = 0; i < arr.Length; i++)
{
reading[i] = int.Parse(arr[i].Substring(0, arr[i].Length - 1));
type[i] = char.Parse(arr[i].Substring(arr[i].Length - 1));
}
foreach (int k in reading)
{
if (k <= 0 || k > 999)
{
count++;
return -1;
}
}
foreach (char ch in type)
{
if (ch != 'E' && ch != 'N' && ch != 'P')
{
count++;
return -2;
}
}
if (count == 0)
{
for (int i = 0; i < arr.Length; i++)
{
if (reading[i] <= 100)
charge += reading[i] * 4.0;
else if (reading[i] > 100 && reading[i] <= 300)
charge += reading[i] * 4.50;
else if (reading[i] > 3300 && reading[i] <= 00)
charge += reading[i] * 4.75;
else
charge += reading[i] * 5.0;
if (type[i] == 'E')
charge += 300;
else if (type[i] == 'P')
charge += 450;
}
}
return charge;
}
}
77. ValidateEmailId
using System;
class Program
{
public static void Main( string[] args )
{
string ipadress = Console.ReadLine();
Console.WriteLine(UserProgramCode.ValidateEmailId(ipadress));
Console.Read();
}
}
using System;
using System.Text.RegularExpressions;
using System.Net.Mail;
class UserProgramCode {
public static string ValidateEmailId(String input1)
{
string result = "";
input1.ToLower();
}
}
78.employee designation
using System;
class Program
{
public static void Main( string[] args )
{
int size=0,i,c = 0,d=0;
size=Convert.ToInt32(Console.ReadLine());
string[] arr = new string[size];
string[] output = new string[size];
string des;
for(i=0;i<size;i++){
arr[i] = Console.ReadLine();
}
des = Console.ReadLine();
output = UserProgramCode.getEmployee(arr,des);
for(i=0;i<output.Length;i++){
if(output[i] != null){
d++;
}else{
c++;
}
}
if (d == (size / 2))
{
Console.WriteLine("same designation");
}
else
{for(i=0;i<output.Length;i++){
if(output[i] != null)
{ Console.WriteLine(output[i]); }
}}
if(c == output.Length)
Console.WriteLine("No employee for "+des+" designation");
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static string[] getEmployee(string[] input,string designation)
{
string[] output = new string [input.Length ];
for (int i = 0; i < input.Length ; i++)
{
if(i<input.Length-1)
{if(input[i+1].Equals (designation ))
{
output[i] = input[i];
}
}
}
return output;
}
}
79.EmployeeAllowancee
using System;
class Program
{
public static void Main( string[] args )
{
int arrSize;
arrSize = Convert.ToInt32(Console.ReadLine());
int[] input = new int[arrSize];
int[] output = new int[arrSize];
for(int i=0;i<arrSize;i++)
{
input[i] = Convert.ToInt32(Console.ReadLine());
}
output = UserProgramCode.empDailyAllowance(input);
for(int i=0;i<output.Length;i++)
{
if(output[i]!=0)
Console.WriteLine(output[i]);
}
Console.Read();
}
}
using System;
class UserProgramCode {
public static int[] empDailyAllowance(int[] input1)
{
int[] result = new int[input1.Length];
int count = 0;
foreach (int k in input1)
{
if (k < 0)
{
count++;
result[0] = -1;
return result;
}
}
for (int i = 0; i < input1.Length; i = i + 2)
{
for (int j = i+2; j < input1.Length; j = j + 2)
{
if (input1[i] == input1[j])
{
count++;
result[0] = -2;
return result;
}
}//4 2 5 3 4
}
if ((input1.Length % 2 == 1) ||( input1.Length > 10))
{
count++;
result[0] = -3;
return result;
}
if (count == 0)
{
int l = 0;
for (int i = 0; i < input1.Length / 2; i++)
{
result[l] = input1[l];
l++;
result[l] = (350 * input1[l] + 100 + 50);
l++;
}
}
return result;
}
}
80.encryptString
using System;
namespace myprograms
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(UserProgramCode.encrypt(Console.ReadLine()));
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace myprograms
{
public class UserProgramCode
{
public static String encrypt(string input1)
{
string a2 = Console.ReadLine().ToString();
char[] a1 = a2.ToCharArray();
char[] b = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z' };
StringBuilder sb = new StringBuilder();
int x = 0;
for (int i = 0; i < a1.Length; i++)
{
if (i % 2 == 0)
{
for (int j = 0; j < b.Length; j++)
if (a1[i] == b[j])
sb.Append(b[j + 1]);
}
else
sb.Append(a2[i]);
}
string q = sb.ToString();
Console.WriteLine(q);
return q;
}
}
}
81.Even Occurrence
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace evenOccur
{
class Program
{
static void Main(string[] args)
{
int n=Convert.ToInt32(Console.ReadLine());
int[] arr=new int[n];
for(int i =0;i<n;i++)
{
arr[i]=Convert.ToInt32(Console.ReadLine());
}
namespace evenOccur
{
class UserMainCode
{
public static int countEvenOccurence(int[] input1)
{
int i, j, c;int p=0;
int[] output1 = new int[input1.Count()];
for(i=0;i<input1.Count();i++)
{
int count=1;
if (input1[i] < 0)
{
input1[i] = -1;
}
else
{
c=input1[i];
for(j=i+1;j<input1.Count();j++)
{
if (input1[j] == c && input1[j]!=-1)
{
input1[j] =-1;
output1[p] = count++;
p++;
}
else
{
continue;
}
}
int occ = 0;
for (int k = 0; i < output1.Count(); k++)
{
if (output1[k] % 2 == 0)
{
occ++;
}
else
{
continue;
}
}
return occ;
}
}
}
82.evenvowels
using System;
namespace myprograms
{
class Program
{
public static void Main(){
Console.WriteLine(UserProgramCode.removeEvenVowels(Console.ReadLine()));
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
namespace myprograms
{
class UserProgramCode{
return str;
}
}
}
83.extensivegif
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication51
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string [] array=s.Split('.');
if (array.Length == 2)
{
for (int i = 1; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
}
else
{
Console.WriteLine("Invalid");
}
Console.ReadLine();
}
}
}
class UserProgramCode
{
public static string extractMax(string str, string sym)
{
}
for (int i = 0; i < str1.Length; i++)
{
if (str1[i].Length == max)
{
ans+= str1[i];
break;
}
}
return ans;
}
}
85.Fibonacci Series
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserMainCode.getSumOfNfibos(n));
//Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int getSumOfNfibos(int n)
{
int first = 0, second = 1, next, c,sum=0;
}
sum = sum + next;
}
return (sum);
}
}
86.file extension
using System;
class Program
{
public static void Main( string[] args )
{
string input;
input = Console.ReadLine();
string extension = UserProgramCode.fileIdentifier(input);
Console.WriteLine(extension);
}
}
using System;
class UserProgramCode
{
public static string fileIdentifier(string input1)
{
// fill your code here
}
}
87.FileExtension
using System;
class Program
{
public static void Main( string[] args )
{
string input;
input = Console.ReadLine();
string extension = UserProgramCode.fileIdentifier(input);
Console.WriteLine(extension);
Console.Read();
}
}
using System;
class UserProgramCode
{
public static string fileIdentifier(string input1)
{
return input1.Substring(input1.IndexOf('.')+1);
}
}
88.Find Average
using System;
using System.Collections.Generic;
class Program
{
public static void Main( string[] args )
{
int size=Convert.ToInt32(Console.ReadLine());
List<int> list = new List<int>();
for(int i=0;i<size;i++)
list.Add(Convert.ToInt32(Console.ReadLine()));
float output=UserProgramCode.findAverage(list);
if(output==-1)
Console.WriteLine("Negative numbers present");
else{
Console.WriteLine(output);
}
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
class UserProgramCode
{
public static float findAverage(List<int> list)
{
float sum = 0;
foreach (var i in list)
{
if (i < 0)
return -1;
else
sum +=i;
}
return sum / list.Count;
}
}
89.Find Existence
using System;
namespace Program
{
class Program
{
public static void Main( string[] args )
{
int size=0,i;
size=Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for(i=0;i<size;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
int searchEle=Convert.ToInt32(Console.ReadLine());
int result=UserProgramCode.findExistence(size,arr,searchEle);
if(result==0)
Console.WriteLine("Not Present");
else if(result==1)
Console.WriteLine("Present");
else
Console.WriteLine("Non Positive");
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static int findExistence(int size,int[] arr,int find)
{
int i;
if (find < 0)
{
return -1;
}
}
return 0;
}
}
STRING PROCESSING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dumps
{
class UserMainCode
{
static void Main(string[] args)
{
getString(Console.ReadLine(), int.Parse(Console.ReadLine()));
Console.ReadKey();
}
public static void getString(string input1, int input2)
{
int c1 = 0, c2 = 0;
string p = input1;
if (input1.Length < input2)
Console.WriteLine("-3");
else
{
int i;
for (i = 0; i < p.Length; i++)
{
if (input1[i] >= '0' && input1[i] <= '9')
{
c1 = 1;
Console.WriteLine("-1");
break;
}
else if ((input1[i] >= 'a' && input1[i] <= 'z') || (input1[i] >= 'A' &&
input1[i] <= 'Z'))
{
}
else
{
c2 = 1;
Console.WriteLine("-2");
break;
}
}
if (c1 == 0 && c2 == 0)
{
string str = input1.Substring((input1.Length - input2));
for (i = 1; i <= input2; i++)
{
input1 = input1 + str;
}
Console.WriteLine(input1);
}
}
}
}
}
STRING REVERSAL
using System;
class Program
{
public static void Main( string[] args )
{
string input = Console.ReadLine();
string output = UserProgramCode.reverseString(input);
if(output == "-1")
Console.WriteLine("Invalid Input");
else
Console.WriteLine(output);
Console.ReadKey();
}
}
using System;
class UserProgramCode {
public static string reverseString(string input)
{
string[] sa = input.Split(' ');
string s="";
foreach (string ins in sa)
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace mallika_exam
{
class Program
{
static void Main(string[] args)
{
char[] ch = element.ToCharArray();
count = 0;
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u')
count++;
}
if (count > max)
{
max = count;
//pos = j;
lenmax = ch.Length;
}
//j++;
}
break;
}
}
Console.WriteLine("_______________");
Console.WriteLine(output);
Console.ReadLine();
}
}
}
STRING ENCRYPTION
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringEncryption
{
class UserProgramCode
{
public static string encrypt(string input)
{
string output="";
for(int i=0;i<input.Length;i++)
{
if (char.IsLetter(input[i]))
{
if (i % 2 == 0)
{
if (input[i] == 'z')
{
output += 'a';
}
else
{
output += (char)(input[i] + 1);
}
}
else
{
output += input[i];
}
}
}
return output;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringEncryption
{
class Program
{
static void Main(string[] args)
{
string input;
input = Console.ReadLine();
string output;
output = UserProgramCode.encrypt(input);
Console.WriteLine(output);
Console.ReadKey();
}
}
}
STRING FINDER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace stringfinder
{
class Program
{
public static void Main( string[] args )
{
string str=Console.ReadLine();
string firststr=Console.ReadLine();
string secondstr=Console.ReadLine();
int result=UserProgramCode.stringFinder(str,firststr,secondstr);
if(result==2)
Console.WriteLine("No");
else
Console.WriteLine("Yes");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int stringFinder(string str, string firststr, string secondstr)
{
//Fill your code here
int t1 = str.IndexOf(firststr);
int t2 = str.IndexOf(secondstr);
if (t1 < t2)
return 1;
else
return 2;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace stringfirstupperandallotherlower
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string strn = "";
string[] a = s.Split(' ');
STRING OCCURANCE
using System;
class UserProgramCode
{
int output=0;
string ip1 = str1.ToLower();
char ip2 = str2.ToLower().;
char[] ch=sr.ToCharArray();
foreach (char ch1 in ch)
{
if (!char.IsLetter(ch1))
{ return -1; }
else
{
if (ch1 == ip2)
{ output++; }
}
}
return output;
}
}
using System;
class Program
{
public static void Main( string[] args )
{
string str1=Console.ReadLine();
string str2=Console.ReadLine();
Console.WriteLine(UserProgramCode.countNoOfWords(str1,str2));
}
}
STRING PROCESSING
using System;
class Program
{
public static void Main( string[] args )
{
string input,output;
input = Console.ReadLine();
output = UserProgramCode.formWordwithLastLetters(input);
Console.WriteLine(output);
Console.ReadLine();
}
}
using System;
using System.Text;
using System.Linq;
class UserProgramCode {
public static string formWordwithLastLetters(string inpt)
{
string input=inpt.ToUpper();
int digit = 0, spl = 0;
string[] words = input.Split();
string res="";
if (words.Length == 1)
return "-3";
else
{
foreach (string item in words)
{
int val = item.Length;
for (int i = 0; i < item.Length; i++)
{
if (char.IsDigit(item[i]))
{
digit++;
}
else if (!(char.IsLetterOrDigit(item[i])))
{
spl++;
}
else if (char.IsLetter(item[i]))
{
if (i == val - 1)
{
namespace myprograms
{
class Program
{
public static void Main()
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.FindResult(a, b));
}
}
}
using System;
namespace myprograms
{
class UserProgramCode{
}
}
STUDENT ELIGIBILITY
using System;
namespace myprograms
{
class Program
{
public static void Main()
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.FindResult(a, b));
}
}
}
using System;
namespace myprograms
{
class UserProgramCode
{
string fail="F";
string reappear="R";
return str;
}
else
{
if (input1 >= 55 && input2 >= 45)
return pass;
namespace StudentExamEligibility
{
class Program
{
static void Main(string[] args)
{
int a, b;
string result;
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
result = UserProgramCode.FindResult(a, b);
Console.WriteLine(result);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StudentExamEligibility
{
class UserProgramCode
{
public static string FindResult(int a, int b)
{
string result;
}
return result;
}
}
}
SUM OF INTERSECTION
using System;
class Program
{
public static void Main( string[] args )
{
int size1,size2;
size1=Convert.ToInt32(Console.ReadLine());
size2=Convert.ToInt32(Console.ReadLine());
int[] arr1 = new int[size1];
int[] arr2 = new int[size2];
for(int i=0;i<size1;i++){
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
for(int i=0;i<size2;i++){
arr2[i] = Convert.ToInt32(Console.ReadLine());
}
int result=UserProgramCode.getSumOfIntersection(size1,arr1,size2,arr2);
if(result==-1)
Console.WriteLine("No common elements found");
else
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static int getSumOfIntersection(int size1,int[] arr1,int size2,int[] arr2)
{
int sum = 0;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main(string[] args)
{
int input = Convert.ToInt32(Console.ReadLine());
int value = UserMainCode.sumOfOddEvenPositioned(input);
if(value == 1)
Console.WriteLine("Valid");
else
Console.WriteLine("Not Valid");
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
{
even = even + j;
}
else
{
odd = odd + j;
}
input = input / 10;
i++;
}
if (even == odd)
return 1;
else
return -1;
}
}
SUM OF POWER
using System;
class Program
{
public static void Main( string[] args )
{
int size=0,i;
size=Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for(i=0;i<size;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(UserProgramCode.getSumOfPower(size,arr));
// Console.ReadKey();
}
}
using System;
class UserProgramCode
{
public static int getSumOfPower(int size,int[] arr)
{
int[] array = new int[size] ;
int sum = 0;
for (int i = 0; i < size; i++)
{
sum = sum + Convert.ToInt32(Math.Pow(arr[i], i));
}
return sum;
}
}
SUM OF SQUARE
using System;
class Program
{
public static void Main(string[] args)
{
int n;
n = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.sumSquare(n));
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getSumOfSquaresOfDigits(n));
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getSumOfSquaresOfDigits(n));
Console.ReadKey();
class UserProgramCode
{
public static int getSumOfSquaresOfDigits(int n)
{
// fill your code here
int sum = 0, squareDigit, digit, num;
num = n;
while (num != 0)
{
digit = num % 10;
squareDigit = digit * digit;
sum = sum + squareDigit;
num = num / 10;
}
return sum;
}
SUM MINMAX
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dumps
{
class UserMainCode
{
static void Main(string[] args)
{
int x = sumMaxMin(int.Parse(Console.ReadLine()),
int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()));
Console.WriteLine(x);
Console.ReadKey();
}
public static int sumMaxMin(int input1, int input2, int input3)
{
if (input1 < 0 || input2 < 0 || input3 < 0)
{
return -1;
}
if (input1 == input2 || input1 == input3 || input2 == input3)
{
return -2;
}
else
{
int[] a = { input1, input2, input3 };
return (a.Max() + a.Min());
}
}
}
}
namespace sumododdneven
{
class Program
{
public static void Main(string[] args)
{
int input = Convert.ToInt32(Console.ReadLine());
int value = UserMainCode.sumOfOddEvenPositioned(input);
if (value == 1)
Console.WriteLine("Valid");
else
Console.WriteLine("Not Valid");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sumododdneven
{
public class UserMainCode
{
public static int sumOfOddEvenPositioned(int input)
{
int r,i=0,se=0,so=0,flag=0;
int [] e=new int[20];
while (input != 0)
{
r = input % 10;
e[i] = r;
i++;
input = input / 10;
}
e.Reverse();
int s = e.Count();
for (i = 0; i < s; i++)
{
if (i % 2 == 0)
se += e[i];
else
so += e[i];
}
if (se == so)
flag = 1;
else
flag = 0;
return flag;
}
}
}
SUM OF CUBE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int sumOfCube(int n)
{
int result=0;
int sum = 0;
if (n < 0)
{
result = -1;
return result;
//break;
}
else
{
for (int i = 1; i <= n; i++)
{
sum = i * i * i;
result = result + sum;
}
return result;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
int result = UserProgramCode.sumOfCube(n);
if (result == -1)
{
Console.WriteLine("The input is not a natural number");
}
else
{
Console.WriteLine(result);
}
}
}
SUM OF DIGITS
using System;
class Program
{
public static void Main( string[] args )
{
string input=Console.ReadLine();
int result=UserProgramCode.sumOfDigits(input);
if(result==-1)
Console.WriteLine("No digit present");
else{
Console.WriteLine(result);
}
Console.Read();
}
}
using System;
class UserProgramCode
{
public static int sumOfDigits(string input)
{
int sum = 0;
}
}
return sum;
}
}
SUMSQUARE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public static void Main(string[] args)
{
int n;
n = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.sumSquare(n));
}
}}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
SWAP PAIRS
using System;
namespace myprograms
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
Console.WriteLine(UserProgramCode.swapPairs(input));
Console.ReadLine();
}
}
}
using System;
namespace myprograms
{
public class UserProgramCode
{
public static String swapPairs(string input)
{
string str1 = "";
for (int k = 0; k < input.Length; k++)
{
if (((int)input[k] >= 65 && (int)input[k] <= 90) || ((int)input[k] >= 97 &&
(int)input[k] <= 122))
{
if (k == input.Length-1)
{
if (input.Length % 2 == 0)
{
}
else
{
}
}
else
{
}
return str1;
}
}
}
namespace myprograms
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
Console.WriteLine(UserProgramCode.swapPairs(input));
Console.ReadLine();
}
}
}
using System;
namespace myprograms
{
public class UserProgramCode
{
public static String swapPairs(string input)
{
int n = input.Length;
string raj = "";
string spcl = "!@#$%^&*";
char[] array = input.ToCharArray();
if(spcl.Contains(input))
{
if (n % 2 == 0)
{
for (int i = 0; i < n - 1; i = i + 2)
{
string m = input.Substring(i, 2);
char[] temp = m.ToCharArray();
Array.Reverse(temp);
string u = new string(temp);
raj = raj + u;
}
}
else
{
for (int i = 0; i < n - 1; i = i + 2)
{
string m = input.Substring(i, 2);
char[] temp = m.ToCharArray();
Array.Reverse(temp);
string u = new string(temp);
raj = raj + u;
}
raj = raj + input[n - 1];
}
}
else
{
Console.WriteLine("Invalid");
}
return raj;
}
}
}
output = UserProgramCode.symmetricDifference(inputArr1,inputArr2);
for(int i=0;i<output.Length;i++)
{
Console.WriteLine(output[i]);
}
Console.ReadLine();
}
}
using System;
using System.Linq;
using System.Collections;
class UserProgramCode
{
public static int[] symmetricDifference(int[] input1, int[] input2)
{
// fill code here
int [] output=new int[10];
var arr1 = input1.Union (input2 );
var arr2 = input1.Intersect(input2);
var arr3 = arr1.Except(arr2);
int i = 0;
foreach (var item in arr3)
{
output[i] = Convert.ToInt32(item);
i++;
}
return output;
}
}
string word;
int len,count=0;
Console.Write("Enter the word: ");
word = Console.ReadLine();
len = word.Length;
for (int i = 0; i < len; i++)
{
if(word[i]=='a'||word[i]=='e'||word[i]=='i'||word[i]=='o'||word[i]=='u')
{
count++;
}
}
Console.Write("Number of vowel are: {0}",count);
Console.ReadKey();
string sentence;
int len, count = 0;
Console.Write("Enter the string: ");
sentence = Console.ReadLine();
len = sentence.Length;
char[] reverse = new char[len];
for (int i = 0; i < len; i++)
{
if (char.IsLetterOrDigit(sentence[i]))
{
reverse[count] = sentence[i];
count++;
}
}
Array.Reverse(reverse);
string rev = new string(reverse);
string rev2 = rev.ToUpper();
Console.WriteLine("reverse: {0}", rev2);
Console.ReadKey();
Calculation of discount
Console.ReadKey();
int num;
double sum=0;
Console.WriteLine("Enter the number: ");
num = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= num; i++)
{
sum += Math.Pow(i, 3);
}
Console.WriteLine("sum of cubes of n natral numbers : {0}",sum);
small = len;
}
}
Console.WriteLine("smallest string length : {0}",small);
}
}
//Program p = new Program();
//p.sumdiff(out output, nums);
Console.WriteLine("Output: {0}",output);
string sent;
int len;
Console.WriteLine("Enter the string: ");
sent = Console.ReadLine();
char[] arr = sent.ToArray();
len = arr.Length;
arr.ToString();
Console.WriteLine("NUmber of charecters: {0}", len);
day of week
int y = 0001, da = 1, m = 1;
Console.WriteLine("year :");
y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("month :");
m = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("day :");
da = Convert.ToInt32(Console.ReadLine());
DateTime d = new DateTime(y,m,da);
Console.WriteLine(d.DayOfWeek);
Console.ReadKey();
nextpalimdrome
//Thread.Sleep(1000);
//Console.WriteLine(dig);
}
nth element to *
string str;
int a,len=0,i = 0,lena = 0;
Console.WriteLine("Enter the string: ");
str = Console.ReadLine();
string[] arr = str.Split(' ');
lena = arr.Length;
Console.WriteLine("Enter the element to be encrypted: ");
a = Int32.Parse(Console.ReadLine());
char[] aa = arr[a - 1].ToCharArray();
len = arr.Length;
foreach (char item in aa)
{
aa[i] = '*';
i++;
}
string ou = new string(aa);
string output = null;
for (i = 0; i < lena; i++)
{
if (i != (a - 1))
output = output + " " + arr[i];
else
output = output + " " + ou;
}
Console.WriteLine("After encryption : {0}",output);
}
}
Console.WriteLine("Sum of digits is : {0}",output);
Console.WriteLine("input: ");
input = Console.ReadLine();
char[] inn = input.ToCharArray();
int sum = 0,place=0;
foreach (char item in inn)
{
for (int i = 0; i < 26; i++)
{
if (item == arr[i])
{
sum = sum + i - place;
place = i;
}
}
}
Console.WriteLine("sum: {0}",sum);
string str;
Console.WriteLine("Enter the string: ");
str = Console.ReadLine();
char[] a = str.ToCharArray();
ArrayList al = new ArrayList();
al.Add(a[0]);
for (int i = 1; i < a.Length; i++ )
{
if (a[i] == a[i - 1])
{
al.Add('*');
al.Add(a[i]);
}
else
{
al.Add(a[i]);
}
}
foreach (char i in al)
{
Console.Write(i);
}
Console.ReadKey();
}
Roman to decimal
string str;
Console.WriteLine("Enter the roman number: ");
str = Console.ReadLine();
char[] arr = str.ToCharArray();
int output = 0, inp = 0;
char itemc = 'z';
foreach (char item in arr)
{
if (item == 'I')
inp = 1;
else if (item == 'V')
inp = 5;
else if (item == 'L')
inp = 50;
SymmetricDifference
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class UserProgramCode
{
public static int[] symmetricDifference(int[] input1, int[] input2)
{
int negative1=0,negative2=0;
foreach (int a in input1)
{
if (a < 0)
negative1++;
}
foreach (int b in input2)
{
if (b < 0)
negative2++;
}
var union = input1.Union(input2);
var intersect = input1.Intersect(input2);
int[] res = new int[5];
else
{
int k = 0;
foreach (int val in union)
{
if (!(res1.Contains(val)))
{
res[k] = val;
k++;
}
}
Array.Sort(res);
}
return res;
}
}
using System;
class Program
{
output = UserProgramCode.symmetricDifference(inputArr1,inputArr2);
for(int i=0;i<output.Length;i++)
{
if(output[i]!=0)
Console.WriteLine(output[i]);
}
Console.Read();
}
}
symmetruicConsoleApplication
using System;
class Program
{
public static void Main( string[] args )
{
int input1,input2;
input1 = Convert.ToInt32(Console.ReadLine());
input2 = Convert.ToInt32(Console.ReadLine());
for(int i=0;i<input1;i++)
{
inputArr1[i] = Convert.ToInt32(Console.ReadLine());
}
int[] inputArr2 = new int[input2];
for(int i=0;i<input2;i++)
{
inputArr2[i] = Convert.ToInt32(Console.ReadLine());
}
int []output =
UserProgramCode.symmetricDifference(inputArr1,inputArr2);
for(int i=0;i<output.Length;i++)
{
Console.WriteLine(output[i]);
}
}
}
using System;
using System.Linq;
using System.Collections.Generic;
class UserProgramCode {
public static int[] symmetricDifference(int[] input1,int[] input2)
{
// fill code here
int [] union=input1.Union(input2).ToArray();
int []intersect =input1.Intersect(input2).ToArray();
int [] symmdiff=union.Except(intersect).ToArray();
return symmdiff;
}
}
TakeHomeSalary
using System;
class Program
{
public static void Main( string[] args )
{
int salary = Convert.ToInt32(Console.ReadLine());
int result = UserProgramCode.calculateHomeSalary(salary);
if(result==-1)
Console.WriteLine("Invalid Input");
else
Console.WriteLine(result);
Console.Read();
}
}
using System;
class UserProgramCode
{
public static int calculateHomeSalary(int salary)
{
int res = 0;
int pf = 0;
int medicalInsurance = 678;
if (salary < 0)
return -1;
else
{
if (salary <= 15000)
pf = 750;
else if (salary > 15000 && salary <= 22000)
pf = 850;
else if (salary > 22000 && salary <= 30000)
pf = 925;
else
pf = 1000;
}
res = salary - pf - medicalInsurance;
return res;
}
}
Tarrif Calculation
using System;
class Program
{
static void Main(string[] args)
{
}
}
class UserProgramCode
{
}
else if (input1 == "LCV")
{
if (input2 == "Single")
cost = 34;
else if (input2 == "Return")
cost = 60;
else if (input2 == "Daily")
cost = 90;
else if (input2 == "Monthly")
cost = 2100;
else
cost = -2;
}
else if (input1 == "Bus")
{
if (input2 == "Single")
cost = 54;
else if (input2 == "Return")
cost = 100;
else if (input2 == "Daily")
cost = 150;
else if (input2 == "Monthly")
cost = 3450;
else
cost = -2;
}
else if (input1 == "Truck")
{
if (input2 == "Single")
cost = 80;
else if (input2 == "Return")
cost = 140;
else if (input2 == "Daily")
cost = 220;
else if (input2 == "Monthly")
cost = 5100;
else
cost = -2;
}
else
{
cost = -1;
}
return cost;
}
}
using System;
class Program
{
string input1,input2;
int output;
input1 = Console.ReadLine();
input2 = Console.ReadLine();
output = UserProgramCode.calculateTariff(input1,input2);
Console.WriteLine(output);
Console.ReadLine();
}
TestVowelsOrder
using System;
class Program
{
public static void Main( string[] args )
{
string input=Console.ReadLine();
int result = UserProgramCode.testOrderVowels(input);
Console.WriteLine(result);
Console.Read();
}
}
using System;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int testOrderVowels(string input)
{
int res=0;
string result="";
input.ToLower();
for (int i = 0; i < input.Length; i++)
{
if (input[i] == 'a' || input[i] == 'e' || input[i] == 'i' || input[i] == 'o' || input[i]
== 'u')
result += input[i];
}
if (result.Length>5)
{
res =- 1;
}
else if (result.Equals("aeiou"))
res = 1;
else
res = 2;
return res;
}
}
The difference bw the date in months
using System;
class UserProgramCode
{
public static int getMonthDifference(string inputDate1,string inputDate2)
{
// fill your code here
DateTime d1 = Convert.ToDateTime(inputDate1);
DateTime d2 = Convert.ToDateTime(inputDate2);
TimeSpan d3 = (d2 - d1);
double month = d3.TotalDays;
month = month / 30;
month = Math.Floor(month);
return Convert.ToInt32(month);
}
}
using System;
class Program
string date1=Console.ReadLine();
string date2=Console.ReadLine();
}
Time Validation using reg
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Time_Validation
{
class Program
{
Console.ReadLine();
}
}
}
Timevalidation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace timevalidation
{
class UserProgramCode
{
namespace timevalidation
{
class Program
{
static void Main(string[] args)
{
string t = Console.ReadLine();
int a = UserProgramCode.ValidateTime(t);
if (a == 1)
{
namespace salary
{
class Program
{
static void Main(string[] args)
{
string d1 = Console.ReadLine();
string d2 = Console.ReadLine();
string d = Console.ReadLine();
int tariff = 0;
Regex r = new Regex(@"\d{4}\.\d{2}\.\d{2}");
if (!r.IsMatch(d1) || !r.IsMatch(d2))
{
Console.WriteLine("Improper Date format in the input");
}
else if (d == "SL")
{
if (diff >= 31 && diff <= 90)
{
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", 1000);
}
if (diff >= 21 && diff <= 30)
{
tariff = (int)Math.Round(1000 + 0.1 * 1000);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff >= 11 && diff <= 20)
{
tariff = (int)Math.Round(1000 + 0.2 * 1000);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff >= 4 && diff <= 10)
{
tariff = (int)Math.Round(1000 + 0.3 * 1000);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff == 3)
{
tariff = (int)Math.Round(1000 + 0.4 * 1000);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
}
else if (d == "1AC")
{
if (diff >= 31 && diff <= 90)
{
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", 2500);
}
if (diff >= 21 && diff <= 30)
{
tariff = (int)Math.Round(1000 + 0.1 * 2500);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff >= 11 && diff <= 20)
{
tariff = (int)Math.Round(1000 + 0.2 * 2500);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff >= 4 && diff <= 10)
{
tariff = (int)Math.Round(1000 + 0.3 * 2500);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff == 3)
{
tariff = (int)Math.Round(1000 + 0.4 * 2500);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
}
else if (d == "2AC")
{
if (diff >= 31 && diff <= 90)
{
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", 2000);
}
if (diff >= 21 && diff <= 30)
{
tariff = (int)Math.Round(1000 + 0.1 * 2000);
else if (d == "3AC")
{
if (diff >= 31 && diff <= 90)
{
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", 1500);
}
if (diff >= 21 && diff <= 30)
{
tariff = (int)Math.Round(1000 + 0.1 * 1500);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff >= 11 && diff <= 20)
{
tariff = (int)Math.Round(1000 + 0.2 * 1500);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff >= 4 && diff <= 10)
{
tariff = (int)Math.Round(1000 + 0.3 * 1500);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
if (diff == 3)
{
tariff = (int)Math.Round(1000 + 0.4 * 1500);
Console.WriteLine("Your ticket is confirmed and the booking cost is Rs
{0}", tariff);
}
}
else
{
Console.WriteLine("Improper class of Travel");
}
Console.ReadLine();
}
}
}
Traintravelfare
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace traveltrainfare
{
class Program
{
static void Main(string[] args)
{
int output = 0;
string input = Console.ReadLine();
DateTime bookingdate;
DateTime traveldate;
bool res = (DateTime.TryParseExact(bookingdate1, format,
CultureInfo.InvariantCulture, DateTimeStyles.None, out bookingdate));
{
a = 2500;
Console.WriteLine(a);
}
}
else
Console.WriteLine("Improper class of travel");
}
}
else
Console.WriteLine("Improper class of travel");
}
else
Console.WriteLine("Improper class of travel");
}
if (output == 3)
{
int a = 0;
if (input.Equals("SL"))
{
a = 1000 + (40 * 1000) / 100;
Console.WriteLine(a);
}
else if (input.Equals("3AC"))
{
a = 1500 + (40 * 1500) / 100;
Console.WriteLine(a);
}
else if (input.Equals("2AC"))
{
a = 2000 + (40 * 2000) / 100;
Console.WriteLine(a);
}
else if (input.Equals("1AC"))
{
a = 2500 + (40 * 2500) / 100;
Console.WriteLine(a);
}
else
Console.WriteLine("Improper class of travel");
}
}
else
Console.WriteLine("Long notice period ticket cannot be printed");
}
else
Console.WriteLine("improper date format");
Console.ReadLine();
}
}
}
Trendy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace trendy
{
class Program
{
static void Main(string[] args)
{
int n,a;
n = Convert.ToInt32(Console.ReadLine());
if (n >= 100 && n <= 999) {
a = n / 10;
a = a % 10;
if (a % 3 == 0)
{
Console.WriteLine("Trendy Number");
}
else {
Console.WriteLine("Not a Trendy Number");
}
else
{
Console.WriteLine("Not a Trendy Number");
}
Console.ReadLine();
}
}
}
Triplets
using System;
class UserProgramCode
{
public static int[] findTriplets(int[] input,int num)
{
int[] triplet=new int[3];
for (int i = 0; i < input.Length; i++)
{
for (int j = i + 1; j < input.Length; j++)
{
for (int k = j+1; k < input.Length; k++)
{
if (input[i] < 0 || input[j] < 0 || input[k] < 0)
{
triplet[0] = -1;
}
else if (input[i] == input[j] || input[j] == input[k] || input[i] == input[k])
{
triplet[0] = -3;
}
}
}
}
if (triplet[0] + triplet[1] + triplet[2] == num)
{
return triplet;
}
else
{
triplet[0] = -2;
}
return triplet;
}
}
using System;
class Program
{
public static void Main( string[] args )
{
int size=0,i,num;
size=Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
int[] output = new int[3];
for(i=0;i<size;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
num = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.findTriplets(arr,num);
for(i=0;i<output.Length;i++)
{
if(output[i]!=0)
Console.WriteLine(output[i]);
}
Console.Read();
}
}
}
Uniquecount
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Uniquecount
{
class Program
{
int ctr=0,ctr1=0;
if (ctr1 == 1)
{
ctr++;
}
ctr1 = 0;
}
}
Console.WriteLine(ctr);
Console.ReadLine();
}
}
}
UniqueCounter
using System;
class UserProgramCode
{
public static int uniqueCounter(string str)
{
int count = 0;
int count1 = 0;
char[] ch=str.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
count1 = 0;
char c = ch[i];
for (int j =0; j < str.Length; j++)
{
char cd = ch[j];
if (cd == c)
{
count1++;
}
}
if (count1 == 1)
{
count++;
}
}
if (count == 0)
return -1;
else
return(count);
}
}
using System;
class Program
{
public static void Main(string[] args)
{
string str = Console.ReadLine();
int result = UserProgramCode.uniqueCounter(str);
if (result == -1)
Console.WriteLine("No unique characters");
else
{
Console.WriteLine(result);
}
}
}
Validate Number another
using System;
using System.Text.RegularExpressions;
class UserProgramCode{
public static int validateNumber(String input1){
int res = 1, i = 0;
int ln = input1.Length;
//Console.WriteLine(ln);
if (ln != 12)
{
res = -1;
}
string[] nw = input1.Split('-');
foreach (var it in nw)
{
if (i == 0)
{
int l = it.Length;
if (l == 3)
{
foreach (char iti in it)
{
if (!Char.IsDigit(iti))
{
res = -1;
break;
}
}
}
else
{
res = -1;
break;
}
}
if (i == 1)
{
int l = it.Length;
if (l == 3)
{
{
int l = it.Length;
if (l == 4)
{
foreach (char iti in it)
{
if (!Char.IsDigit(iti))
{
res = -1;
break;
}
}
}
else
{
res = -1;
break;
}
}
i++;
}
return res;
}
}
using System;
class Program
{
public static void Main(){
int result = UserProgramCode.validateNumber(Console.ReadLine());
if(result == 1){
Console.WriteLine("Valid Number");
}
else if(result == -1){
Console.WriteLine("Invalid Number");
}
}
}
validate pan
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace validate_pan
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the pan card number");
string str = Console.ReadLine();
string str1 = str.Substring(0, 4);
Console.WriteLine(str1);
string str2 = str.Substring(4, 4);
int flag = 0;
Console.WriteLine(str2);
if (str.Count() == 9)
{
for (int i = 0; i < str1.Length; i++)
{
if (char.IsUpper(str1[i]) &&char.IsDigit(str2[i]) &&char.IsUpper(str[8]))
{
flag = 1;
}
else { flag = 0; }
}
if (flag == 0)
{ Console.WriteLine("Pancard is invalid"); }
else { Console.WriteLine("Pan is valid"); }
}
else { Console.WriteLine("Pancard is invalid"); }
Console.ReadLine();
}
}
}
validateIdlocation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
// string s1 = Console.ReadLine();
//string s2 = Console.ReadLine();
string[] a = input1.Split('-');
int len = input1.Length;
len3++;
}
}
else
{
return -1;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
static void Main(string[] args)
{
string input1 = Convert.ToString(Console.ReadLine());
string input2 = Convert.ToString(Console.ReadLine());
if (UserMainCode.validateIDLocations(input1, input2) == 1)
{
Console.WriteLine("valid");
}
else
{
Console.WriteLine("invalid");
}
Console.ReadKey();
}
}
validateIDLocations
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int validateIDLocations(String input1, String input2)
{
int res = 1, i = 0; ;
string[] nw = input1.Split('-');
foreach (var it in nw)
{
if (i == 0)
{
if (nw[i] == "CTS")
{
;
}
else
{
res = -1;
break;
}
}
if (i == 1)
{
int l = it.Length;
if (l == 3 && it == input2.Substring(0,3))
{
;
}
else
{
res = -1;
break;
}
}
if (i == 2)
{
int l = it.Length;
if (l == 4)
{
foreach (char iti in it)
{
if (!Char.IsDigit(iti))
{
res = -1;
break;
}
}
}
else
{
res = -1;
break;
}
}
i++;
}
return res;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
static void Main(string[] args)
{
string input1 = Convert.ToString(Console.ReadLine());
string input2 = Convert.ToString(Console.ReadLine());
if(UserProgramCode.validateIDLocations(input1, input2)==1)
{
Console.WriteLine("valid");
}
else
{
Console.WriteLine("invalid");
}
Console.ReadKey();
}
}
ValidateNegativeNumber
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ValidateNegativeNumber
{
class UserProgramCode
{
public static string validateNumber(string num)
{
string output1=null;
int count = 0;
int flag = 0;
int flag1 = 0;
int output = 0;
StringBuilder sb = new StringBuilder();
char[] ch = num.ToCharArray();
if (ch[0] == '-')
{
for (int i = 1; i < ch.Length; i++)
if (char.IsDigit(ch[i]))
{
count++;
}
}
if (count == ch.Length - 1)
{
flag = 1;
}
else
{
flag1 = -1;
}
if (flag == 1)
{
for (int j = 1; j < ch.Length; j++)
sb.Append(ch[j]);
output1 = sb.ToString();
}
else if (flag1 == -1)
{
output = -1;
output1 = Convert.ToString(output);
}
return output1;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ValidateNegativeNumber
{
class Program
{
public static void Main(string[] args)
{
string num = Console.ReadLine();
class UserProgramCode
{
public static string validateNumber(string num)
{
int dash = 0, n = 0;
int length = num.Length;
char[] ch = num.ToCharArray();
if (ch[0] == '-')
{
dash++;
}
foreach (var item in ch)
{
if (Char.IsDigit(item))
{
n++;
}
}
if (dash == 1 && n == length - 1)
{
int x = int.Parse(num);
x = -x;
string output = x.ToString();
return output;
}
else
{
return "-1";
}
}
}
using System;
class Program
{
public static void Main(string[] args)
{
string num = Console.ReadLine();
class UserProgramCode
{
public static int validateNumber(int[] arr1,int size1,int[] arr2,int size2)
{
int res = 0, sum = 0;
int cnt1 = 0, cnt2 = 0;
//int flag = 0;
//int[] nar1 = new int[size1 + size2];
//
int [] nar2 =
int j ,k;
for (int i = 0; i < size1; i++)
{
if (arr1[i] < 0)
{
cnt1++;
}
}
for (int i = 0; i < size2; i++)
{
if (arr2[i] < 0)
{
cnt2++;
}
}
if (cnt1 > 0 && cnt2 > 0)
{
res = -3;
}
}
for (k = 0; k<size2; k++)
{
nw.Add(arr2[k]);
}
//Console.WriteLine(it);
}
//int[] nw = a.Distinct().ToArray();
res = sum;
}
return res;
class Program
{
public static void Main( string[] args )
{
int i;
int size1=Convert.ToInt32(Console.ReadLine());
int size2=Convert.ToInt32(Console.ReadLine());
int[] arr1 = new int[size1];
int[] arr2 = new int[size2];
for(i=0;i<size1;i++){
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
for(i=0;i<size2;i++){
arr2[i] = Convert.ToInt32(Console.ReadLine());
}
int result=UserProgramCode.validateNumber(arr1,size1,arr2,size2);
if(result==-3)
Console.WriteLine("Both inputs has negative numbers");
else if(result==-2)
Console.WriteLine("Input 2 has negative numbers");
else if(result==-1)
Console.WriteLine("Input 1 has negative numbers");
else
Console.WriteLine(result);
//Console.ReadKey();
}
}
validateVoter
using System;
class Program
{
public static void Main(string[] args)
{
string dob = Console.ReadLine();
string electionDate = Console.ReadLine();
int output = UserProgramCode.validateVoter(dob, electionDate);
if (output == -1)
Console.WriteLine("Invalid Date format");
else if (output == 0)
Console.WriteLine("Not Eligible");
else
Console.WriteLine("Eligible");
}
}
using System;
using System.Globalization;
using System.Text.RegularExpressions;
class UserProgramCode
{
//public static int output4;
public static int validateVoter(string input1,string input2)
{
int output4;
DateTime dt;
DateTime dt2;
bool res = DateTime.TryParseExact(input1, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
bool res2 = DateTime.TryParseExact(input2, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt2);
if (res == true && res2 == true)
{
int year = dt2.Year - dt.Year;
int month = dt2.Month - dt.Month;
if (month < 0)
{
year = year - 1;
month = month + 12;
}
if (year > 18)
{
output4 = 1;
return output4;
}
else
{
output4 = 0;
return output4;
}
}
output4 = -1;
return output4;
}
}
Voting
using System;
using System.Globalization;
class UserProgramCode
{
public static int validateVoter(string dob, string electionDate)
{
//Fill your code here
int output1;
DateTime db = new DateTime();
DateTime db1 = new DateTime();
try
{
db = DateTime.ParseExact(dob
{
output1 = 1;
}
else
{
output1 = 0;
}
}
catch
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();
}
}
using System;
class Program
{
public static void Main(string[] args)
{
string dob = Console.ReadLine();
string electionDate = Console.ReadLine();
int output = UserProgramCode.validateVoter(dob, electionDate);
if (output == -1)
Console.WriteLine("Invalid Date format");
else if (output == 0)
Console.WriteLine("Not Eligible");
else
Console.WriteLine("Eligible");
}
}
Vowels
using System;
using System.Text;
using System.Linq;
{
return 1;
}
else
{
return -1;
}
}
}
using System;
namespace vowelstringorder
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string");
string input = Console.ReadLine();
int count = 0;
string str = "";
string lowinput = input.ToLower();
string vowel = "aieou";
foreach (char ch in lowinput)
{
if (vowel.Contains(ch))
{
str += ch.ToString();
count++;
}
else
{
continue;
}
}
if (count == 5 && str.Equals(vowel))
{
Console.WriteLine("string is in order");
}
else
{
Console.WriteLine("Order not correct");
}
Console.ReadLine();
}
}
}
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
string input1 = "confir";
string output1 = " ";
output1 = input1.Substring(input1.Length / 2 - 1, 2);
Console.WriteLine(output1);
Console.Read();
}
}
}
Get Number of Days
COUNT NUMBER OF DAYS IN A MONTH
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace myprograms
{
}
}
Get The Longest String
GET LONGEST STRING
using System;
using System.Collections.Generic;
namespace myprograms
{
class UserProgramCode{
}
else
{
foreach (String item in input1)
{
}
}
num++;
}
else
{
break;
}
}
if (flag == 0)
{
if (num == input1.Count)
{
if (max == 0)
{
Maxlen = "No elements found";
}
}
}
else
{
Maxlen = "String contains non alphabetic characters.";
}
return Maxlen;
}
}
}
}
Get word with Maximum Vowels
string str = Console.ReadLine();
string[] arr = str.Split(' ');
int max = 0, lenmax = 0, count;
//int pos=0,j=0;
foreach (string element in arr)
char[] ch = element.ToCharArray();
count = 0;
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u')
count++;
}
if (count > max)
{
max = count;
//pos = j;
lenmax = ch.Length;
}
//j++;
}
Console.ReadLine();
}
Id Verification (validate id locations)
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
class UserProgramCode
{
public static int validateIDLocations(String input1, String input2)
{
string
s1 = "CTS";
return -1;
if (str[2].Length != 4)
{
return -1;
else
{
char[] c = str[2].ToCharArray();
foreach (char ch in c)
{
if (!char.IsDigit(ch))
{
return -1;
}
}
}
return 1;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication12
{
class Program
{
public static void Main(string[] args)
{
int size = 0, i;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (i = 0; i < size; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(UserProgramCode.getSumOfPower(size, arr));
}
}
class UserProgramCode
{
public static int getSumOfPower(int size, int[] arr)
{
int[] array = new int[] { 7, 3, 2, 1 };
int s = 4;
int sum = 0;
for (int i = 0; i < s; i++)
{
sum = sum + Convert.ToInt32(Math.Pow(arr[i], i));
}
return sum;
}
}
}
Leader
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace leader
{
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
}
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] < 0)
flag = 1;
}
if (flag == 0)
{
for (int i = 0; i < arr.Length - 1; i++)
{
count = 0;
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[i] > arr[j])
count++;
}
if (arr.Length - (i + 1) == count)
list.Add(arr[i]);
}
list.Add(arr[arr.Length - 1]);
list.Sort();
foreach (int item in list)
{
Console.WriteLine(item);
}
}
else
Console.WriteLine("-1");
Console.ReadLine();
}
}
}
length of the smallest string in the given string array
len = item.Length;
//
if (small == 0)
//
//
small = len;
//
//
//
//
//
small = len;
}
//}
//Console.WriteLine("smallest string length : {0}",small);
Longest Palindrome
public static int LongestPalindrome(string seq)
{
int Longest = 0;
List<int> l = new List<int>();
int i = 0;
int palLen = 0;
int s = 0;
int e = 0;
while (i<seq.Length)
{
if (i > palLen && seq[i-palLen-1] == seq[i])
{
palLen += 2;
i += 1;
continue;
}
l.Add(palLen);
Longest = Math.Max(Longest, palLen);
s = l.Count - 2;
e = s - palLen;
bool found = false;
for (int j = s; j > e; j--)
{
int d = j - e - 1;
if (l[j] == d)
{
palLen = d;
found = true;
break;
}
l.Add(Math.Min(d, l[j]));
}
if (!found)
{
palLen = 1;
i += 1;
}
}
l.Add(palLen);
Longest = Math.Max(Longest, palLen);
return Longest;
}
longestPallindrome
public static int LongestPalindrome(string seq)
{
int Longest = 0;
List<int> l = new List<int>();
int i = 0;
int palLen = 0;
int s = 0;
int e = 0;
while (i<seq.Length)
{
if (i > palLen && seq[i-palLen-1] == seq[i])
{
palLen += 2;
i += 1;
continue;
}
l.Add(palLen);
Longest = Math.Max(Longest, palLen);
s = l.Count - 2;
e = s - palLen;
bool found = false;
for (int j = s; j > e; j--)
{
int d = j - e - 1;
if (l[j] == d)
{
palLen = d;
found = true;
break;
}
l.Add(Math.Min(d, l[j]));
}
if (!found)
{
palLen = 1;
i += 1;
}
}
l.Add(palLen);
Longest = Math.Max(Longest, palLen);
return Longest;
}
Maximum Vowel String
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace my_project
{
class Class1
{
static void Main(string[] args)
{
string input1 = string.Empty;
input1 = Console.ReadLine();
Console.WriteLine(input1);
string[] s = input1.Split(' ');
string str = string.Empty;
string vow = "aeiouAEIOU";
int count = 0,max=0;
for (int i = 0; i < s.Length; i++)
{
count = 0;
char[] ch = s[i].ToCharArray();
for (int j = 0; j < ch.Length; j++)
{
if (vow.Contains(ch[j]))
{
count++;
}
if (count > max)
{
max = count;
str = s[i];
}
}
}
Console.WriteLine(str);
}
}
}
Online Shopping
namespace SM1
{
class UserProgramCode
{
public static void onlineSalesAmount(int input1, int input2)
{
float discount = 0, saved = 0;
if (input1 <= 0)
Console.WriteLine("Invalid Price Amount");
else if ((input2 < 1000 || input2 > 1800))
{
Console.WriteLine("The price of the product is Rs {0} and discounts are
not applicable.", input1);
}
else
{
}
else if (input2 > 1100 && input2 <= 1200)
{
discount = (40 * input1) / 100;
saved = input1 - discount;
}
else if (input2 > 1200 && input2 <= 1600)
{
discount = (30 * input1) / 100;
saved = input1 - discount;
}
else if (input2 > 1600)
{
discount = (25 * input1) / 100;
saved = input1 - discount;
}
}
class Program
{
static void Main(string[] args)
{
int cost = Convert.ToInt32(Console.ReadLine());
int time = Convert.ToInt32(Console.ReadLine());
UserProgramCode.onlineSalesAmount(cost, time);
Console.ReadLine();
Console.ReadLine();
}
}
}
permutation_Final
using System;
using System.Collections.Generic;
using System.Linq;
class UserProgramCode
{
public static void go(char[] list, int k, int m)
{
int i;
if (k == m)
{
Console.Write(list);
Console.WriteLine(" ");
}
else
for (i = k; i <= m; i++)
{
swap(ref list[k], ref list[i]);
go(list, k + 1, m);
swap(ref list[k], ref list[i]);
}
}
/*public static void setper(char[] list)
{
int x = list.Length - 1;
go(list, 0, x);
}*/
public static void swap(ref char a, ref char b)
{
if (a == b)
return;
a ^= b;
b ^= a;
a ^= b;
}
char[] di=arr.Distinct().ToArray();
List<string> oup=new List<string>();
foreach(char cc in di)
{
if(char.IsNumber(cc) || char.IsSymbol(cc))
{
ctr++;
oup.Add("-1");
return oup;
}
}
int x = di.Length - 1;
go(di, 0, x);
return oup;
}
}
-------------------------------------------------using System;
using System.Collections.Generic;
class Program
string str;
str = Console.ReadLine();
li=UserProgramCode.permString(str);
for(int i=0;i<li.Count;i++)
if(li[i].Equals("-1"))
Console.WriteLine("Invalid Input");
else
Console.WriteLine(li[i]);
Console.ReadLine();
namespace example
{
class Quadraticroots
{
double a, b, c;
class Roots
{
public static void Main()
{
Quadraticroots qr = new Quadraticroots();
qr.read();
qr.compute();
}
}
}
Quadratic_Root
/*
* C# Program to Find Roots of a Quadratic Equation
*/
using System;
namespace example
{
class Quadraticroots
{
double a, b, c;
m = 1;
else if (d1 > 0)
m = 2;
else if (d1 == 0)
m = 3;
else
m = 4;
switch (m)
{
case 1: Console.WriteLine("\n Not a Quadratic equation, Linear equation");
Console.ReadLine();
break;
case 2: Console.WriteLine("\n Roots are Real and Distinct");
r1 = (-b + Math.Sqrt(d1)) / (2 * a);
r2 = (-b - Math.Sqrt(d1)) / (2 * a);
Console.WriteLine("\n First root is {0:#.##}", r1);
Console.WriteLine("\n Second root is {0:#.##}", r2);
Console.ReadLine();
break;
case 3: Console.WriteLine("\n Roots are Real and Equal");
r1 = r2 = (-b) / (2 * a);
Console.WriteLine("\n First root is {0:#.##}", r1);
Console.WriteLine("\n Second root is {0:#.##}", r2);
Console.ReadLine();
break;
case 4: Console.WriteLine("\n Roots are Imaginary");
r1 = (-b) / (2 * a);
r2 = Math.Sqrt(-d1) / (2 * a);
Console.WriteLine("\n First root is {0:#.##} + i {1:#.##}", r1, r2);
Console.WriteLine("\n Second root is {0:#.##} - i {1:#.##}", r1, r2);
Console.ReadLine();
break;
}
}
}
class Roots
{
public static void Main()
{
Quadraticroots qr = new Quadraticroots();
qr.read();
qr.compute();
}
}
}
regex Phone number
Match match = Regex.Match(input1, @"((\\d{3}\ ?)|(\d{3}-))?\d{3}-\d{4}");
if (match.Success)
{
return 1;
}
else
return -1;
Reimbursement
namespace SM1
{
class UserProgramCode
{
public static int calulateAmountRefundable(double fee, int marks, bool arr)
{
double total;
else
{
if (!arr)
{
if (marks >= 80 && marks <= 85)
{
total = (40 * fee) / 100;
total = total + 3000;
return (int)total;
}
else if (marks >= 86 && marks <= 90)
{
total = (50 * fee) / 100;
total = total + 5000;
return (int)total;
}
else if (marks >= 90 && marks <= 100)
{
total = (60 * fee) / 100;
total = total + 7000;
return (int)total;
}
else
return 0;
}
else
{
return -3;
}
}
}
class Program
{
static void Main(string[] args)
{
else if(res==-2)
Console.WriteLine("Invalid percentage");
else
Console.WriteLine(res);
Console.ReadLine();
}
}
}
Remove Tens
usermaincode.-------------------------------------------------------------------------------------------------
if (arr[i] != 10)
{
output[k] = arr[i];
k++;
}
else
{
count++;
for(j=0;j<count;j++)
{
output[k]=0;
k++;
}
return output;
}
--------------------------------------------------------------------------------------------------------------------program.cs
---------------------------------------------------------------------------------------------------------------------
int size, i;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
int[] output = new int[size];
namespace ConsoleApplication23
{
class Program
{
public static void Main(string[] args)
{
int size = 0, i;
size = Convert.ToInt32(Console.ReadLine());
if (f == 1)
Console.WriteLine("Array contains negative numbers");
else if (size == count)
{
Console.WriteLine("No repeated numbers");
}
else
{
foreach (var result in i)
Console.WriteLine(result);
}
}
}
}
Reverse and Format
using System;
class Program
string str=Console.ReadLine();
char ch = Convert.ToChar(Console.ReadLine());
Console.WriteLine(UserProgramCode.reshape(str,ch));
Console.Read();
}
----------------------USER PROGRAM
----------------------using System;
class UserProgramCode
{
int l = str.Length;
string sree = "";
char[] temp = str.ToCharArray();
for (int i = l - 1; i >= 0; i--)
{
sree = string.Concat(sree, temp[i]);
if (i != 0)
{
if (char.IsLetterOrDigit(sentence[i]))
//
//
reverse[count] = sentence[i];
//
count++;
//
//}
//Array.Reverse(reverse);
//string rev = new string(reverse);
//string rev2 = rev.ToUpper();
//Console.WriteLine("reverse: {0}", rev2);
//Console.ReadKey();
Reverse Substring
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication32
{
public class UserProgramCode
{
public static string reverseSubstring(string s, int si, int l)
{
char[] A = s.ToCharArray();
Array.Reverse(A);
string b = string.Empty;
for (int i = si - 1; i < si + l - 1; i++)
{
b = b + A[i];
//
Console.WriteLine(A[i]);
}
return b;
}
}
class Program
{
public static void Main(string[] args)
{
int l, si;
string s;
s = Console.ReadLine();
si = int.Parse(Console.ReadLine());
l = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.reverseSubstring(s, si + 1, l));
}
}
}
namespace ConsoleApplication32
{
public class UserProgramCode
{
public static string reverseSubstring(string s, int si, int l)
{
char[] A = s.ToCharArray();
Array.Reverse(A);
string b = string.Empty;
for (int i = si - 1; i < si + l - 1; i++)
{
b = b + A[i];
//
Console.WriteLine(A[i]);
}
return b;
}
}
class Program
{
public static void Main(string[] args)
{
int l, si;
string s;
s = Console.ReadLine();
si = int.Parse(Console.ReadLine());
l = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.reverseSubstring(s, si + 1, l));
}
}
}
Series positive odd
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
public static void Main(string [] args)
{
int n;
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.addSeries(n));
Console.ReadLine();
}
}
}
class UserProgramCode
{
public static int addSeries(int n)
{
int sum=0;
for(int i=1;i<=((n+1)/2);i++)
{
if (i == 1)
sum = sum + i;
else if (i % 2 == 0)
sum = sum + (2 * i - 1);
else
sum = sum - (2 * i - 1);
}
return sum;
}
}
Sort by length and alphabetic order
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace _16th_april
{
class Program
{
static void Main(string[] args)
{
/*Boundory Avg*/
//
//
//
//
arr[i] = Convert.ToInt32(Console.ReadLine());
}
//}
//Array.Sort(arr);
//string avg = ((arr[0] + arr[size - 1])*1.0 / 2).ToString();
//Console.WriteLine(avg);
//Console.ReadLine();
/*Sort Length*/
char ch = Convert.ToChar(Console.ReadLine());
list.Add(item);
}
}
var result = list.Cast<string>().OrderBy(str => str.Length).ThenBy(str
=> str);
foreach (string item1 in result)
{
Console.WriteLine(item1);
}
}
else
Console.WriteLine("invalid string");
Console.ReadLine();
/*Count Character*/
//// {
////
////
////
if (ch.Contains(b[i]))
////
////
count++;
////
////
////
else
////
////
flag = 1;
////
break;
////
//// }
//// if ( flag==0)
////
Console.WriteLine(count);
//// else
////
Console.WriteLine("Invalid");
////// Console.WriteLine(count);
//// Console.ReadLine();
}
}
}
Sort List
int n;
int flag = 0;
n = Convert.ToInt32(Console.ReadLine());
int p = Convert.ToInt32(Console.ReadLine());
if (p > 0)
{
sorting[i] = p;
}
else
{
flag = 1;
}
}
if (flag == 0)
{
int[] sorted = UserProgramCode.sortList(sorting);
Console.WriteLine("Sorted Array :");
foreach (int a in sorted)
{
Console.WriteLine("{0}", a);
}
}
else
{
Console.WriteLine("Invalid Input");
Console.ReadLine();
}
}
class UserProgramCode
{
public static int[] sortList(int[] sorting)
{
Array.Sort(sorting);
return sorting;
}
}
if (count == 0)
{
output1.Add("-1");
return output1;
}
for (int i = 0; i < size; i++)
{
if (li[i].Substring(0, 1) == ch.ToString())
{
li[i] = li[i] + '_' + count;
}
}
output = li;
foreach (var s in output)
{
if (s.Substring(0, 1) == ch.ToString())
{
output1.Add(s);
return output1;
Sorted Array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int n;
int flag = 0;
n = Convert.ToInt32(Console.ReadLine());
int[] sorting = new int[n];
for (int i = 0; i < n; i++)
{
int p = Convert.ToInt32(Console.ReadLine());
if (p > 0)
{
sorting[i] = p;
}
else
{
flag = 1;
}
}
if (flag == 0)
{
int[] sorted = UserProgramCode.sortList(sorting);
Console.WriteLine("Sorted Array :");
foreach (int a in sorted)
{
Console.WriteLine("{0}", a);
}
}
else
{
Console.WriteLine("Invalid Input");
}
Console.ReadLine();
}
}
class UserProgramCode
{
public static int[] sortList(int [] sorting)
{
Array.Sort(sorting);
return sorting;
}
}
}
String Manipulation
stringManipulation
public static string stringManipulation(string str1, string str2)
{
char[] ch = str2.ToCharArray();
Array.Reverse(ch);
str2 = new string(ch);
int n = str1.Length;
string a, b;
if (n % 2 == 0)
{
a = str1.Substring(0, n / 2);
b = str1.Substring(n / 2);
}
else
{
a = str1.Substring(0, (n + 1) / 2);
b = str1.Substring((n + 1) / 2);
}
{
f = 0;
}
else
{
f = 1;
}
}
if (f == 1)
{
res = "Special character found";
}
return (res);
}
String Processing 1
using System;
class UserProgramCode
{
public static string getString(string input1,int input2)
{
char[] ch = input1.ToCharArray();
string s=null;
int len = input1.Length;
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] >= '0' && ch[i] <= '9')
{
s = "-1";
goto s1;
}
}
}
for (int j = 0; j < ch.Length; j++)
if ((ch[j] >= 'a' && ch[j] <= 'z') || (ch[j] >= 'A' && ch[j] <= 'Z') || ch[j] ==
' ')
s = "1";
if(s=="1")
{
string q=null;
q=input1.Substring(len-input2,input2);
string h=null;
for (int w = 0; w < input2; w++)
h = h + q;
string n =input1+h;
s=n;
}
s1: return s;
}
}
Strong Number
strong no.
r = num % 10;
while (i <= r)
{
f = f * i;
i++;
}
sum = sum + f;
else
Console.WriteLine("Sum of all digits factorial is {0}, sum);
Console.ReadLine();
}
Sum of cubes of n natural numbers
//int num;
//double sum=0;
//Console.WriteLine("Enter the number: ");
//num = Convert.ToInt32(Console.ReadLine());
//for (int i = 1; i <= num; i++)
//{
//
//}
//Console.WriteLine("sum of cubes of n natral numbers : {0}",sum);
Sum of largest integer in range
public static void Main(string[] args)
{
int flag = 0;
int size, sum = 0;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (int i = 0; i < size; i++)
{
int it = Convert.ToInt32(Console.ReadLine());
}
else if (it > 100)
{
flag = 2;
}
}
if (flag == 0)
{
sum = UserProgramCode.largestNumber(arr);
Console.WriteLine(sum);
}
else if (flag == 1)
{
Console.WriteLine("-1");
}
else if (flag == 2)
{
Console.WriteLine("-2");
}
Console.ReadKey();
}
Array.Sort(arr);
ArrayList arrayList1 = new ArrayList();
ArrayList arrayList2 = new ArrayList();
ArrayList arrayList3 = new ArrayList();
ArrayList arrayList4 = new ArrayList();
ArrayList arrayList5 = new ArrayList();
ArrayList arrayList6 = new ArrayList();
ArrayList arrayList7 = new ArrayList();
ArrayList arrayList8 = new ArrayList();
ArrayList arrayList9 = new ArrayList();
ArrayList arrayList10 = new ArrayList();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] >=1 && arr[i] <= 10)
{
arrayList1.Add(arr[i]);
}
if (arr[i] >= 11 && arr[i] <= 20)
{
arrayList2.Add(arr[i]);
}
if (arr[i] >= 21 && arr[i] <= 30)
{
arrayList3.Add(arr[i]);
}
}
int temp=0 ,Max=0;
foreach (int x in arrayList1)
{
temp = x;
if (Max < temp)
{
Max = temp;
}
}
int a = 0, b = 0;
foreach (int x in arrayList2)
{
a = x;
if (b < a)
{
b = a;//b
}
}
int c = 0, d = 0;
foreach (int x in arrayList3)
{
c = x;
if (d < c)
{
d = c;//d
}
}
int e = 0, f = 0;
foreach (int x in arrayList4)
{
e = x;
if (f < e)
{
f = e;//f
}
}
int g = 0, h = 0;
foreach (int x in arrayList5)
{
g = x;
if (h < g)
{
h = g;//h
}
}
int k = 0, l = 0;
foreach (int x in arrayList6)
{
k = x;
if (l < k)
{
l = k;
}
}
int m = 0, n = 0;
foreach (int x in arrayList7)
{
m = x;
if (n < m)
{
n = m;//n
}
}
int o = 0, p = 0;
foreach (int x in arrayList8)
{
o = x;
if (p < o)
{
p = o;//p
}
}
int q = 0,yy=0;
foreach (int x in arrayList9)
{
temp = x;
if (yy < q)
{
yy = q;//yy
}
}
int pp = 0, qq = 0;
foreach (int x in arrayList10)
{
pp = x;
if (qq < pp)
{
qq = pp;//qq
}
//Console.WriteLine("{0}",Max);
summ= Max + b + d + f + h + l + n + p + yy + qq;
return summ;
}
Sum of n fibonnaci series
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
//Console.WriteLine(c);
//to get the series of fib
sum = sum + c;
a = b;
b = c;
}
return (sum);
}
Sum of Squares
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace ConsoleApplication34
{
class Program
{
static void Main(string[] args)
{
int number, sum;
number = Convert.ToInt32(Console.ReadLine());
sum = UserProgramCode.getSumOfSquareOfDigits(number);
Console.WriteLine(sum);
Console.ReadKey();
}
}
}
class UserProgramCode
{
public static int getSumOfSquareOfDigits(int number)
{
int sum = 0, squareDigit, digit, num;
num = number;
while (num != 0)
{
digit = num % 10;
squareDigit = digit * digit;
sum = sum + squareDigit;
num = num / 10;
return sum;
}
Symmetric Difference
---------------UserProgramCode
---------------using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
class UserProgramCode
{
public static int[] symmetricDifference(int[] input1, int[] input2)
{
var union = input1.Union(input2);
var intersect = input1.Intersect(input2);
var symmetric = union.Except(intersect);
int[] result = new int[symmetric.Count()];
// Write intersection to screen.
int i = 0;
foreach (int value in symmetric)
{
result[i] = value;
i++;
}
return result;
}
}
--------Program
--------using System;
class Program
{
public static void Main( string[] args )
int input1,input2;
input1 = Convert.ToInt32(Console.ReadLine());
input2 = Convert.ToInt32(Console.ReadLine());
for(int i=0;i<input1;i++)
inputArr1[i] = Convert.ToInt32(Console.ReadLine());
for(int i=0;i<input2;i++)
inputArr2[i] = Convert.ToInt32(Console.ReadLine());
int[] output =
UserProgramCode.symmetricDifference(inputArr1,inputArr2);
for(int i=0;i<output.Length;i++)
Console.WriteLine(output[i]);
}
Console.Read();
}
Triplets
Program.cs
using System;
class Program
{
public static void Main( string[] args )
{
int size=0,i,num;
size=Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
int[] output = new int[3];
for(i=0;i<size;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
num = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.findTriplets(arr,num);
for(i=0;i<output.Length;i++)
{
if(output[i]!=0)
Console.WriteLine(output[i]);
}
Console.Read();
}
}
}
UserCodeProgram.cs
using System;
class UserProgramCode
{
public static int[] findTriplets(int[] input,int num)
{
int[] triplet=new int[3];
for (int i = 0; i < input.Length; i++)
{
for (int j = i + 1; j < input.Length; j++)
{
for (int k = j+1; k < input.Length; k++)
{
if (input[i] < 0 || input[j] < 0 || input[k] < 0)
{
triplet[0] = -1;
}
else if (input[i] == input[j] || input[j] == input[k] || input[i] == input[k])
{
triplet[0] = -3;
}
}
}
if (triplet[0] + triplet[1] + triplet[2] == num)
{
return triplet;
}
else
{
triplet[0] = -2;
}
return triplet;
}
}
Validate Password
PASSWORD VALIDATION
using System;
using System.Globalization;
c
lass UserProgramCode
{
public static int validatePassword(string input1)
{
int output1 = 0; int sp = 0;
if (input1.Length >= 8)
{
char[] temp =input1.ToCharArray();
if (char.IsLetter(temp[0]) && char.IsLetterOrDigit(temp[input1.Length - 1]))
{
foreach (char item in temp)
{
if (item == '@' || item == '_' || item == '#')
{
sp++;
}
}
if (sp > 0)
{
output1 = 1;
}
else
{
output1 = -1;
}
}
else
{
output1 = -1;
}
}
else
{
output1 = -1;
}
return output1;
}
}
Validate Phone Number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication26
{
class Program
{
public static void Main(string[] args)
{
string number = Console.ReadLine();
int output = UserProgramCode.validatePhoneNumber(number);
if (output == 2)
Console.WriteLine("Invalid");
else
Console.WriteLine("Valid");
Console.ReadLine();
}
}
class UserProgramCode
{
if ((input.Length) == 10)
{
for (int i = 0; i < 10; i++)
{
if (!char.IsDigit(input[i]))
{
return 2;
}
}
}
else
{
return 2;
}
return 1;
}
}
}
Voter
//4.Voter
public static int output4;
public static void voter(string input1)
{
DateTime dt;
bool res = DateTime.TryParseExact(input1, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
int year = DateTime.Now.Year - dt.Year;
int month = DateTime.Now.Month - dt.Month;
if (month < 0)
{
year = year - 1;
month = month + 12;
}
if (year > 18)
{
output4 = 1;
}
else
{
output4 = -1;
}
}
Console.WriteLine(output4);
}
class UserMainCode
{
public static string getWordWithMaximumVowels(string sentence)
{
sentence = sentence.ToLower();
string[] sarr = sentence.Split();
string res = string.Empty;
int vow = 0;
int vow_max = 0;
foreach (string s in sarr)
{
char[] ch = s.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] >= 'a' && ch[i] <= 'z')
{
switch (ch[i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
vow++;
break;
}
if (vow > vow_max)
{
vow_max = vow;
res = new string(ch);
}
vow = 0;
}
return res;
}
}
reverse a substring
public static string reversesubstring(string str, int start, int end)
{
char[] abc = str.ToCharArray();
Array.Reverse(abc);
string ret = new string(abc);
string asp = ret.Substring(start, end);
return asp;
}
==================================================
===========================================
validate a negative number
public static string validatenegativenumber(string str)
{
}
if (flag == 0)
{
string s = new string(abc);
string g = s.Substring(1, s.Length - 1);
return g;
}
else
{
string g = "invalid number";
return g;
}
==================================================
========================
//Count vowels in a word
//
//string word;
//int len,count=0;
//Console.Write("Enter the word: ");
//word = Console.ReadLine();
//len = word.Length;
//for (int i = 0; i < len; i++)
//{
//
if(word[i]=='a'||word[i]=='e'||word[i]=='i'||word[i]=='o'||word[i]=='u')
//
//
//
count++;
}
//}
//Console.Write("Number of vowel are: {0}",count);
//Console.ReadKey();
==================================================
======================
if (char.IsLetterOrDigit(sentence[i]))
//
//
reverse[count] = sentence[i];
//
count++;
//
//}
//Array.Reverse(reverse);
//string rev = new string(reverse);
//string rev2 = rev.ToUpper();
//Console.WriteLine("reverse: {0}", rev2);
//Console.ReadKey();
==================================================
===========
//Calculation of discount
//
//
//}
//if (a == 'M')
//{
//
//
//}
//Console.WriteLine("Amount paid: {0}",amount);
//Console.ReadKey();
==================================================
====================
//Sum of cubes of n natural numbers
//
//int num;
//double sum=0;
//Console.WriteLine("Enter the number: ");
//num = Convert.ToInt32(Console.ReadLine());
//for (int i = 1; i <= num; i++)
//{
//
//}
//Console.WriteLine("sum of cubes of n natral numbers : {0}",sum);
==================================================
=====================
//length of the smallest string in the given string array
//
//int len = 0,small=0 ;
//string sentence;
//Console.WriteLine("Enter the sentence");
//sentence = Console.ReadLine();
//string[] strarr = sentence.Split(' ');
//foreach (string item in strarr)
//{
//
len = item.Length;
//
if (small == 0)
//
//
small = len;
//
//
//
//
//
small = len;
}
//}
//Console.WriteLine("smallest string length : {0}",small);
==================================================
========================
//Alternate addition and subtraction
//
//int[] nums = new int[10];
//int output=0;
//Console.WriteLine("Enter 10 numbers: ");
//for (int i = 1; i <= 10; i++)
//{
//
nums[i-1] = Convert.ToInt32(Console.ReadLine());
//}
//for (int i = 1; i <= 10; i++)
//{
//
if (i == 1 || i == 2)
//
//
//
//
else
//
//
if (i % 2 == 1)
//
//
//
//
if (i % 2 == 0)
//
//
//
//
}
}
//}
////Program p = new Program();
////p.sumdiff(out output, nums);
//Console.WriteLine("Output: {0}",output);
==================================================
============
//count all charecters of an string array
//
//string sent;
//int len;
//Console.WriteLine("Enter the string: ");
//sent = Console.ReadLine();
//char[] arr = sent.ToArray();
//len = arr.Length;
//arr.ToString();
//Console.WriteLine("NUmber of charecters: {0}", len);
==================================================
============
//remove duplicate elements and sum of even numbers
//
//int[] a = new int[10];
//int i = 0, j = 10, k=0,sum=0;
//Console.WriteLine("Input 10 numbers...");
//for (i = 0; i < 10; i++)
//{
//
a[i] = Int32.Parse(Console.ReadLine());
//}
//for (i = 0; i < j; i++)
//{
//
if (a[i] != -1)
//
//
//
//
if (a[i] == a[k])
//
//
//
a[k] = -1;
}
//
//
}
}
//}
//foreach (int item in a)
//{
//
if (item != -1)
//
//
//sum += item;
//
Console.WriteLine(item);
//
//}
//foreach (int item in a)
//{
//
//
//
sum += item;
//
//Console.WriteLine(item);
//
//}
//Console.WriteLine("sum is : {0}", sum);
==================================================
=================
//day of week
//
//int y = 0001, da = 1, m = 1;
//Console.WriteLine("year :");
//y = Convert.ToInt32(Console.ReadLine());
//Console.WriteLine("month :");
//m = Convert.ToInt32(Console.ReadLine());
//Console.WriteLine("day :");
//da = Convert.ToInt32(Console.ReadLine());
s//DateTime d = new DateTime(y,m,da);
//Console.WriteLine(d.DayOfWeek);
//Console.ReadKey();
==================================================
===============
//nextpalimdrome
//
//
//
num = Convert.ToInt32(Console.ReadLine());
//
dig = num+1;
//
int dige;
//
do
//
//
dige = dig;
//
sum = 0;
//
do
//
//
//
//
//
//
//Console.WriteLine(sum);
//
if (sum != dig)
//
//
dig = dig+1;
//
//Thread.Sleep(1000);
//
//Console.WriteLine(dig);
//
//
//
Console.WriteLine(sum);
===========================================
//nth element to *
//
//string str;
//int a,len=0,i = 0,lena = 0;
//Console.WriteLine("Enter the string: ");
//str = Console.ReadLine();
//string[] arr = str.Split(' ');
//lena = arr.Length;
//Console.WriteLine("Enter the element to be encrypted: ");
//a = Int32.Parse(Console.ReadLine());
//char[] aa = arr[a - 1].ToCharArray();
//len = arr.Length;
//foreach (char item in aa)
//{
//
aa[i] = '*';
//
i++;
//}
//string ou = new string(aa);
//string output = null;
//for (i = 0; i < lena; i++)
//{
//
//
//
//
//}
if (i != (a - 1))
output = output + " " + arr[i];
else
output = output + " " + ou;
if (char.IsDigit(item))
//
//
Console.WriteLine(item);
//
Thread.Sleep(1000);
//
int i = 0;
//
i = (int) item;
//
Console.WriteLine(i);
//
output += i;
//
//}
//Console.WriteLine("Sum of digits is : {0}",output);
}
==================================================
======
CALCULATE NUMBER OF STEPS TO FIND THE CHARACTER
//char[] arr = new char[]
//{ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x',
'c', 'v', 'b', 'n', 'm' };
//string input;
//Console.WriteLine("input: ");
//input = Console.ReadLine();
//char[] inn = input.ToCharArray();
//int sum = 0,place=0;
//foreach (char item in inn)
//{
//
//
//
if (item == arr[i])
//
//
//
place = i;
//
//
}
}
//}
//Console.WriteLine("sum: {0}",sum);
==================================================
===
// * between repeating chars
//
//string str;
//Console.WriteLine("Enter the string: ");
//str = Console.ReadLine();
//char[] a = str.ToCharArray();
//ArrayList al = new ArrayList();
//al.Add(a[0]);
//for (int i = 1; i < a.Length; i++ )
//{
//
//
//
al.Add('*');
//
al.Add(a[i]);
//
//
else
//
//
//
al.Add(a[i]);
}
//}
//foreach (char i in al)
//{
//
Console.Write(i);
//}
//Console.ReadKey();
==================================================
===============
//Roman to decimal
//
//string str;
//Console.WriteLine("Enter the roman number: ");
//str = Console.ReadLine();
//char[] arr = str.ToCharArray();
//int output = 0, inp = 0;
//char itemc = 'z';
//foreach (char item in arr)
//{
//
//
//
//
if (item == 'I')
inp = 1;
else if (item == 'V')
inp = 5;
//
//
//
inp = 50;
else if (item == 'C')
//
//
inp = 100;
else if (item == 'D')
//
//
inp = 500;
else if (item == 'M')
//
//
inp = 1000;
else if (item == 'X')
//
inp = 10;
//
//
//
//
//
//
//
//
//
//
//
//
itemc = item;
//
//
//
else
//
//
//
//
itemc = item;
//
//
//}
//Console.WriteLine("Output : {0}", output);
====================================
}
else
flag = 1;
}
if (flag == 1)
{
result1 = "-1";
return result1;
}
else
{
result2 = abc.ToString();
return result2;
}
===================================
Insert to middle of string
public static string output14;
public static void insertMiddle(string input1, string input2)
{
char[] chararr = input2.ToCharArray();
Array.Reverse(chararr);
string str = new string(chararr);
output14 = input1.Substring(0, input1.Length / 2) + str +
input1.Substring(input1.Length / 2 + 1);
Console.WriteLine(output14);
}
================================================
{
output2 = "-1";
}
Console.WriteLine(output2);
}
Add Series
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
public static void Main(string [] args)
{
int n;
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.addSeries(n));
Console.ReadLine();
}
}
}
class UserProgramCode
{
public static int addSeries(int n)
{
int sum=0;
for(int i=1;i<=((n+1)/2);i++)
{
if (i == 1)
sum = sum + i;
else if (i % 2 == 0)
sum = sum + (2 * i - 1);
else
}
return sum;
}
}
Add Years
Adding years to date. If date format is wrong return -1. If years given is negative
return -2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "27/09/1992";
int input2=2;
int output1 = 0;
string output=" ";
DateTime dt;
bool res = DateTime.TryParseExact(input1, "dd/MM/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
output = dt.ToString("dd/MM/yyyy");
// Console.WriteLine(output);
output1 = 1;
}
if (res == false)
{
output1 = -1;
}
if (input2 < 0)
{
output1 = -2;
}
Console.WriteLine(output1);
Console.Read();
}
}
}
ALL VOWELS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode {
public static int testOrderVowels(string input1)
{
int output1 = 0;
char[] ch = input1.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u')
{
sb.Append(ch[i]);
}
if (sb.ToString() == "aeiou")
{
output1 = 1;
}
else
{
output1 = -1;
}
}
return output1;
}
}
//
nums[i-1] = Convert.ToInt32(Console.ReadLine());
//}
//for (int i = 1; i <= 10; i++)
//{
//
if (i == 1 || i == 2)
//
//
//
//
else
//
//
if (i % 2 == 1)
//
//
//
//
if (i % 2 == 0)
//
//
//
//
}
}
//}
////Program p = new Program();
////p.sumdiff(out output, nums);
//Console.WriteLine("Output: {0}",output);
}
using System;
using System.Text;
using System.Collections;
class UserProgramCode
{
public static int[] arrangeAfterCubing(int[] input1)
{
int i=0,ch,c;
int ch1=0,flag=1;
int s = input1.Length;
ArrayList sb = new ArrayList();
int[] op1 = new int[s];
for (i = 0; i < s; i++)
{
if (input1[i] < 0)
{
flag = 0;
ch1 = input1[i] * input1[i];
input1[i] = ch1;
}
}
if (flag == 0)
{
for (i = 0; i < s; i++)
{
op1[i] = input1[i]; ;
}
return op1;
}
else
{
for (i = 0; i < s - 1; i++)
{
ch = input1[i] * input1[i];
if (input1[i + 1] == ch)
{
c = input1[i] * input1[i] * input1[i];
if (i == 0)
{
sb.Add(input1[i]);
sb.Add(c);
sb.Add(input1[i + 1]);
}
else
{
sb.Add(c);
sb.Add(input1[i + 1]);
}
}
else
{
if (i == 0)
{
sb.Add(input1[i]);
sb.Add(input1[i + 1]);
}
else
{
sb.Add(input1[i + 1]);
}
}
}
int len = sb.Count;
int[] op = new int[len];
i = 0;
foreach (int n in sb)
{
op[i] = n;
i++;
}
return op;
}
}
}
Array Median
public static int GetMedian(int[] Value)
{
decimal Median = 0;
int size = Value.Length;
int mid = size / 2;
Median = (size % 2 != 0) ? (decimal)Value[mid] : ((decimal)Value[mid] +
(decimal)Value[mid+ 1]) / 2;
return Convert.ToInt32(Math.Round(Median));
}
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)
ALPHABET"
//
-> (0-9)
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)
{
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);
}
}
}
Berth Type
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace seatnumber
{
class Program
{
static void Main(string[] args)
{
try
{
parentseat = Convert.ToInt32(Console.ReadLine());
grandfatherseat = Convert.ToInt32(Console.ReadLine());
sonseat = Convert.ToInt32(Console.ReadLine());
//divide = grandfatherseat % 8;
}
else
{
Console.WriteLine("Invalid seat number");
}
}
catch (Exception e)
{
Console.WriteLine("invalid input");
}
Console.ReadLine();
}
}
}
BMI
namespace SM1
{
class UserProgramCode
{
}
class Program
{
static void Main(string[] args)
{
float w = float.Parse(Console.ReadLine());
float h = float.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.BMICalc(w, h));
Console.ReadLine();
}
}
}
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);
}
}
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)
{
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)
ALPHABET"
//
-> (0-9)
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)
{
}
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
{
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");
}
}
}
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][09][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");
}
}
}
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);
}
}
}
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;)
//
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);
}
}
}
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;
}
}
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);
}
}
}
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");
}
}
}
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;
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);
}
}
}
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
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);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace finaltakehomesalary
{
class Program
{
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)
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);
}
}
}
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);
}
static void Main(string[] args)
{
int[] n = new int[] { 1, 2, 3, 5, 7, 5, 0, 9 };
Program.elements(n, 2, 7);
}
}
}
25.voting
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)
{
}
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 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");
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;
}
}
static void Main(string[] args)
{
Program.vat(20000, 'M');
}
}
}
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);
}
}
}
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");
}
}
}
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.prime no 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);
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#");
}
}
}
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);
}
}
}
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);
}
}
}
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");
}
}
}
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);
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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();
}
}
else
{
Console.WriteLine("First Character Is A Number");
count1++;
}
}
else
{
}
}
else
{
Console.WriteLine("First Character Is A Small Character");
count1++;
}
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);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
}
}
}
==================================================
=======
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Console.Read();
}
}
}
==================================================
=======using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
}
}
==================================================
=======
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
}
foreach (var item in b)
{
if ((a.Contains(item)) == false)
c.Add(item);
}
}
}
==================================================
=======
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//input2:2015-01-22
//output:24
namespace ConsoleApplication8
{
class Class2
{
public static void monthdiff(string input1, string input2)
{
//DateTime dt1;
//DateTime dt2;
DateTime dt1 = Convert.ToDateTime(input1);
DateTime dt2 = Convert.ToDateTime(input2);
//dt1 = DateTime.TryParseExact(input1, "YYYY - mm - dd", null);
//dt2 = DateTime.TryParseExact(input1, "YYYY - mm - dd", null);
TimeSpan t = dt2 - dt1;
double res = t.TotalDays;
double output= (res / 365)*12;
Console.WriteLine(output);
Console.Read();
}
static void Main(string[] args)
{
Class2.monthdiff("2013 - 01 - 22", "2015 - 01 - 22");
}
}
==================================================
=======Day name to be printed
String str="14-2-2014";
DateTime dt;
bool res=Date.TryParseExact(str,"dd-MMyyyy",null,System.Globalization.DateTimeStyles.None,out dt);
if(res==true)
{
string op=dt.DayofWeek.ToString();
Console.WriteLine(op);
}
==================================================
===================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//3.Wap to find if the given string has vowels in alphabetical order or not.
No vowels should repeat.
namespace ConsoleApplication8
{
class Program
{
public static void method(string input)
{
int j = 0,output=0;
char[] ch1= new char[50];
char[] ch = input.ToLower().ToCharArray();
foreach (char c in ch)
{
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
{
ch1[j] = c;
j++;
}
}
for (int i = 0; i < j-1; i++)
{
if (ch1[i] > ch1[i + 1])
{
output = -1;
}
else
{
output = 1;
}
}
Console.WriteLine( output);
Console.Read();
}
static void Main(string[] args)
{
Program.method("life");
}
}
}
========================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Class1
{
public static void method(string input,int input1,int input2)
{
char[] strarr = input.ToCharArray();
Array.Reverse(strarr);
StringBuilder sb=new StringBuilder();
for (int i = input1; i <(input1+input2); i++)
{
sb.Append(strarr[i]);
}
string output = string.Empty;
output = sb.ToString();
Console.WriteLine(output);
Console.Read();
}
namespace ConsoleApplication8
{
class Class2
{
public static void monthdiff(string input1, string input2)
{
//DateTime dt1;
//DateTime dt2;
DateTime dt1 = Convert.ToDateTime(input1);
DateTime dt2 = Convert.ToDateTime(input2);
}
}
}
==================================================
=======
squares
//2.sum of squares of gigits
//input:321
//3*3+2*2+1*1
//output:14
namespace ConsoleApplication9
{
class Class1
{
static void Main(string[] args)
{
int num = 321;
int rem = 0;
double sum = 0;
while (num > 0)
{
rem = num % 10;
sum = sum +( Math.Pow(rem,2));
num = num / 10;
}
Console.WriteLine(sum);
Console.Read();
}
}
}
==================================================
=======
/3.password validation
==================================================
=======
Length of shortest word
namespace ShortWord
{
class Program
{
static void Main(string[] args)
{
string[] strarr = {"good","bad","life","at" };
int min=strarr[0].Length;
int j=0;
string s1=string.Empty;
foreach (string s in strarr)
{
j = s.Length;
if (j < min)
{
min = j;
s1 = s;
}
}
Console.WriteLine(s1);
Console.Read();
}
}
}
==================================================
=============
5.print word where the length is maximum in string array
if two words has largest length,print the word which comes first in the array
==================================================
=================
6.input:"read"
"write"
"edit"
"elbow"
input2:'e'
output:"edit","elbow"
==================================================
==================
count no.of characters in string array
==================================================
===================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//3}Ex: input1-welcome
//input2: 3
//output=welome(3char from strtng and 3 char from ending)
namespace RemovingElementsSpecified
{
class Program
{
public static void method(string input)
{
char[] ch = input.ToCharArray();
int j=input.Length;
string s = string.Empty;
string output=s;
Console.WriteLine(output);
Console.Read();
}
using System.Text;
namespace Assess
{
class Fileafterdot
{
public static void Namedot(string str)
{
int k = str.IndexOf(".");
string res = str.Substring(k + 1);
Console.WriteLine(res);
}
}
}
==================================================
=====================
given string array it shld contain numbers only in numeric format not in
letters
ex: input-{"123","24.5"},output= 1
input={"123","one"},output= -1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnlyIntegerStrings
{
class Program
{
static void Main(string[] args)
{
string[] s1=new string[100];
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter {0} strings",n);
char[] c=new char[100];
//int[] p = new int[100];
int count1 = 0;
for (int i = 0; i<n; i++)
{
s1[i] = Console.ReadLine();
}
int count=0;
for (int i = 0; i<n; i++)
{
count = 0;
foreach (var item in s1[i])
{
//if (!((item >= 'a' && item <= 'z') || (item >= 'A' && item <= 'Z')))
if ((item >= 48 && item <= 57) || (item >= 48 && item <= 57 && item ==
46))
{
count++;
}
//p[i] = count;
count1++;
}
if (count1 == n)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("-1");
}
Console.ReadLine();
}
}
}
==================================================
===================
given input string store the word with max no of vowels in output
ex:input=sun rises in the east
output=rises
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MaxnumberofVowels
{
class Program
{
static void Main(string[] args)
{
int n,i;
Console.WriteLine("enter n");
n=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter {0} strings",n);
string[] s=new string[n];
int count=0;
string output="";
int max = -1;
for ( i = 0; i <n; i++)
{
s[i] = Console.ReadLine();
}
int[] a=new int[100];
for ( i = 0; i < n; i++)
{
count = 0;
foreach (var item in s[i])
{
if (item == 'a' || item == 'A')
{
count++;
}
if (item == 'e' || item == 'E')
{
count++;
}
if (item == 'i' || item == 'I')
{
count++;
}
if (item == 'o' || item == 'O')
{
count++;
}
if (item == 'u' || item == 'U')
{
count++;
}
Console.WriteLine(output);
Console.Read();
}
}
}
==================================================
====================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Assess
{
class DaysinMonth
{
public static void Getdays(string str)
{
//string str = "12-07-2014";
DateTime dt;
bool res = DateTime.TryParseExact(str, "dd-MM-yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
}
}
}
==================================================
===============================
given a string array. find the string with smallest length and starts with
given char(input2).
==================================================
===================================
namespace Assess
{
class Oddnext
{
public static void nextchar(string str)
{
char[] ch = str.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
if (i % 2 == 0)
{
ch[i] = Convert.ToChar(Convert.ToInt32(ch[i] + 1));
}
else
{
ch[i] = ch[i];
}
}
string res = new string(ch);
Console.WriteLine(res);
}
}
}
==================================================
=======================================
given a string, print the smallest length string and if more than one string
is present with same length, then print the string whose first letter comes
first in aplhabest(ex= kolkata,chennai o/p:chennai)
==================================================
====================================
Convert roman to decimal.If the input is anything other than capital
"I',"V',"X','L','C','D','M'..store -1 in the output
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RomanNum
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter string");
string str = Console.ReadLine().ToUpper();
int sum=0;
int[] arr = str.ToCharArray().Select(x => { return x == 'I' ? 1 : x == 'V' ? 5 :
x == 'X' ? 10 : x == 'L' ? 50 : x == 'C' ? 100 : x == 'D' ? 500 : x == 'M' ? 1000 :
0; }).ToArray() ;
foreach (int j in arr)
{
sum = sum + j;
}
for (int k = 0; k < arr.Length-1; k++)
{
if (arr[k] < arr[k + 1])
{
sum = sum - 2 * arr[k];
}
}
Console.WriteLine(sum);
Console.Read();
}
}
}
==================================================
=================================
2.Count the number of vowels in given string.If the string consists of anything other
than alphabet store -1 in output variable
4.Sum of cubes of n natural numbers.If the input is other than natural number store
-1 in output array
==================================================
============================
compute current bill
given inputs:
string input1 : meter reading of the form XXXXXAAAAA
(for eg:ABC2012345)
string input2 : meter reading of the form XXXXXAAAAA
(for eg:ABC2312660)
where first 5 characters refer to customerid and next 5 characters refer to currrent
bill
int input3:total number of units used (for eg: 4 units)
now compute the bill (by using the values in the exAMPLE)
OUTPUT1=(12345-12660)*4
==================================================
============================
purchase amount discount on tv discount on music system
1-25000
25001-50000
>50000
10
10
15
20
30
nonac=600.if input3 is -v2,op is -2.if ip1 is not C or H or B,op=-1.if ip3 is not "AC" or
"NAC" op=-1.
==================================================
reversing the array and conditions a)-1 if array size <0 b) -2 if any negative
element in the array
============================================
date related question like assign output the day of the week in lower case when
input is one year and output day must be next year
=================================================
count the 3 consecutive repeated elements in the string a)print the count b)if no
such element print out put=-1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace threetimesrepeated
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
int count=0;
int out1=0;
char[] ch = str.ToCharArray();
int j=1;
for (int i = 0; i <ch.Length; i++)
{
if (ch[i] == ch[j])
{
count++;
j++;
if (count == 2)
{
out1 = 1;
break;
}
}
Console.WriteLine(out1);
Console.ReadLine();
}
}
}
==================================================
===========================
input1,input2,input3 are strings,check whether input3 comes next to input2 in
input1
eg:input1:abcdefghijkl
input2 ef
input3:jkl
if true o/p=1
else o/p=2
==================================================
===================
in a string remove all the repeated elemnts where as putting o/p=first occurance of
that elemnt in same format
businness logics:
a)if such display o/p
b)else o/p=-1
==================================================
====================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assess
{
class Splchar
{
}
}
==================================================
===================
write a method to accept "first name" and "last name" as input1 and store
last name and intial of first name in the ouput1.
namespace Assess
{
class Colorcode
{
public static void code(string str)
{
Regex dd = new Regex(@"^[#]{1}([A-F-0-9]{6})$");
if (dd.IsMatch(str))
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("-1");
}
Console.ReadLine();
}
}
}
==================================================
=========================
write a method to store the sum of first n fibonacci numbers the input1 contains n.
sum=0+1+1+2+3+5+8..... in output1.
Example:input1=5
sum=0+1+1+2+3=7
output1=7
==================================================
==========================
write a method to accept a string as input1 and character in input2 and
store the number of times the input2 character had occured in input1
string in output1.
Business Rules:
1) It should be counted despite its case.
2) The string should contain only alphabets else store "-1" in the output1.
string s1 = Console.ReadLine();
char ch = Convert.ToChar(Console.ReadLine());
char[] ch1 = s1.ToCharArray();
int c = 0;
foreach (var n in ch1)
{
if (n==char.ToUpper(ch) || n==char.ToLower(ch))
{
c++;
}
}
Console.WriteLine ;
Console.ReadLine();
==================================================
========================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//6)write a method to count the no, of vowels in the given input string and
the vowels can be of any order and assume that the vowels are not
repeated.
//Business rules:
//
1)If the count is equal to 5 and alphabetical order store 1 in the output1.
//
//
//Example:input1="aeiosawu"
//
output1=1
namespace NonRepeatedVowels
{
class Program
{
public static void method(string input)
{
char[] ch = input.ToLower().ToCharArray();
string s = string.Empty;
}
}
char[] res =s.ToCharArray();
char[] v= res.Distinct().ToArray();
Console.WriteLine(v.Length);
Console.Read();
}
static void Main(string[] args)
{
Program.method("aeiosawu");
}
}
}
==================================================
=============================================
reverse all characters of given string
input={"hai hello"}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace reversearray
{
class Program
{
static void Main(string[] args)
{
string str = "hi hello";
string[] s1=str.Split(' ');
for (int i = 0; i < s1.Length; i++)
{
Array.Reverse(s1);
}
foreach (var b in s1)
{
Console.WriteLine(s1);
Console.ReadLine();
}
}
}
}
================================
count no of vowels in given string
input=avinash
o/p=3
4)calculate vat amount based on given bill amount and type of product
m----vat 9%
v-----vat 65%
e-----vat 34%
z-----vat 6.25%
(5).WAP to find the odd and even numbers from array and square of odd nos
==================================================
====================
1)i/p1-{even,elephant,parrot,apple",even","eager"}
i/p2-{'e'}
o/p-{"even"}
output first string that match with given character,having minimum length.
Bussiness Rule:
only letters is to be allowed as input else display {'-1"}
if there is no match of given character with the strings present in array diaplay {"2"};
==================================================
=====================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DaysInAMonth
{
class Program
{
public static void month(int input1,int input2)
//public static void month(string input)
{
int output = 0;
// DateTime dt;
//bool res =
DateTime.TryParseExact(input,"MM/dd/yyyy",null,System.Globalization.DateTimeStyl
es.None,out dt);
//if (res == true)
//{
// output=DateTime.DaysInMonth(dt.Year,dt.Month);
//}
output = DateTime.DaysInMonth(input1, input2);
Console.WriteLine(output);
Console.Read();
}
static void Main(string[] args)
{
Program.month(2014,2);
// Program.month("02/19/2014");
}
}
==================================================
==========================
input delhi:mumbai:bihar:cochin
input 2:delimeter
output:bihar
select the name which have minimum length and in alphabetical order
eg:bihar delhi have minimum length.so, based on alphabetical order bihar should be
o/p
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//output:bihar
//select the name which have minimum length and in alphabetical order
//eg:bihar delhi have minimum length.so, based on alphabetical order bihar should
be o/p
namespace WordWithMinLength
{
class Program
{
public static void method(string[] input)
{
Array.Sort(input);
int j = 0,min=0,k=0;
min = input[0].Length;
string res=string.Empty;
foreach (string s in input)
{
if (j == min)
{
continue;
}
if (j < min)
{
min = j;
res = s;
}
}
Console.WriteLine(res);
Console.Read();
}
static void Main(string[] args)
{
string[] strarr = new string[] {"delhi","bihar","mumbai","cochin" };
Program.method(strarr);
}
}
}
==================================================
===========
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace underscoreprgm
{
class Program
{
static void Main(string[] args)
{
string str = "rabbit";
char[] ch = str.ToCharArray();
Array.Reverse(ch);
string s1 = string.Empty;
for (int i = 0; i < ch.Length; i++)
{
s1 = s1 + ch[i] + '-';
}
char[] c1=s1.ToCharArray();
string s2=string.Empty;
for (int i = 0; i < (c1.Length) - 1; i++)
{
s2 = s2 + c1[i];
}
Console.WriteLine(s2);
Console.ReadLine();
}
}
}
==================================================
====================
i/p1-{"parrot'}
o/p-{"qasrpt"}
assume odd postion of an array as 0 .replace letters in odd postions with next
alphabet
example-a should be replaced with b .....z with a.
namespace Assess
{
class Oddnext
{
public static void nextchar(string str)
{
char[] ch = str.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
if (i % 2 == 0)
{
ch[i] = Convert.ToChar(Convert.ToInt32(ch[i] + 1));
}
else
{
ch[i] = ch[i];
}
}
string res = new string(ch);
Console.WriteLine(res);
}
}
}
==================================================
=================================
2.i/p1={1,2,3,1,2,2,2,3,2,2,2}
o/p=10
here find the max count b/w repeated elements including the number
count
1 is repeated twice so include ones in the count o cont for 1 is 4
2 is repeated 7 times and the no of digits b/w first 2 and last 2 is
10
so o/p is 10
3 is no where repeated so no need to count
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RepeatDiffSum
{
class Program
{
public static void method(int[] arr)
{
int sum=0;
int[] arr1 = new int[10];
int count, k = 0, count1;
for (int i = 0; i < arr.Length; i++)
{
count = 0;
count1 = 0;
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[i] == arr[j])
{
count++;
count1 = j;
arr1[k] = arr[j];
arr[j] = 0;
sum = count + count1;
}
}
}
Console.WriteLine(sum);
}
static void Main(string[] args)
{
int[] n = new int[] { 1, 2, 3, 1, 2, 2, 2, 3, 2, 2, 2 };
Program.method(n);
Console.Read();
}
}
}
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$0r$$$$$$$$$$$$$$$$$$$
$$
class ReapetedCount
{
Console.WriteLine(count);
==================================================
=================================================
3.using list:
store the no's greater than 5 and less than 500 if greater than 500 store -1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NewPrgm
{
class Class5
{
static void Main(string[] args)
{
List<int> a = new List<int>();
// Console.WriteLine("enter number of elements");
int b = Convert.ToInt32(Console.ReadLine());
// int cnt=0;
//for (int i = 0; i < b; i++)
//{
//
//
//
//
continue;
else
//
cnt++;
//}
//if (cnt > 0)
//
a.Add(-1);
//else
//{
//
//
//
//
a.Add(input1);
//
// }
if (b > 5 && b < 500)
a.Add ;
else
a.Add(-1);
foreach (var item in a)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
==================================================
============================
//1.find the sum of the powers of each digit in a no. depnding on its indices
// eg: input1(integer)= 345
// output(integer)=30
// (3^0+4^1+5^2=30)
namespace SumOfProdOfNumWithInd
{
class Program
{
public static void method(int input)
{
int output;
int rem = 0, count = 0;
double sum=0;
int temp = input;
while (input > 0)
{
rem= input % 10;
count++;
input = input / 10;
}
input = temp;
rem = 0;
while (input > 0)
{
rem = input % 10;
sum=sum+(Math.Pow(rem,(count-1)));
count--;
input = input / 10;
}
Console.WriteLine(sum);
Console.Read();
}
static void Main(string[] args)
{
Program.method(345);
}
}
}
==================================================
=========================
2.searching a no. in an array
B.Rules:if element to be searched is present in array output=1
if any element in array or no. to be searched is negative output=2
if element to be searched is not there in array output=-1
==================================================
=======
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter string");
string str = Console.ReadLine();
string[] s = str.Split(' ');
string p=string.Empty;
for (int i = 0; i < s.Length; i++)
{
if (s[i] == "is")
{
p = p +s[i]+' '+ "not" + ' ';
s[i]=p;
}
}
string h = string.Empty;
foreach(string x in s)
{
h = h + x + ' ';
}
Console.WriteLine(h);
Console.ReadLine();
}
}
}
==================================================
=======
wo input strings.output must be the count of how many times 2nd word of
the input2 present in input1
input1: "A dog is a dog"
input2:" A dog is pet animal"
output: 2
6.input is a integer
output must be the highest digit in a no.
eg: input1: 4629
output=9;
===================================
2.LIST1:[2,3,5,6]
LIST2:[6,8,9,0,5]
OUTPUT 22
BUSINESS RULE1:1.IF in List 1 any element is -ve output -1
==============================================
i/p:gowtham
o/p gtwahm
o/p gtwahm
'case2:mahesh o/p:amehhs
3.i/p1:list<string>,i/p2:char o/p tring that start with char(i/p2) and having highest
length
namespace Assess
{
class Telephonebill
{
public static void tbill(int input)
{
double output1;
if (input < 300)
{
output1 = 200;
}
if ((input > 300) && (input <= 350))
{
output1 = 200 + (input - 300) * 0.6;
Console.WriteLine(output1);
}
if ((input > 350) && (input <= 400))
{
output1 = 200 + (50 * 0.6) + ((input - 350) * 0.5);
Console.WriteLine(output1);
}
if (input > 400)
{
output1 = 200 + (50 * 0.6) + (50 * 0.5) + ((input - 400) * 0.4);
Console.WriteLine(output1);
}
}
}
}
==================================================
=============================
calculate the rate of interest for given princple amount and given no of years
if p<50000 and p> 100001 and no of years (n)>3 interest is 8.75%
if p>500001 and p<10000001 and n>5 interest is 9.5%
by default interest for any amount and years is 8.25%
simple interest =(p*t*r)/100;
business logics:
if p negative output must be -1
if n is negative output must be -1
(question is similar but not with exact values)
and some more business logics having -2 and -3 also
==================================================
============================
6 . XML()
John Smith White question
==================================================
=======
remove tens in an array n appent trailing edges with zero
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
if (a[i] == 10)
{
int b = i;
while (b < (n-1))
{
a[b] = a[b + 1];
a[n - 1] = 0;
b++;
}
}
foreach (int g in a)
{
Console.WriteLine(g) ;
}
Console.ReadLine();
}
}
}
1. COMMON CHARACTER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main()
{
String input1 = Console.ReadLine();
String input2 = Console.ReadLine();
Console.WriteLine(UserProgramCode.commonChars(input1, input2));
Console.ReadLine();
}
}
class UserProgramCode
{
public static int commonChars(String input1, String input2)
{
char[] s1a = input1.ToCharArray();
int l1 = input1.Length;
int l2 = input2.Length;
Array.Sort(s1a);
Array.Sort(s2a);
else if (!s1c.Contains(s1a[i]))
{
s1c.Add(s1a[i]);
}
}
continue;
else if (!s2c.Contains(s2a[i]))
{
s2c.Add(s2a[i]);
}
}
int c = 0;
// Console.WriteLine(c);
return c;
*************************************************************************************
********
2)common element in an array
{
foreach (var item1 in list2)
{
if (item < 0 || item1 < 0)
{
count++;
}
}
}
if (count > 0)
{
abs.Add(-1);
}
else
{
abs = list1.Intersect(list2).ToList();
}
return (abs);
********************************************************************
3) extract max substring
string MaxStr="";
int maxLength = 0;
string[] ar = str.Split(Convert.ToChar(sym));
if(s.Length == maxLength)
{
if (MaxStr != "")
{
if (Convert.ToChar(s.ToLower().Substring(0, 1)) <
Convert.ToChar(MaxStr.ToLower().Substring(0, 1)))
{
MaxStr = s;
maxLength = s.Length;
}
}
}
else if (s.Length > maxLength)
{
MaxStr = s;
maxLength = s.Length;
}
else { }
}
return MaxStr;
*****************************************************************************
int flag = 1;
int sum = 4;
if (input1 == 1)
{
sum = 1;
}
else if (input1 == 3)
{
sum = 4;
}
else if (input1 > 3)
{
for (int i = 5; i <= input1; i = i + 2)
{
if (flag == 1)
{
sum = sum - i;
flag = 0;
}
else
{
sum = sum + i;
flag = 1;
}
}
}
return (sum);
***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int getSumOfNfibos(int n)
{
{
int a = -1, b = 1, c = 0, i, sum = 0;
int input1 = n;
for (i = 1; i <= input1; i++)
{
c = a + b;
//Console.WriteLine(c);
//to get the series of fib
sum = sum + c;
a = b;
b = c;
}
return (sum);
}
*********************************************************************************
6)check anagrams
using System;
class Program
{
public static void Main( string[] args )
{
string str1 = Console.ReadLine();
string str2 = Console.ReadLine();
Console.WriteLine(UserProgramCode.checkAnagram(str1,
str2).ToString().ToUpper());
}
}
using System;
class UserProgramCode
{
public static bool checkAnagram(string str1, string str2)
{
// fill your code here
str1 = str1.ToLower();
str1 = str1.Replace(" ", "");
str2 = str2.ToLower();
str2 = str2.Replace(" ", "");
{
return false;
}
}
foreach (char item in str2)
{
if (!char.IsLetter(item))
{
return false;
}
}
if (ix == -1)
return false;
}
return true;
}
}
************************************************************************************
7)date diff
using System;
class Program
{
public static void Main( string[] args )
{
string date1=Console.ReadLine();
string date2=Console.ReadLine();
int result = UserProgramCode.getMonthDifference(date1,date2);
Console.WriteLine(result);
}
}
using System;
class UserProgramCode
{
public static int getMonthDifference(string inputDate1,string inputDate2)
{
// fill your code here
DateTime d1 = Convert.ToDateTime(inputDate1);
DateTime d2 = Convert.ToDateTime(inputDate2);
TimeSpan d3 = (d2 - d1);
double month = d3.TotalDays;
month = month / 30;
month = Math.Floor(month);
return Convert.ToInt32(month);
}
}
***********************************************************************
8)revised salary
using System;
class Program
{
public static void Main( string[] args )
{
int salary;
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for(int i=0;i<4;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
salary = UserProgramCode.revisedSalary(arr);
Console.WriteLine(salary);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static int revisedSalary(int[] arr)
{
// fill your code here
int id = arr[0];
int grade = arr[1];
int rating = arr[2];
int sal = arr[3];
int newsal = 0;
if (id >= 100000 && id <= 500000)
{
if (grade == 1)
{
if (rating == 1)
{
newsal = (Int32)(newsal + sal * .15 + sal);
return newsal;
}
else if (rating == 2)
{
newsal = (Int32)(newsal + sal * .1 + sal);
return newsal;
}
else if (rating == 3)
{
newsal = (Int32)(newsal + sal * .05 + sal);
return newsal;
}
else
{
return -3;
}
}
else if (grade == 2)
{
if (rating == 1)
{
newsal = (Int32)(newsal + sal * .1 + sal);
return newsal;
}
else if (rating == 2)
{
newsal = (Int32)(newsal + sal * .05 + sal);
return newsal;
}
else if (rating == 3)
{
newsal = (Int32)(newsal + sal * .02 + sal);
return newsal;
}
else
{
return -3;
}
}
else if (grade == 3)
{
if (rating == 1)
{
}
}
*****************************************************************************
9)sum of squares
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getSumOfSquaresOfDigits(n));
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int getSumOfSquaresOfDigits(int n)
{
return sum;
}
}
}
*************************************************************************************
***************************
10)tarrif
sing System;
class Program
{
public static void Main( string[] args )
{
string input1,input2;
int output;
input1 = Console.ReadLine();
input2 = Console.ReadLine();
output = UserProgramCode.calculateTariff(input1,input2);
Console.WriteLine(output);
}
}
using System;
class UserProgramCode
{
cost = 200;
else
cost = -2;
}
else if (input1 == "Car")
{
if (input2 == "Single")
cost = 20;
else if (input2 == "Return")
cost = 38;
else if (input2 == "Daily")
cost = 65;
else if (input2 == "Monthly")
cost = 1500;
else
cost = -2;
}
else if (input1 == "LCV")
{
if (input2 == "Single")
cost = 34;
else if (input2 == "Return")
cost = 60;
else if (input2 == "Daily")
cost = 90;
else if (input2 == "Monthly")
cost = 2100;
else
cost = -2;
}
else if (input1 == "Bus")
{
if (input2 == "Single")
cost = 54;
else if (input2 == "Return")
cost = 100;
else if (input2 == "Daily")
cost = 150;
else if (input2 == "Monthly")
cost = 3450;
else
cost = -2;
}
else if (input1 == "Truck")
{
if (input2 == "Single")
cost = 80;
else if (input2 == "Return")
cost = 140;
else if (input2 == "Daily")
cost = 220;
else if (input2 == "Monthly")
cost = 5100;
else
cost = -2;
}
else
{
cost = -1;
}
return cost;
}
}
*************************************************************************************
*************************************
11)validate password
using System;
class Program
{
public static void Main( string[] args )
{
String password=Console.ReadLine();
int result=UserProgramCode.validatePassword(password);
if(result==1)
Console.WriteLine("Valid password");
else
Console.WriteLine("Invalid password");
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static int validatePassword(String input)
{
// fill your code here
int output1 = 0, letter = 0, digit = 0, sc = 0;
if (input.Length >= 6 && input.Length <= 20)
{
char[] ch = input.ToCharArray();
foreach (char c in ch)
{
if (char.IsDigit(c))
letter++;
if (char.IsLetter(c))
digit++;
if (c == '@' || c == '#' || c == '$')
sc++;
}
if (digit >= 1 && sc >= 1 && (letter + digit + sc) == input.Length)
output1 = 1;
else
output1 = -1;
}
else
output1 = -1;
return output1;
}
}
*************************************************************************************
*************************************
12)/////count vowels///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CountVowells
{
class UserProgramCode
{
public static int countVowels(string input)
{
int output = 0;
foreach (char c in input)
{
if (char.IsLetter(c) == false)
{
output = -1;
return output;
}
else
{
switch (c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
output++;
break;
}
return output;
}
}
}
*************************************************************************************
***********************************
13)
int bill;
if(input2=="AC")
if(input1=='C')
bill=1300*input3;
Console.WriteLine(bill);
if(input1=='H')
bill=1100*input3;
Console.WriteLine(bill);
if(input1=='B')
bill=1400*input3;
Console.WriteLine(bill);
else if(input2=="Non-AC")
if(input1=='C')
bill=1000*input3;
Console.WriteLine(bill);
if(input1=='H')
bill=800*input3;
Console.WriteLine(bill);
if(input1=='B')
bill=1100*input3;
Console.WriteLine(bill);
}
}
*************************************************************************************
***********************************
14)
///string answer////
using System;
class UserProgramCode
{
public static string getString(string input1, int input2)
{
char[] ch = input1.ToCharArray();
string s=null;
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] >= '0' && ch[i] <= '9')
{
s = "-1";
break;
}
if ((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z') || ch[i] == ' ')
{
}
}
else
{
s = "-2";
break;
}
}
return s;
}
}
class Program
{
string input1;
int input2;
string output;
input1 = Console.ReadLine();
input2 = Convert.ToInt32(Console.ReadLine());
*************************************************************************************
********
15)
////ans:repeat charcter
class UserProgramCode
{
public static string repeatRemoveString(string input1,int input2)
{
// fill code here
if (input2 < 0)
return "Invalid Input";
if(input2 < 2)
return "Input value is insufficient";
if (input > 10)
return "Input value is too long";
if (len % 2 == 0)
{
else
{
for (int i = 0; i < len; i = i + 2)
{
sb.Append(abc[i]);
}
}
return snew;
}
}
*************************************************************************************
*********************************
16)
using System;
using System.Collections.Generic;
namespace myprograms
{
class UserProgramCode{
else if (item > 500 || item1 > 500 || item2 > 500)
{
l.Add(-2);
break;
}
else
{
if ((item == item1 && item == item2 && item2 == item1) &&
item % 3 == 0)
{
flag++;
l.Add(item);
j++;
}
}
}
}
}
if (flag == 0)
{
l.Add(0);
}
return l;
}
}
}
*************************************************************************************
*********
17)
add and reverse
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int AddReverse(int[] ar,int k)
{
int sum = 0,rem,rev=0;
for (int i = 0; i < ar.Length; i++)
{
if (ar[i] > k)
{
sum = sum + ar[i];
}
}
while (sum > 0)
{
rem = sum % 10;
rev = rev * 10 + rem;
sum = sum / 10;
}
return rev;
}
}
*************************************************************************************
***********************************
18) color code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class UserMainCode
{
public static void Main(string[] args)
{
string input1 = "#FF85HH";
int output1 = 0;
Regex reg = new Regex(@"^([#])+([A-F0-9]{6})+$");
if (reg.IsMatch(input1))
{
output1 = 1;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();
}
}
*************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int[] FindCommonElements(int[] ar1, int[] ar2, int[] ar3)
{
int[] c1 = new int[ar1.Length];
int k = 0;
for (int i = 0; i < ar1.Length; i++)
{
if (ar1[i] % 3 == 0)
{
c1[k] = ar1[i];
k++;
}
}
int[] c2 = new int[ar2.Length];
k = 0;
for (int i = 0; i < ar2.Length; i++)
{
if (ar2[i] % 3 == 0)
{
c2[k] = ar2[i];
k++;
}
}
int[] c3 = new int[ar3.Length];
k = 0;
for (int i = 0; i < ar3.Length; i++)
{
if (ar3[i] % 3 == 0)
{
c3[k] = ar3[i];
k++;
}
}
int[] result = new int[c1.Length];
int l = 0;
result[l] = a;
l++;
}
}
}
if (result.Length == 0)
{
result[0] = 0;
return result;
}
for (int i = 0; i < result.Length; i++)
{
for (int j = i + 1; j < result.Length; j++)
{
if (result[i] < result[j])
{
int temp = result[i];
result[i] = result[j];
result[j] = temp;
}
}
}
return result;
}
*************************************************************************************
********************************
20")
power of 2
using System;
int n = Convert.ToInt32(Console.ReadLine());
int result = UserMainCode.twoPower(n);
Console.WriteLine(result);
Console.Read();
}
}
using System;
*************************************************************************************
**********************************
21)remove vowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace gvyjv
{
class Program
{
static void Main(string[] args)
{
string i=Console.ReadLine();
string str= UserProgramCode.removeEvenVowels(i);
Console.WriteLine(str);
Console.Read();
}
}
}
using System;
using System.Text;
namespace myprograms
{
class UserProgramCode{
char[] ch = input1.ToCharArray();
int count = 1;
foreach (char i in ch)
{
if (count % 2 == 0)
{
if (!(i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'u'))
{
sb.Append(i);
count++;
}
else
{
count++;
}
}
else
{
sb.Append(i);
count++;
}
}
string output = sb.ToString();
return output;
}
}
}
*************************************************************************************
*****************************
22)vowels
using System;
using System;
using System.Text;
using System.Linq;
{
return 1;
}
else
{
return -1;
}
}
}
*************************************************************************************
******************************
23)common char
using System;
class Program
{
public static void Main()
{
String input1 = Console.ReadLine();
String input2 = Console.ReadLine();
Console.WriteLine(UserProgramCode.commonChars(input1,input2));
}
}
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class UserProgramCode{
public static int commonChars(String input1,String input2){
char[] s1a = input1.ToCharArray();
int l1 = input1.Length;
int l2 = input2.Length;
Array.Sort(s1a);
Array.Sort(s2a);
else if (!s1c.Contains(s1a[i]))
{
s1c.Add(s1a[i]);
}
}
else if (!s2c.Contains(s2a[i]))
{
s2c.Add(s2a[i]);
}
}
int c = 0;
if (i1 == i2)
{
c++;
}
}
}
return c;
}
}
*************************************************************************************
**
using System;
namespace myprograms
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
Console.WriteLine(UserProgramCode.swapPairs(input));
}
}
}
using System;
namespace myprograms
{
public class UserProgramCode
{
public static String swapPairs(string input)
{
string str = " ";
char temp;
char[] ch = input.ToCharArray();
for (int i = 0; i < input.Length-1; i++)
{
if (!char.IsLetter(ch[i]))
{
str = "Invalid Input";
goto l;
}
}
for (int i = 0; i < input.Length - 1; i++)
{
temp = ch[i];
ch[i] = ch[i + 1];
ch[i + 1] = temp;
i = i + 1;
}
l:return str;
}
}
}
}
}
}
*************************************************************************************
********************************
26)compare dashes
class UserProgramCode
{
public static int compareDashes(string input1, string input2)
{
// fill your code here
char[] s1 = input1.ToCharArray();
char[] st1 = input2.ToCharArray();
int len, count = 0;
if (s1.Length > st1.Length)
{
len = s1.Length;
}
else
{
len = st1.Length;
}
for (int i = 0; i < len; i++)
{
if (s1[i] == '-')
{
if (st1[i] != '-')
{
count++;
break;
}
}
}
if (count > 0)
return 2;
else
return 1;
*************************************************************************************
******************************************
27)validate phone no
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication26
{
class Program
{
public static void Main(string[] args)
{
string number = Console.ReadLine();
int output = UserProgramCode.validatePhoneNumber(number);
if (output == 2)
Console.WriteLine("Invalid");
else
Console.WriteLine("Valid");
Console.ReadLine();
}
}
class UserProgramCode
{
if ((input.Length) == 10)
{
for (int i = 0; i < 10; i++)
{
if (!char.IsDigit(input[i]))
{
return 2;
}
}
}
else
{
return 2;
}
return 1;
}
}
}
*************************************************************************************
*
28)COMMON CHARACTER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main()
{
String input1 = Console.ReadLine();
String input2 = Console.ReadLine();
Console.WriteLine(UserProgramCode.commonChars(input1, input2));
Console.ReadLine();
}
}
class UserProgramCode
{
public static int commonChars(String input1, String input2)
{
char[] s1a = input1.ToCharArray();
int l1 = input1.Length;
int l2 = input2.Length;
Array.Sort(s1a);
Array.Sort(s2a);
continue;
else if (!s1c.Contains(s1a[i]))
{
s1c.Add(s1a[i]);
}
}
else if (!s2c.Contains(s2a[i]))
{
s2c.Add(s2a[i]);
}
}
int c = 0;
// Console.WriteLine(c);
return c;
}
}
*************************************************************************************
*
29)common characters
COMMON CHARACTER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main()
{
String input1 = Console.ReadLine();
String input2 = Console.ReadLine();
Console.WriteLine(UserProgramCode.commonChars(input1, input2));
Console.ReadLine();
}
}
class UserProgramCode
{
public static int commonChars(String input1, String input2)
{
char[] s1a = input1.ToCharArray();
int l1 = input1.Length;
int l2 = input2.Length;
Array.Sort(s1a);
Array.Sort(s2a);
else if (!s1c.Contains(s1a[i]))
{
s1c.Add(s1a[i]);
}
}
else if (!s2c.Contains(s2a[i]))
{
s2c.Add(s2a[i]);
}
}
int c = 0;
// Console.WriteLine(c);
return c;
*************************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication12
{
class Program
{
public static void Main(string[] args)
{
int size = 0, i;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (i = 0; i < size; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(UserProgramCode.getSumOfPower(size, arr));
}
}
class UserProgramCode
{
**********************************************************************************
{
//Fill your code here
int i = 0; int j = 0;
int span = 1; int temp = 0;
for (i = 0; i < size; i++)
{
for (j = i+1; j < size; j++)
{
if (arr[i] == arr[j])
{
temp = j - i + 1;
if (temp > span)
{
span = temp;
}
}
}
}
return span;
}
***********************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NextYearDay
{
class Program
{
static void Main(string[] args)
{
string input, output;
input = Console.ReadLine();
output = UserProgramCode.nextYearDay(input);
if (output == null)
{
Console.WriteLine("Invalid date");
}
Console.WriteLine(output);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NextYearDay
{
class UserProgramCode
{
public static string nextYearDay(string date)
{
string output="";
DateTime day;
bool check = DateTime.TryParseExact(date, "dd/MM/yyyy", null,
System.Globalization.DateTimeStyles.None, out day);
if (check == true)
{
day = day.AddYears(1);
//Console.WriteLine(day);
//day = day.DayOfWeek;
output = day.DayOfWeek.ToString();
output = output.ToLower();
return output;
}
else
{
return output;
}
}
}
}
************************************************************************************
33)string encryption
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringEncryption
{
class Program
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringEncryption
{
class UserProgramCode
{
public static string encrypt(string input)
{
string output="";
for(int i=0;i<input.Length;i++)
{
if (char.IsLetter(input[i]))
{
if (i % 2 == 0)
{
if (input[i] == 'z')
{
output += 'a';
}
else
{
output += (char)(input[i] + 1);
}
}
else
{
output += input[i];
}
}
}
return output;
}
}
}
*************************************************************************************
**
34)stringManipulation
}
}
if (f == 1)
{
res = "Special character found";
}
return (res);
*************************************************************************************
**
35) gyrating
using System;
class Program
{
public static void Main( string[] args )
{
int arrSize;
arrSize = Convert.ToInt32(Console.ReadLine());
int[] input = new int[arrSize];
for(int i=0;i<arrSize;i++)
{
input[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(UserProgramCode.gyRating(input));
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode {
public static int gyRating(int[] input1)
{
int k = 0;
if (input1[i] < 0)
{
return -2;
}
}
for (int i = 0; i < input1.Length; i++)
{
int n = input1[i];
string str=n.ToString();
while (n > 0)
{
int d = n % 10;
n = n / 10;
ar[k] = d;
k++;
}
for (int y = 1; y < ar.Length; y++)
{
if (ar[y - 1] > ar[y])
{
ctr1++;
}
else if (ar[y - 1] < ar[y])
{
ctr2++;
}
}
if (ctr1 > 0 && ctr2 > 0)
{
return -1;
}
ctr1 = 0;
ctr2 = 0;
k = 0;
return 1;
}
}
************************************************************************************
36)image types
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace image
{
class Program
{
static void Main(string[] args)
{
int a = int.Parse(Console.ReadLine());
List<string> image = new List<string>();
for (int i = 0; i < a; i++)
{
image.Add(Console.ReadLine());
}
List<string> ouyp = userProgramcode.imagescount(image);
Console.WriteLine(s);
}
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace image
{
class userProgramcode
{
public static List<string> imagescount(List<string> input1)
{
int k = 0,ctr=0;
string[] ar=new string[8]{"jpeg","jfif","exif","tiff","raw","gif","bmp","png"};
List<string> outp = new List<string>();
string[] st = new string[input1.Count];
int[] sco = new int[input1.Count];
for (int j = 0; j < input1.Count; j++)
{
string[] arr = input1[j].Split('.');
if (arr.Length==2 && !st.Contains(arr[1]) && ar.Contains(arr[1]) )
{
st[k] = arr[1];
sco[k] = sco[k] + 1;
k++;
}
else if (arr.Length == 2 && st.Contains(arr[1]) && ar.Contains(arr[1]) )
{
for (int p = 0; p < st.Length; p++)
{
if (st[p] == arr[1])
{
sco[p] = sco[p] + 1;
break;
}
}
}
else
{
ctr++;
}
}
if (ctr != input1.Count)
{
int[] co = new int[k];
co = sco.ToArray();
sco = co.Distinct().ToArray();
Array.Sort(sco);
Array.Reverse(sco);
return outp;
}
*************************************************************************************
*
37)longest pallindrome
using System;
using ConsoleApplication1;
class Program
{
public static void Main( string[] args )
{
string str;
int palindromeLen;
str = Console.ReadLine();
palindromeLen = UserProgramCode.LongestPalindrome(str);
Console.WriteLine(palindromeLen);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class UserProgramCode
{
public static int LongestPalindrome(string seq)
{
int Longest = 0;
List<int> l = new List<int>();
int i = 0;
int palLen = 0;
int s = 0;
int e = 0;
while (i < seq.Length)
{
if (i > palLen && seq[i - palLen - 1] == seq[i])
{
palLen += 2;
i += 1;
continue;
}
l.Add(palLen);
Longest = Math.Max(Longest, palLen);
s = l.Count - 2;
e = s - palLen;
bool found = false;
for (int j = s; j > e; j--)
{
int d = j - e - 1;
if (l[j] == d)
{
palLen = d;
found = true;
break;
}
l.Add(Math.Min(d, l[j]));
}
if (!found)
{
palLen = 1;
i += 1;
}
}
l.Add(palLen);
Longest = Math.Max(Longest, palLen);
return Longest;
}
}
}
*************************************************************************************
**
38)triplets
using System;
class Program
{
public static void Main( string[] args )
{
int size=0,i,num;
size=Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
using System;
class UserProgramCode
{
public static int[] findTriplets(int[] input,int num)
{
}
}
*************************************************************************************
*********************************
using System;
class Program
{
public static void Main( string[] args )
{
double input1;
char input2;
input1 = Convert.ToDouble(Console.ReadLine());
input2 = Convert.ToChar(Console.ReadLine());
int value = UserProgramCode.calculateBillAmount(input1,input2);
if(value == -2)
Console.Write("No Items");
else if(value == -1)
Console.Write("Negative Values");
else
Console.Write(value);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static int calculateBillAmount(double input1,char input2)
{
double dp;
double na=0;
char[] ch = new char[] { 't', 'm'};
if (input1 < 0)
{
return -1;
}
if ((input2 !='t') && input2 != 'm')
{
return -2;
}
return (int)na;
}
else if(input2 == 'm')
{
dp =(0.1 * input1);
na=(input1 - dp);
return (int)na;
}
else
{
Console.WriteLine("not valid");
}
}
else if (input1 >= 25001 && input1 <= 5000)
{
if (input2 == 't')
{
dp = (0.1 * input1);
na = (input1 - dp);
return (int)na;
}
else if (input2 == 'm')
{
dp = (0.2 * input1);
na = (input1 - dp);
return (int)na;
}
else
{
Console.WriteLine("not valid");
}
}
if (input1 >= 50000)
{
if (input2 == 't')
{
dp = (0.15 * input1);
na = (input1 - dp);
return (int)na;
}
else if (input2 == 'm')
{
dp = (0.3 * input1);
na = (input1 - dp);
return (int)na;
}
else
{
Console.WriteLine("not valid");
}
}
return (int)na;
}
}
*************************************************************************************
*************************************
using System;
class Program
{
public static void Main( string[] args )
{
string date1=Console.ReadLine();
string date2=Console.ReadLine();
int result = UserProgramCode.getDateDifference(date1,date2);
Console.WriteLine(result);
}
}
using System;
class UserProgramCode
{
public static int getDateDifference(string inputDate1,string inputDate2)
{
DateTime d1 = Convert.ToDateTime(inputDate1);
DateTime d2 = Convert.ToDateTime(inputDate2);
TimeSpan d3 =(d2-d1);
double n = d3.TotalDays;
return (int)n;
*************************************************************************************
41)class divison
using System;
class Program
{
public static void Main( string[] args )
{
int m1=Convert.ToInt32(Console.ReadLine());
int m2=Convert.ToInt32(Console.ReadLine());
int m3=Convert.ToInt32(Console.ReadLine());
int m4=Convert.ToInt32(Console.ReadLine());
int m5=Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.calculateResult(m1,m2,m3,m4,m5));
}
}
using System;
class UserProgramCode
{
public static String calculateResult(int m1,int m2,int m3,int m4,int m5)
{
double n = 0;
double p = 0;
n = (m1 + m2 + m3 + m4 + m5);
p = (n) / 5;
if (p >= 60)
{
return("first class");
}
else if (p >= 50 && p <= 59)
{
return ("second class");
}
else if (p >= 40 && p <= 49)
{
return ("third class");
}
else
{
return (" failed");
}
}
}
**********************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
public static void Main(string[] args)
{
String word=Console.ReadLine();
int result=UserProgramCode.checkCharacters(word);
if(result==1)
{
Console.WriteLine("The characters are same");
}
else
{
Console.WriteLine("The characters are different");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int checkCharacters(String word)
{
int i = 0;
int l;
char[] ch = word.ToCharArray();
l=ch.Length;
if (ch[0] == ch[l - 1])
{
return 1;
}
else
{
return 0;
}
}
}
}
}
*************************************************************************************
*************************************************************************************
****
43)square of digits
using System;
class Program
{
public static void Main (string[] args)
{
int n;
n=int.Parse(Console.ReadLine()) ;
Console.WriteLine (UserProgramCode.sumSquare(n));
}
}
using System;
}
}
*************************************************************************************
**
44)maxmin sum of 3 input
using System;
class Program
{
public static void Main( string[] args )
{
int input1,input2,input3,output;
input1 = Convert.ToInt32(Console.ReadLine());
input2 = Convert.ToInt32(Console.ReadLine());
input3 = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.sumMaxMin(input1,input2,input3);
Console.WriteLine(output);
}
}
using System;
class UserProgramCode {
public static int sumMaxMin(int input1,int input2,int input3)
{
int max, min;
max = input1;
min = input2;
int sum = 0;
if (input1 == input2 || input2 == input3 || input3 == input1)
{
return -2;
}
else if (input1 < 0 || input2 < 0 || input3 < 0)
{
return -1;
}
}
}
*************************************************************************************
****
using System;
class Program
{
public static void Main( string[] args )
{
String str=Console.ReadLine();
Console.WriteLine(UserProgramCode.negativeString(str));
}
}
using System;
using System.Text;
class UserProgramCode
{
public static string negativeString (string str)
{
System.Text.StringBuilder b2 = new StringBuilder();
string[] st = str.Split(' ');
// Note:
// You must assign the result of Replace to a new string.
foreach (string sb in st)
{
if (sb == "is")
{
b2.Append(sb.Replace(sb, "is not "));
}
else
{
b2.Append(sb + " ");
}
}
string sr = b2.ToString();
return sr;
}
}
*************************************************************************************
***
46) digit sum
using System;
class Program
{
public static void Main( string[] args )
{
int input,output;
input = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.getDigitSum(input);
Console.WriteLine(output);
}
}
class UserProgramCode {
public static int getDigitSum(int input)
{
int r, sum = 0, r1 = 0, sum2 = 0;
}
else
{
return(sum);
}
}
}
*************************************************************************************
***
47)ADD DAYS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
class Program
{
public static void Main(string[] args)
{
string inputDate = Console.ReadLine();
int day = Convert.ToInt32(Console.ReadLine());
string output = UserProgramCode.addDays(inputDate, day);
if (output.Equals("-1"))
Console.WriteLine("n value is negative");
else if (output.Equals("-2"))
Console.WriteLine("Invalid date format");
else
Console.WriteLine(output);
}
}
class UserProgramCode
{
public static string addDays(string date, int day)
{
//Fill your code here
DateTime dt;
string output;
if (day < 0)
{
return "-1";
}
else
{
bool res = DateTime.TryParseExact(date, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt = dt.AddDays(day);
output = dt.ToString("MM/dd/yyyy");
return output;
}
else
{
return "-2";
}
// return output;
}
}
*************************************************************************************
*********************************************
int l = str.Length;
string sree="";
char[] temp = str.ToCharArray();
for (int i = l-1; i >=0; i--)
{
sree = string.Concat(sree, temp[i]);
if (i != 0)
{
*************************************************************************************
*************************************
using System.Collections.Generic;
using System;
class UserProgramCode
{
public static string extractMax(string str, string sym)
{
// fill your code here
char dem = Convert.ToChar(sym);
string[] input = str.Split(dem);
int max = 0;
List<string> l = new List<string>();
l.Add("0");
foreach (var i in input)
{
if (max < i.Length)
{
max = i.Length;
l[0] = i;
}
}
return l[0];
}
}
*************************************************************************************
*************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace my_project
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(dt);
Console.WriteLine(dt2);
double days = (dt2 - dt).TotalDays;
days = Math.Abs(days);
Console.WriteLine(days);
51)check batch
using System;
class Program
{
public static void Main( string[] args )
{
string input1,output;
input1 = Console.ReadLine();
output = UserProgramCode.checkBatch(input1);
Console.WriteLine(output);
}
}
using System;
class UserProgramCode {
public static string checkBatch(string input1)
{
// fill code here
string city=input1.Substring(0,3);
string year = input1.Substring(3, 2);
string stream =input1.Substring(5, 2);
string batch=input1.Substring(7, 3);
string output = "";
int count = 0,temp=0;
if (city == "CHN" || city == "CBE" || city == "KOC" || city == "PUN" || city ==
"BGL" || city == "HYD" || city == "KOL")
{
switch (city)
{
case "CHN":
city = "Chennai";
break;
case "CBE":
city="Coimbatore";
break;
case "KOC":
city = "Kochi";
break;
case "PUN":
city = "Pune";
break;
case "BGL":
city = "Bangalore";
break;
case "HYD":
city = "Hyderabad";
break;
case "KOL":
city = "Kolkata";
break;
}
if (Char.IsDigit(i))
{
temp++;
}
}
if (count != year.Length || temp != batch.Length)
{
return "-2";
}
if (!stream.Equals("DN"))
{
return "-3";
}
}
else
{
return "-1";
}
output = "DotNet batch " + batch + " has joined in 20" + year + " year and is
at " + city + " Location.";
return output;
}
}
*************************************************************************************
**************************************
52)extract max
using System;
class Program
{
public static void Main( string[] args )
{
string str,sym;
str = Console.ReadLine();
sym = Console.ReadLine();
string output = UserProgramCode.extractMax(str,sym);
Console.WriteLine(output);
}
}
using System.Collections.Generic;
using System;
class UserProgramCode
{
public static string extractMax(string str, string sym)
{
// fill your code here
char dem = Convert.ToChar(sym);
string[] input = str.Split(dem);
int max = 0;
List<string> l = new List<string>();
l.Add("0");
foreach (var i in input)
{
if (max < i.Length)
{
max = i.Length;
l[0] = i;
}
else if (max == i.Length)
{
char i1 = Convert.ToChar(l[0].Substring(0,1));
char i2 = Convert.ToChar(i.Substring(0, 1));
if (i1 > i2)
{
max = i.Length;
l[0] = i;
}
}
return l[0];
}
}
*************************************************************************************
**************************************
53)arrange after cubing
using System;
class Program
{
public static void Main( string[] args )
{
int n=Convert.ToInt32(Console.ReadLine());
int[] value=new int[n];
for(int i=0;i<n;i++)
{
value[i]=Convert.ToInt32(Console.ReadLine());
}
int[] output = UserProgramCode.arrangeAfterCubing(value);
for(int i=0;i<output.Length;i++)
{
Console.Write(output[i]+"\n");
}
}
}
using System;
using System.Text;
using System.Collections;
class UserProgramCode
{
public static int[] arrangeAfterCubing(int[] input1)
{
int i=0,ch,c;
int ch1=0,flag=1;
int s = input1.Length;
ArrayList sb = new ArrayList();
int[] op1 = new int[s];
for (i = 0; i < s; i++)
{
if (input1[i] < 0)
{
flag = 0;
ch1 = input1[i] * input1[i];
input1[i] = ch1;
}
}
if (flag == 0)
{
for (i = 0; i < s; i++)
{
op1[i] = input1[i]; ;
}
return op1;
}
else
{
for (i = 0; i < s - 1; i++)
{
ch = input1[i] * input1[i];
if (input1[i + 1] == ch)
{
c = input1[i] * input1[i] * input1[i];
if (i == 0)
{
sb.Add(input1[i]);
sb.Add(c);
sb.Add(input1[i + 1]);
}
else
{
sb.Add(c);
sb.Add(input1[i + 1]);
}
}
else
{
if (i == 0)
{
sb.Add(input1[i]);
sb.Add(input1[i + 1]);
}
else
{
sb.Add(input1[i + 1]);
}
}
}
int len = sb.Count;
int[] op = new int[len];
i = 0;
foreach (int n in sb)
{
op[i] = n;
i++;
}
return op;
}
}
}
*************************************************************************************
**********************************
54)remove duplicates
using System;
class Program
{
public static void Main(string[] args)
{
string input;
input = Console.ReadLine();
string outputStr = UserProgramCode.removeDuplicates(input);
Console.WriteLine(outputStr);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static string removeDuplicates(string input1)
{
char[] ch = input1.ToCharArray();
char[] res = ch.Distinct().ToArray();
}
}
*************************************************************************************
********************************find 55)find occurence
***
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NumberOfOccurences
{
class Program
{
static void Main(string[] args)
{
string input1;
char input2;
input1 = Console.ReadLine();
input2 = Convert.ToChar(Console.ReadLine());
int value = UserProgramCode.findOccurence(input1, input2);
if (value == -1)
Console.WriteLine("Invalid Input");
else
Console.WriteLine(value);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NumberOfOccurences
{
class UserProgramCode
{
public static int findOccurence(string input1,char input2)
{
// fill your code here
int output=0;
string ip1 = input1.ToLower();
char ip2 = char.ToLower(input2);
char[] ch=sr.ToCharArray();
foreach (char ch1 in ch)
{
if (!char.IsLetter(ch1))
{ return -1; }
else
{
if (ch1 == ip2)
{ output++; }
}
}
return output;
}
}
}
*************************************************************************************
************************************
using System;
class Program
{
public static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
int result = UserProgramCode.findLargestDigit(num);
if (result == -1)
Console.WriteLine("Negative Number");
else
Console.WriteLine(result);
Console.ReadKey();
}
}
using System;
class UserProgramCode
{
public static int findLargestDigit(int num)
{
int temp=0,rem=0,output=0;
temp = num;
if (temp < 0)
{
return -1;
}
else
{
while (temp > 0)
{
rem = temp % 10;
if(rem>=output)
output = rem;
temp = temp / 10;
}
return output;
}
}
*************************************************************************************
*******************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
static void Main(string[] args)
{
Console.WriteLine(UserProgramCode.formNewWord(word, n));
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
*************************************************************************************
***********************************
58)Remove Substring
---------------------------------------------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Reverse_Substring
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int strt = int.Parse(Console.ReadLine());
int len = int.Parse(Console.ReadLine());
string ans = UserProgramCode.reverseSubstring(s, strt,len);
Console.WriteLine(ans);
Console.Read();
}
}
class UserProgramCode
{
public static string reverseSubstring(string s, int a, int b)
{
string op = "";
string str = "";
char[] ch = s.ToCharArray();
Array.Reverse(ch);
foreach (var item in ch)
{
op = op + item;
}
str = op.ToString();
op = str.Substring(a, b);
return op;
}
}
}
*************************************************************************************
*********************************
59)NextYearDay
----------------------------------------------------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NextYearDay
{
class Program
{
static void Main(string[] args)
{
string d = Console.ReadLine();
string dt = UserCodeProgram.nextYearDay(d);
Console.WriteLine(dt);
Console.ReadLine();
}
}
class UserCodeProgram
{
public static string nextYearDay(string d)
{
DateTime dt;
// int x,o;
string op;
bool res = DateTime.TryParseExact(d, "dd/mm/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt = dt.AddYears(1);
op = dt.DayOfWeek.ToString();
//if (dt.Year % 4 == 0 && dt.Year % 100 != 0)
//
x = 1;
x = 1;
//else
//
x = 0;
//if (x == 1)
//{
//
//dt = dt.AddDays(366);
//
o = (Convert.ToInt32(dt.DayOfWeek)) - 1;
//
op = o.ToString();
//}
//else
//{
//
op = dt.DayOfWeek.ToString();
//}
return op;
}
else
return "invalid";
}
}
}
*************************************************************************************
*****************************************
60)Largest_String
------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace largest_string
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
List<string> s = new List<string>();
for (int i = 0; i < n; i++)
{
s.Add(Console.ReadLine());
}
char a = Convert.ToChar(Console.ReadLine());
string ans = UserCodeProgram.getLongestString(s, a);
Console.WriteLine(ans);
Console.ReadKey();
}
}
class UserCodeProgram
{
public static string getLongestString(List<string> s, char a)
{
// int n = s[0].Length;
int c = 0;
string op = "";
string[] s1 = new string[10];
if (s.Count != 0)
{
for (int i = 0; i < s.Count; i++)
{
s[i] = s[i].ToLower();
if (Convert.ToChar(s[i].Substring(0, 1)) == a)
{
s1[c] = s[i];
c++;
}
}
int n = s1[0].Length;
op = s1[0];
for (int m = 0; m < c; m++)
{
if (n < s1[m].Length)
{
n = s1[m].Length;
op = s1[m];
}
}
return op;
}
else
op = "No elements found";
return op;
}
}
}
*************************************************************************************
************************************
61)add days
using System;
class Program
{
public static void Main(string[] args)
{
string inputDate = Console.ReadLine();
int day = Convert.ToInt32(Console.ReadLine());
string output = UserProgramCode.addDays(inputDate, day);
if (output.Equals("-1"))
Console.WriteLine("n value is negative");
else if (output.Equals("-2"))
Console.WriteLine("Invalid date format");
else
Console.WriteLine(output);
}
}
using System;
using System.Globalization;
class UserProgramCode
{
public static string addDays(string date, int day)
{
DateTime dt;
string output;
if (day < 0)
{
return "-1";
}
else
{
bool res = DateTime.TryParseExact(date, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt = dt.AddDays(day);
output = dt.ToString("MM/dd/yyyy");
return output;
}
else
{
return "-2";
}
// return output;
}
}
*************************************************************************************
*********************************
62)print capitalized
using System;
class Program
{
public static void Main()
{
Console.WriteLine(UserProgramCode.printCapitalized(Console.ReadLine()));
}
}
using System;
using System.Linq;
class UserProgramCode
{
public static String printCapitalized(String input1)
{
// string input = "Features Of JAVA2 ";
input1 = input1.ToLower();
char a;
int count = 0;
string[] str = input1.Split(' ');
string output = "";
foreach (string s in str)
{
count = 0;
foreach (char ch in s)
{
a = ch;
if (count == 0)
{
if (char.IsLetter(ch))
{
a = (char)((int)ch - 32);
}
}
output = output + a;
count++;
}
output = output + " ";
}
return output;
}
}
*************************************************************************************
**********************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication12
{
class Program
{
public static void main(string[] args)
{
int size = 0, i;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (i = 0; i < size; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(UserProgramCode.getSumOfPower(size, arr));
Console.ReadLine();
}
}
class UserProgramCode
{
public static int getSumOfPower(int size, int[] arr)
{
int sum = 0;
for (int i = 0; i < s; i++)
{
sum = sum + Convert.ToInt32(Math.Pow(arr[i], i));
}
return sum;
}
}
}
64)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication65
{
class Program
{
static void Main(string[] args)
{
int size;
size = Convert.ToInt32(Console.ReadLine());
string[] arr = new string[size];
List<string> list = new List<string>();
for (int i = 0; i < size; i++)
{
arr[i] = Console.ReadLine();
}
list = UserProgramCode.removeDuplicateDate(arr);
for (int i = 0; i < list.Count; i++)
{
Console.WriteLine(list[i]);
} Console.ReadLine();
}
}
class UserProgramCode
{
public static List<string> removeDuplicateDate(string[] arr)
{
// fill your code here
return list1;
}
}
}
-----------==================================================
===============================================
65).Array Median
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication67
{
class Program
{
static void Main(string[] args)
{
int a = Convert.ToInt32(Console.ReadLine());
int[] ar = new int[a];
a1 = Math.Ceiling(Median);
a = Convert.ToInt32(a1);
return a;
}
}
}
==================================================
==================================================
==============================================
66).Calculate Frequency
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Class16
{
public static int output;
int i = 0;
int count = 0;
while ((i = str2.IndexOf(str1, i)) != -1)
{
i += str1.Length;
count++;
}
return count;
}
}
if (x > 0)
{
Console.WriteLine("output: 2");
}
Console.ReadLine();
}
}
}
==================================================
==================================================
===============================
67).Add Years
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace AddYears
{
class Program
{
public static void Main(string[] args)
{
string inputDate = Console.ReadLine();
int day = Convert.ToInt32(Console.ReadLine());
string output = UserProgramCode.addYears(inputDate, day);
if (output.Equals("-1"))
Console.WriteLine("Invalid Input");
else if (output.Equals("-2"))
Console.WriteLine("Invalid date format");
else
Console.WriteLine(output);
Console.ReadLine();
}
}
class UserProgramCode
{
public static string addYears(string date, int day)
{
// fill your code here
DateTime dt;
string output;
if (day < 0)
{
return "-1";
}
else
{
bool res = DateTime.TryParseExact(date, "dd/MM/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt = dt.AddDays(day);
output = dt.ToString("dd/MM/yyyy");
return output;
}
else
{
return "-2";
}
}
}
}
}
==================================================
==================================================
==================================================
======
68). Get String
\
strin 1
Input:
cognizant
3
output:
cognizantantantant
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication86
{
class Program
{
static void Main(string[] args)
{
string input1;
int input2;
string output;
input1 = Console.ReadLine();
input2 = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.getString(input1, input2);
Console.WriteLine(output);
Console.ReadLine();
}
class UserProgramCode
{
public static string getString(string input1, int input2)
{
char[] ch = input1.ToCharArray();
string s = "";
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] >= '0' && ch[i] <= '9')
{
s = "-1";
break;
}
if ((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z') || ch[i] ==
' ')
{
//q=input1.Substring(m,input1.Length-1);
q = input1.Substring(m, input2);
string h = null;
string n = h + input1;
for (int w = 0; w < input2; w++)
n = n + q;
// string n = h + input1;
s = n;
}
}
else
{
s = "-2";
break;
}
}
return s;
}
}
}
==================================================
==================================================
==================================================
==
69).
Input:
Battle
Final
2
output:
The Charater is a
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication87
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
string str1 = Console.ReadLine();
char[] ch = str.ToCharArray();
char[] ch1 = str1.ToCharArray();
int n=int.Parse(Console.ReadLine());
// for (int i = 0; i < str.Length; i++)
// {
char c=ch[n-1];
//Console.WriteLine(c);
char c1=ch1[str1.Length-n];
//Console.WriteLine(c1);
if(c1==c)
Console.WriteLine("The Character is {0}",c);
Console.ReadLine();
}
}
}
==================================================
==================================================
==================================================
=========
70)even odd position
Input:
price
4
output
piepiepiepie
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
class Program
{
public static void Main(string[] args)
{
int input2;
string input1, output;
input1 = Console.ReadLine();
input2 = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.repeatRemoveString(input1, input2);
Console.WriteLine(output);
Console.ReadLine();
}
}
class UserProgramCode
{
public static string repeatRemoveString(string input1, int input2)
{
// fill code here
if (input2 < 0)
return "Invalid Input";
if (input2 < 2)
return "Input value is insufficient";
if (input2 > 10)
return "Input value is too long";
if (len % 2 == 0)
{
for (int i = 1; i < len; i = i + 2)
{
sb.Append(abc[i]);
}
}
else
{
for (int i = 0; i < len; i = i + 2)
{
sb.Append(abc[i]);
}
}
return snew;
}
}
*************************************************************************************
***********************************
71. adddays
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace add_days
{
class UserProgramCode
{
public static string addDays(string date, int add)
{
DateTime newDate;
string output;
if(add <0)
{
return "-1";
}
else if(DateTime.TryParseExact(date, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out newDate) == false)
{
return "-2";
}
else
{
newDate = newDate.AddDays(add);
output = newDate.ToString("MM/dd/yyyy");
return output;
}
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------
72. addnoncommon
using System;
class UserProgramCode
{
public static int validateNumber(int[] arr1,int size1,int[] arr2,int size2)
{
// fill your code here
int check1=0, check2=0, flag=0,sum=0;
for (int i = 0; i < arr1.Length;i++ )
{
if (arr1[i] < 0)
{
check1 = -1;
}
}
}
}
if(flag==0)
{
sum = sum + arr1[i];
}
}
for (int i = 0; i < size2; i++)
{
flag = 0;
for (int j = 0; j < size1; j++)
{
if (arr2[i] == arr1[j])
{
flag = 1;
}
}
if (flag == 0)
{
sum = sum + arr2[i];
}
return sum;
}
}
}
-----------------------------------73. division
using System;
class UserProgramCode
{
public static String calculateResult(int m1, int m2, int m3, int m4, int m5)
{
//Fill your code here
float c;
c = (float)(m1 + m2 + m3 + m4 + m5);
float d;
d = (float)(c / 5);
//d = d * (100);
if (d > 60)
return "First Class";
else if (d >= 50 && d <= 59)
return "Second Class";
else if (d >= 40 && d <= 49)
return "Third Class";
else
return "Failed";
}
}
using System;
class UserProgramCode
{
public static int calculateCost(int cost, char fltype, char dctype)
{
if (dctype != 'S' && dctype != 'C')
return (-3);
if (fltype != 'N' && fltype != 'E')
return (-2);
int value = 0;
if (dctype == 'S')
value = value + 15000;
if (dctype == 'C')
value = value + 25000;
if (fltype == 'N')
value = value + (cost * 400);
if (fltype == 'E')
value = value + (cost * 700);
if (value < 20000)
return -1;
else
return (value);
}
}
----------------------------------------------------------
75. capital
using System;
using System.Linq;
class UserProgramCode
{
public static String printCapitalized(String input1)
{
// string input = "Features Of JAVA2 ";
input1 = input1.ToLower();
char a;
int count = 0;
string[] str = input1.Split(' ');
string output = "";
foreach (string s in str)
{
count = 0;
foreach (char ch in s)
{
a = ch;
if (count == 0)
{
if (char.IsLetter(ch))
{
a = (char)((int)ch - 32);
}
}
output = output + a;
count++;
}
output = output + " ";
}
return output;
}
}
-----------------------------------------------76. checksupply
using System;
class UserProgramCode
{
public static string CheckSupply(int stock, int quantity, bool credit)
{
//Fill your code here
String s="";
if ((quantity <= stock) && (credit == true))
{
s = "Supply";
}
else if (credit == false)
{
s = "Cannot Supply";
}
else if ((quantity > stock) && (credit == true) && (stock != 0))
{
s = "Balance Will Be Shipped Later";
}
else if ((credit == true) && (stock == 0))
{
s = "Out Of Stock";
}
return s;
}
}
--------------------------------------------------------77. checkcharacter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int checkCharacters(String word)
{
char[] ch = word.ToCharArray();
if (ch[0] == ch[word.Length - 1])
{
return 1;
}
else
return 0;
}
}
---------------------------------------------------------
78. checksum
using System;
class UserProgramCode
{
public static int checkSum(int number)
{
int rem,sum=0;
while(number>0)
{
rem=number%10;
if(rem%2!=0)
{
sum=sum+rem;
}
number=number/10;
}
if(sum%2==0)
return -1;
else
return 1;
}
}
--------------------------------------------------------------
79. commonchar
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class UserProgramCode
{
public static int commonChars(String input1, String input2)
{
char[] s1a = input1.ToCharArray();
int l1 = input1.Length;
int l2 = input2.Length;
Array.Sort(s1a);
Array.Sort(s2a);
else if (!s1c.Contains(s1a[i]))
{
s1c.Add(s1a[i]);
}
}
else if (!s2c.Contains(s2a[i]))
{
s2c.Add(s2a[i]);
}
}
int c = 0;
if (i1 == i2)
{
c++;
}
}
}
// Console.WriteLine(C);
return c;
}
}
------------------------------------------80. commonelement
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ebox
{
class UserProgramCode
{
static public List<int> FindCommonElements(List<int> arr1, List<int> arr2,
List<int> arr3)
{
List<int> l=new List<int>();
int flag=0,j=0;
foreach (int item in arr1)
{
foreach (var item1 in arr2)
{
foreach (var item2 in arr3)
{
if (item < 0 || item1 < 0 || item2 < 0)
{
l.Add(-1);
break;
}
else if (item > 500 || item1 > 500 || item2 > 500)
{
l.Add(-2);
break;
}
else
{
if ((item == item1 && item == item2 && item2 == item1) &&
item % 3 == 0)
{
flag++;
l.Add(item);
j++;
}
}
}
}
}
if (flag == 0)
{
l.Add( 0 );
}
return l;
}
-------------------------------------------------------------------------------------81. convertformat
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
char[] c1 = a[0].ToCharArray();
char[] c2 = a[1].ToCharArray();
char[] c3 = a[2].ToCharArray();
sb.Append('-');
sb.Append(c3[i]);
}
else
{
sb.Append(c3[i]);
}
}
// Console.WriteLine(output);
return output;
}
else
{
return " ";
}
}
}
-------------------------------------------------82. convertromantodecimal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int convertRomanToDecimal(String s)
{
//fill your code here
char[] ch = s.ToCharArray();
int flag = 0, c = 0, sum = 0;
int[] a = new int[20];
foreach (char i in ch)
{
//Console.Write(I);
if (!(i == 'I' || i == 'V' || i == 'X' || i == 'L' || i == 'C' || i == 'D' || i == 'M'))
{
flag = 1;
}
}
if (flag == 1)
{
return -1;
}
else
{
foreach (char i in ch)
{
switch (I)
{
case 'I':
a[c] = 1;
c++;
break;
case 'V':
a[c] = 5;
c++;
break;
case 'X':
a[c] = 10;
c++;
break;
case 'L':
a[c] = 50;
c++;
break;
case 'C':
a[c] = 100;
c++;
break;
case 'D':
a[c] = 500;
c++;
break;
case 'M':
a[c] = 1000;
c++;
break;
}
}
}
for (int i = 0; i < c; i++)
{
if (a[i] >= a[i + 1])
{
sum = sum + a[i];
}
else
{
sum = sum - a[i];
}
}
return sum;
//Console.WriteLine(sum);
//Console.ReadKey();
}
------------------------------------83. checkpallindrome
using System;
using System.Globalization;
using System.Text;
char[] a = str.ToCharArray();
char[] b = str.ToCharArray();
Array.Reverse(b);
string stra = new string(a);
string strb = new string(b);
if (stra.Equals(strb))
{
char[] d = str.ToCharArray();
foreach (char item in stra)
{
if (item == 'a' || item == 'A' || item == 'e' || item == 'E' || item == 'i' ||
item == 'I' || item == 'o' || item == 'O' || item == 'u' || item == 'U')
{
}
}
-------------------------------------------
84. countnumberofchar
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int countCharacters(String s)
{
int n=0;
foreach (var a in s)
{
n++;
}
return n;
}
-------------------------------------85. countbetweennumbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
int count = 0;
for (i = 0; i < inputElements.Length; i++)
{
if (inputElements[i] < 0 ||n1<0||n2<0)
{
flag = 1;
}
}
if (flag == 1)
{
return -1;
}
else
{
count++;
}
}
return count;
}
}
}
-------------------------------------------------------------
86. countchar
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int countCharacters(String s)
{
char[] ch = s.ToCharArray();
int l = ch.Length;
return l;
}
---------------------------------------------------------------------87. countdigit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace count
{
class UserProgramCode
{
public static int countDigits(String input1)
{
//Fill Your Code Here
int count = 0,output=0;
int count1 = 0;
char[] ch = input1.ToCharArray();
foreach (char c in ch)
{
if (char.IsLetterOrDigit(C) || char.IsWhiteSpace(C))
{
count++;
}
}
if (count == ch.Length)
{
foreach (char c1 in ch)
{
if (char.IsDigit(c1))
{
count1++;
}
}
output = count1;
}
else
{
output = -1;
}
return output;
}
-----------------------------88. countoddinteger
using System;
namespace myprograms
{
class UserProgramCode
{
public static int countOddIntegers(int[] array)
{
int i, count = 0;
for (i = 0; i < array.Length; i++)
{
if (array[i] < 0)
{
return -1;
}
}
}
}
return (count);
}
}
}
-----------------------------------89. daysofweek
using System;
using System.Globalization;
using System;
class UserProgramCode
{
public static int findGiftVoucher(int dice1, int dice2)
{
int result;
if ((dice1 < 1 || dice1 > 6) || (dice2 < 1 || dice2 > 6))
{
result = -1;
return result;
}
else
{
int c = dice1 + dice2;
if (c == 2 || c == 3 || c == 6 || c == 11)
{
result = 1000;
}
else if (c == 4 || c == 7 || c == 10)
{
result = 3000;
}
else if (c == 5 || c == 8 || c == 9 || c == 12)
{
result = 5000;
else
{
result = -1;
return result;
}
return result;
}
}
}
--------------------------------------------------------------91. getbigdifference
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetBigDiff
{
class UserProgramCode
{
public static int getBigDiff(int[] input)
{
int max, min, size, output;
size = input.Length;
max = input[0];
min = input[0];
for (int i = 1; i < size; i++)
{
if (max < input[i])
{
max = input[i];
}
if (min > input[i])
{
min = input[i];
}
}
}
}
}
--------------------------------------------------------------92.efficiencychecker
using System;
namespace myprograms
{
class UserProgramCode
{
public static String EfficiencyChecker(float input1)
{
string output1;
}
}
------------------------------------------------------------------------------93. encryptstring
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace myprograms
{
public class UserProgramCode
{
public static String encrypt(string input1)
{
string a2 = Console.ReadLine().ToString();
char[] a1 = a2.ToCharArray();
char[] b = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z' };
StringBuilder sb = new StringBuilder();
int x = 0;
for (int i = 0; i < a1.Length; i++)
{
if (i % 2 == 0)
{
}
else
sb.Append(a2[i]);
}
string q = sb.ToString();
Console.WriteLine(q);
return q;
}
}
}
--------------------------------------94. findlargestdigit
using System;
class UserProgramCode
{
public static int findLargestDigit(int num)
{
int temp=0,rem=0,output=0;
temp = num;
if (temp < 0)
{
return -1;
}
else
{
while (temp > 0)
{
rem = temp % 10;
if(rem>=output)
output = rem;
temp = temp / 10;
}
}
return output;
}
}
---------------------------95. findlowestdigit
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
else
{
for (i = 1; i < l; i++)
{
if (array[i] < small)
small = array[i];
}
outpt = small;
}
return outpt;
}
}
----------------------------96. findresult
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
}
}
-------------------------------------------97. formnewword
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
}
}
---------------------------------------------------------98. getcount
using System;
class UserProgramCode
{
public static int GetCount(int size,string[] arr,char ch)
{
int count=0;
{
foreach (char i in item)
{
if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z'))
{
}
else
{
return -2;
}
}
string item1=item.ToLower();
char[] a=item1.ToCharArray();
if(ch>='A' && ch<='Z')
ch=(char)((int)ch+32);
if(ch>='a' && ch<='z')
{
if(a[0]==ch)
count++;
}
else
return -2;
}
if(count>0)
return count;
if (count == 0)
return -1;
return 0;
}
}
-----------------------------------------------------------------99. stringmanipulation
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class UserProgramCode
{
using System;
class UserProgramCode
{
public static int getMaxSpan(int size, int[] arr)
{
int ind2=0, c=0;
if (size == 1)
{
return 1;
}
if (i == 0 && c != 0)
return ind2 - i;
}
return 0;
}
}
----------------------------------------------------101. insuranceguide
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static void InsuranceGuide(char health, int age, char gender, char location)
{
//Fill your code here
if (health == 'E' && age >= 25 && age <= 35 && location == 'C' && gender
== 'M')
{
Console.WriteLine(4);
Console.WriteLine(200000);
}
else if (health == 'E' && age >= 25 && age <= 35 && location == 'C' &&
gender == 'F')
{
Console.WriteLine(3);
Console.WriteLine(100000);
}
else if (health == 'P' && age >= 25 && age <= 35 && location == 'V' &&
gender == 'M')
{
Console.WriteLine(6);
Console.WriteLine(10000);
}
else if(age>=60)
Console.WriteLine("Age limit Exceeded");
else
Console.WriteLine("The person cannot be insured");
}
}
---------------------------------------------------------------102. ipvalidator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int ipValidator(String input)
{
//Fill your code here
string str = input;
int status = 0;
for (int i = 0; i < str.Length; i++)
{
if (!(char.IsDigit(str[i]) || str[i] == '.'))
{
status = 1;
break;
}
}
string[] sarr = str.Split('.');
if (sarr.Length != 4)
{
status = 1;
}
if (status != 1)
{
if (!(int.Parse(sarr[0]) >= 1 && int.Parse(sarr[0]) <= 255))
{
status = 1;
}
}
if (status != 1)
{
for (int j = 1; j < sarr.Length; j++)
{
if (!(int.Parse(sarr[j]) >= 0 && int.Parse(sarr[j]) <= 255))
{
status = 1;
break;
}
}
}
if (status == 1)
return 0;
else
return 1 ;
}
-------------------------------------------------------------103. longestwordlength
using System;
namespace myprograms
{
class UserProgramCode
{
public static int longestWordLength(String[] array)
{
}
}
}
-------------------------------------------------------------------------------
104. lowestelementinstring
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program2
{
class UserProgramCode
{
public static int findLowest(int[] array)
{
int res=0,low=array[0];
foreach (var a in array)
{
if (a < 0)
{
res=-1;
return res;
}
else if(a<low)
{
res = a;
}
}
return res;
}
}
}
-----------------------------------------------------------------------------
105. matchingstring(sortstring)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static List<string> SortStrings(int size, List<string> li, char ch)
{
List<string> res = new List<string>();
int c = 0;
if (c == 0 )
{
res.Add("-1");
return res;
}
else
{
foreach (var item in li)
{
if (item.Contains(ch))
{
res.Add(item + "_" + c);
}
}
}
return res;
}
------------------------------------------------------------------
106. negativestring
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static string negativeString(string str)
{
StringBuilder b2 = new StringBuilder();
string[] st = str.Split(' ');
// Note:
// You must assign the result of Replace to a new string.
foreach (string sb in st)
{
if (sb == "is")
{
b2.Append(sb.Replace(sb, "is not "));
}
else
{
b2.Append(sb+ " ");
}
}
string sr=b2.ToString();
return sr;
}
}
-------------------------------------------------------------------------------
107. removetens
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int[] removeTens(int[] arr, int size)
{
int count = 0, k = 0;
int[] output = new int[size];
return output;
}
}
------------------------------------------------------------------------------------------
108. repeatedint
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static void findRepeatedIntegers(int size,int[] arr)
{
//Fill your code here
int f = 0,count=0;
for (int i1 = 0; i1 < size;i1++ )
{
if(arr[i1]<0)
{
f = 1;
}
}
if (f == 1)
Console.WriteLine("Array contains negative numbers");
else if (size == count)
{
Console.WriteLine("No repeated numbers");
}
else
{
foreach (var result in i)
Console.WriteLine(result);
}
}
}
---------------------------------------------------------------------------------------
109. reverseSubstring
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
sb.Append(ch[j]);
j++;
i++;
}
String str1 = sb.ToString();
return str1;
}
}
----------------------------------------------------------------------------------------
110. sortafteranumberselect(GetElements)
using System;
using System.Collections.Generic;
namespace myprograms
{
class UserProgramCode
{
}
}
}
-----------------------------------------------------------------------------------111. stringfinder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int stringFinder(string str, string firststr, string secondstr)
{
//Fill your code here
int t1 = str.IndexOf(firststr);
int t2 = str.IndexOf(secondstr);
if (t1 < t2)
return 1;
else
return 2;
}
}
--------------------------------------------------------------------------------------
112. student(findresult)
using System;
namespace myprograms
{
class UserProgramCode{
}
}
}
-----------------------------------------------------------------------------------
113. studenteligibility
using System;
namespace myprograms
{
class UserProgramCode
{
return str;
}
else
{
if (input1 >= 55 && input2 >= 45)
return pass;
return fail;
}
}
}
--------------------------------------------------------------------------------114. sumofoddeven
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sumododdneven
{
public class UserMainCode
{
public static int sumOfOddEvenPositioned(int input)
{
int r,i=0,se=0,so=0,flag=0;
int [] e=new int[20];
while (input != 0)
{
r = input % 10;
e[i] = r;
i++;
input = input / 10;
}
e.Reverse();
int s = e.Count();
for (i = 0; i < s; i++)
{
if (i % 2 == 0)
se += e[i];
else
so += e[i];
}
if (se == so)
flag = 1;
else
flag = 0;
return flag;
}
}
}
-------------------------------------------------------------------------------115. sumcube
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int sumOfCube(int n)
{
int result=0;
int sum = 0;
if (n < 0)
{
result = -1;
return result;
//break;
}
else
{
for (int i = 1; i <= n; i++)
{
sum = i * i * i;
}
}
-------------------------------------------------------------116. sumSquare
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
}
}
-------------------------------------------------------117. timevalidation(validatetime)
using System;
namespace time_validation
{
class UserProgramCode
{
char[] ch = input1.ToCharArray();
if(ch[2]==':')
{
if (ch[0] == '0' || ch[0] == '1')
{
if (ch[0] == '1' && (ch[1] == '1' || ch[1] == '2' || ch[1] == '0'))
{
if((ch[3]=='0' || ch[3]=='1'|| ch[3]=='2'|| ch[3]=='3'|| ch[3]=='4'||
ch[3]=='5') &&
(ch[4] == '0' || ch[4] == '1' || ch[4] == '2' || ch[4] == '3' || ch[4]
== '4' || ch[4] == '5' || ch[3] == '6' || ch[3] == '7' || ch[3] == '8' || ch[3] == '9'))
{
if ((ch[ch.Length - 2] == 'A' || ch[ch.Length - 2] == 'P' ||
ch[ch.Length - 2] == 'a' || ch[ch.Length - 2] == 'p') && (ch[ch.Length - 1] == 'M' ||
ch[ch.Length - 1] == 'm'))
{
output1 = 1;
}
else
output1 = -1;
}
else
output1=-1;
}
else
output1=-1;
}
else
output1 = -1;
}
else
output1 = -1;
return output1;
}
}
}
---------------------------------------------------------------------------------------------------------------------------------------
118. uniquecounter
using System;
class UserProgramCode
{
public static int uniqueCounter(string str)
{
int count = 0;
int count1 = 0;
char[] ch=str.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
count1 = 0;
char c = ch[i];
for (int j =0; j < str.Length; j++)
{
char cd = ch[j];
if (cd == c)
{
count1++;
}
}
if (count1 == 1)
{
count++;
}
}
if (count == 0)
return -1;
else
return(count);
}
}
-------------------------------------------------------------------------
119. validateidlocation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int validateIDLocations(String input1, String input2)
{
string[] a = input1.Split('-');
int len = input1.Length;
char[] b = input2.ToCharArray();
char[] b3 = { b[0], b[1], b[2] };
int len3 = 0;
char[] a2a = a[2].ToCharArray();
else
{
return -1;
}
}
}
------------------------------------------------------------------------------------------120. ValidateNegativeNumber
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ValidateNegativeNumber
{
class UserProgramCode
{
public static string validateNumber(string num)
{
string output1=null;
int count = 0;
int flag = 0;
int flag1 = 0;
int output = 0;
StringBuilder sb = new StringBuilder();
char[] ch = num.ToCharArray();
if (ch[0] == '-')
{
for (int i = 1; i < ch.Length; i++)
if (char.IsDigit(ch[i]))
{
count++;
}
}
if (count == ch.Length - 1)
{
flag = 1;
}
else
{
flag1 = -1;
}
if (flag == 1)
{
for (int j = 1; j < ch.Length; j++)
sb.Append(ch[j]);
output1 = sb.ToString();
}
else if (flag1 == -1)
{
output = -1;
output1 = Convert.ToString(output);
}
return output1;
}
}
}
----------------------------------------------------------------------------------------------121. validatenumber
using System;
class UserProgramCode
{
public static string validateNumber(string num)
{
int dash = 0, n = 0;
int length = num.Length;
char[] ch = num.ToCharArray();
if (ch[0] == '-')
{
dash++;
}
foreach (var item in ch)
{
if (Char.IsDigit(item))
{
n++;
}
}
if (dash == 1 && n == length - 1)
{
int x = int.Parse(num);
x = -x;
string output = x.ToString();
return output;
}
else
{
return "-1";
}
}
}
--------------------------------------------------------------------------122. validateVoter
using System;
using System.Globalization;
using System.Text.RegularExpressions;
class UserProgramCode
{
//public static int output4;
public static int validateVoter(string input1,string input2)
{
int output4;
DateTime dt;
DateTime dt2;
bool res = DateTime.TryParseExact(input1, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt);
bool res2 = DateTime.TryParseExact(input2, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out dt2);
if (res == true && res2 == true)
{
int year = dt2.Year - dt.Year;
int month = dt2.Month - dt.Month;
if (month < 0)
{
year = year - 1;
month = month + 12;
}
if (year > 18)
{
output4 = 1;
return output4;
}
else
{
output4 = 0;
return output4;
}
}
output4 = -1;
return output4;
}
}
-----------------------------------------------------------------------
123.sumofsquareofdigit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SumOfSquaresOfDigit
{
class UserProgramCode
{
public static int getSumOfSquareOfDigits(int number)
{
int sum = 0, squareDigit, digit, num;
num = number;
while (num != 0)
{
digit = num % 10;
squareDigit = digit * digit;
sum = sum + squareDigit;
num = num / 10;
return sum;
}
}
}
-------------------------------------------------------------------------------124. SumCommonElements(getSumOfIntersection)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SumCommonElements
{
class UserProgramCode
{
public static int getSumOfIntersection(int sizea, int sizeb, int[] a, int[] b)
{
int output = -1, sum=0;
{
sum=sum + a[i];
}
}
}
}
if (sum == 0)
{
output = -1;
}
else
{
output = sum;
}
return output;
}
}
}
------------------------------------------------------------------------125. NumberOfOccurences(countNoOfWords)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NumberOfOccurences
{
class UserProgramCode
{
public static int countNoOfWords(string input1, string input2)
{
int output=0;
string[] i1 = input1.Split(' ');
string [] i2 = input2.Split(' ');
string check = i2[1];
foreach (string i in i1)
{
if (string.Compare(i, check) == 0 )
{
output++;
}
}
return output;
}
}
}
----------------------------------------------------------------------------126. nextYearDay
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NextYearDay
{
class UserProgramCode
{
public static string nextYearDay(string date)
{
string output="";
DateTime day;
bool check = DateTime.TryParseExact(date, "dd/MM/yyyy", null,
System.Globalization.DateTimeStyles.None, out day);
if (check == true)
{
day = day.AddYears(1);
//Console.WriteLine(day);
//day = day.DayOfWeek;
output = day.DayOfWeek.ToString();
output = output.ToLower();
return output;
}
else
{
return output;
}
}
}
}
--------------------------------------------------------------------------127. LongestString(getLongestString)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LongestString
{
class UserProgramCode
{
public static String output;
public static string getLongestString(int size, string[] input, char check)
{
{
if (maxLength < input1.Length)
{
maxLength = input1.Length;
output = input1;
}
}
else
{
output = "No element found";
}
count++;
}
}
return output;
}
}
}
--------------------------------------------------------------------128. IndexPowerArray(getSumOfPower)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IndexPowerArray
{
class UserProgramCode
{
public static int getSumOfPower(int size, int[] input)
{
int sum;
double i1, vari, sum1=0;
for (int i = 0; i < size; i++)
{
i1 = Convert.ToDouble(I);
vari = Convert.ToDouble(input[i]);
//Console.WriteLine(i1+"\t"+vari);
sum1 = sum1 + Math.Pow(vari, i1);
//Console.WriteLine("\t" + sum1+"\n");
}
sum = (int)sum1;
return sum;
}
}
}
---------------------------------------------------------------------------------------------129. calculateBill
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateBill
{
class UserProgramCode
{
public static int calculateBill(string prevRead, string curRead, int
perUnitCharges)
{
int billAmount=0, i=0;
StringBuilder prev = new StringBuilder();
StringBuilder cur = new StringBuilder();
string i1 = prev.ToString();
string i2 = cur.ToString();
int p = int.Parse(i1);
int cr = int.Parse(i2);
return billAmount;
}
}
}
-------------------------------------------------------------------------130. calculateCharge
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateCharge
{
class UserProgramCode
{
public static int calculateCharge(string input1, string input2)
{
DateTime checkInDate, checkOutDate;
int output=0, minCharge = 20;
//double time;
bool check1 = DateTime.TryParseExact(input1, "yyyy-MMdd:HH:mm:ss",null, System.Globalization.DateTimeStyles.None, out checkInDate);
}
else
{
//time = (t1.Hours * 60 * 60) + (t1.Minutes*60)+(t1.Seconds);
if (days == 1)
{
//Console.WriteLine("exc");
output = minCharge +(5*(24-3));
}
else if (days == 0)
{
//Console.WriteLine("normal");
if (h < 3)
{
// Console.WriteLine("Three");
output = minCharge;
}
else
{
//Console.WriteLine("more");
output = minCharge + (5 * (h - 3));
}
}
}
if (output > 100)
{
output = 100;
}
return output;
}
}
}
*************************************************************************************
***********************************
CALCULATE FREQUENCY
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Class16
{
public static int output;
if (str1.Equals(s))
output++;
}
return output;
}
}
if(x>0)
{
Console.WriteLine("output: 2");
}
Console.ReadLine();
}
}
}
Calculate VAT
Calculate VAT%
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
double input1=1000;
double output1;
double percent;
double vat;
char input2='M';
switch (input2)
{
case 'M':
percent = 9;
Console.Read();
}
}
}
Calculation of discount
//Console.WriteLine("T for tv M for music player");
//Console.WriteLine("Enter product initial: ");
//char a;
//a = Convert.ToChar(Console.ReadLine());
//double amount, discount;
//Console.WriteLine("Enter the actual amount to be paid: ");
//amount = Convert.ToInt64(Console.ReadLine());
//if (a == 'T')
//{
//
//
//}
//if (a == 'M')
//{
//
//
//}
//Console.WriteLine("Amount paid: {0}",amount);
//Console.ReadKey();
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);
}
}}
COLOR CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class UserMainCode
{
public static void Main(string[] args)
{
string input1 = "#FF85HH";
int output1 = 0;
Regex reg = new Regex(@"^([#])+([A-F0-9]{6})+$");
if (reg.IsMatch(input1))
{
output1 = 1;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();
}
}
}
Common Element in Array
List<int> abs = new List<int>();
int count = 0;
foreach (var item in list1)
{
foreach (var item1 in list2)
{
if (item < 0 || item1 < 0)
{
count++;
}
}
}
if (count > 0)
{
abs.Add(-1);
}
else
{
abs = list1.Intersect(list2).ToList();
}
return (abs);
}
Concatenate String
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace t3
{
class Program
{
static void Main(string[] args)
{
string a, b;
a = Convert.ToString(Console.ReadLine());
b = Convert.ToString(Console.ReadLine());
if (a.Length == b.Length)
{
Console.Write(String.Concat(a, b));
}
else
{
if (a.Length > b.Length)
{
Console.Write(String.Concat((a.Substring((a.Lengthb.Length),b.Length)),b));
}
else
{
Console.Write(String.Concat(a, (b.Substring((b.Length - a.Length),
a.Length))));
}
}
Console.ReadKey();
}
}
}
count Character
/*Count Character*/
string s = Console.ReadLine();
string str = s.Replace(" ", "");
string ch = Console.ReadLine();
char[] b = str.ToCharArray();
int count=0;
int flag = 0;
for (int i = 0; i < b.Length; i++)
{
if (b[i] >= 'a' && b[i] <= 'z')
{
if (ch.Contains(b[i]))
{
count++;
}
}
else
{
flag = 1;
break;
}
}
if ( flag==0)
Console.WriteLine(count);
else
Console.WriteLine("Invalid");
// Console.WriteLine(count);
Console.ReadLine();
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
string[] input1 = { "santhu", "minnu", "keerthi" };
int c=0,count = 0;
foreach (string s in input1)
{
char[] ch = s.ToCharArray();
foreach (char i in ch)
{
if (char.IsLetter(i))
{
c++;
}
}
if (c > 0)
{
count = count + c;
}
Console.WriteLine(count);
Console.Read();
}
}
}
---------
Count Vowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CountVowells
{
class UserProgramCode
{
public static int countVowels(string input)
{
int output = 0;
foreach (char c in input)
{
if (char.IsLetter(c) == false)
{
output = -1;
return output;
}
else
{
switch (c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
output++;
break;
}
return output;
}
}
}
Counting Bill
int bill;
if(input2=="AC")
if(input1=='C')
bill=1300*input3;
Console.WriteLine(bill);
if(input1=='H')
bill=1100*input3;
Console.WriteLine(bill);
if(input1=='B')
bill=1400*input3;
Console.WriteLine(bill);
else if(input2=="Non-AC")
if(input1=='C')
bill=1000*input3;
Console.WriteLine(bill);
if(input1=='H')
bill=800*input3;
Console.WriteLine(bill);
if(input1=='B')
bill=1100*input3;
Console.WriteLine(bill);
}
}
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][09][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);
}
Credit Card
public static string output11;
public static void CreditCard(string input1)
{
Regex dd = new Rege:@@"[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}$");
if (dd.IsMatch(input1))
{
output11 = "1";
}
else
{
output11 = "-1";
}
Console.WriteLine(output11);
}
1) Anagram
---------------------------------------------using System;
class Program
{
public static void Main(string[] args)
{
string input1 = Console.ReadLine();
string input2 = Console.ReadLine();
bool result = UserProgramCode.checkAnagram(input1, input2);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class UserProgramCode
{
public static bool checkAnagram(string input1, string input2)
{
string in1 = input1.ToLower();
char[] charin = in1.ToCharArray();
Array.Sort(charin);
-------------------------------------------------------------------------------------2) Cubing
using System;
class Program
int n=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<n;i++)
value[i]=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<output.Length;i++)
Console.Write(output[i]+"\n");
}
Console.ReadLine();
}
using System;
using System.Text;
using System.Collections;
class UserProgramCode
{
int i=0,ch,c;
int ch1=0,flag=1;
int s = input1.Length;
ArrayList sb = new ArrayList();
int[] op1 = new int[s];
for (i = 0; i < s; i++)
{
if (input1[i] < 0)
{
flag = 0;
}
if (flag == 0)
{
for (i = 0; i < s; i++)
{
op1[i] = input1[i]; ;
}
return op1;
}
else
{
for (i = 0; i < s - 1; i++)
{
ch = input1[i] * input1[i];
if (input1[i + 1] == ch)
{
c = input1[i] * input1[i] * input1[i];
if (i == 0)
{
sb.Add(input1[i]);
sb.Add(c);
sb.Add(input1[i + 1]);
}
else
{
sb.Add(c);
sb.Add(input1[i + 1]);
}
}
else
{
if (i == 0)
{
sb.Add(input1[i]);
sb.Add(input1[i + 1]);
}
else
{
sb.Add(input1[i + 1]);
}
}
}
int len = sb.Count;
int[] op = new int[len];
i = 0;
foreach (int n in sb)
{
op[i] = n;
i++;
}
return op;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------3) FormNewWord
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
static void Main(string[] args)
{
Console.WriteLine(UserProgramCode.formNewWord(word, n));
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------4)FindLargestDigit
using System;
class Program
{
public static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
int result = UserProgramCode.findLargestDigit(num);
if (result == -1)
Console.WriteLine("Negative Number");
else
Console.WriteLine(result);
Console.ReadKey();
}
}
using System;
class UserProgramCode
{
public static int findLargestDigit(int num)
{
int temp=0,rem=0,output=0;
temp = num;
if (temp < 0)
{
return -1;
}
else
{
while (temp > 0)
{
}
return output;
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------5) InitialFormat
using System;
class Program
string input1;
input1 = Console.ReadLine();
Console.WriteLine(output);
Console.ReadLine();
using System;
class UserProgramCode
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
6) DuplicateCharacters
using System;
class Program
{
public static void Main(string[] args)
{
string input;
input = Console.ReadLine();
string outputStr = UserProgramCode.removeDuplicates(input);
Console.WriteLine(outputStr);
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static string removeDuplicates(string input1)
{
char[] ch = input1.ToCharArray();
char[] res = ch.Distinct().ToArray();
//Console.Read();
return output;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------7) NumberOfOccurances
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NumberOfOccurences
{
class Program
{
static void Main(string[] args)
{
string input1;
char input2;
input1 = Console.ReadLine();
input2 = Convert.ToChar(Console.ReadLine());
int value = UserProgramCode.findOccurence(input1, input2);
if (value == -1)
Console.WriteLine("Invalid Input");
else
Console.WriteLine(value);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NumberOfOccurences
{
class UserProgramCode
{
public static int findOccurence(string input1,char input2)
{
// fill your code here
int output=0;
string ip1 = input1.ToLower();
char ip2 = char.ToLower(input2);
char[] ch=sr.ToCharArray();
foreach (char ch1 in ch)
{
if (!char.IsLetter(ch1))
{ return -1; }
else
{
if (ch1 == ip2)
{ output++; }
}
}
return output;
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------8) CountOfElements
using System;
class Program
int size=0,i;
char ch;
size=Convert.ToInt32(Console.ReadLine());
for(i=0;i<size;i++)
{
arr[i] = Console.ReadLine();
ch=Convert.ToChar(Console.ReadLine());
int f = UserProgramCode.GetCount(size,arr,ch);
if(f == -1)
{
else
{
Console.WriteLine(f);
Console.ReadLine();
sing System;
class UserProgramCode
{
public static int GetCount(int size,string[] arr,char ch)
{
//Fill your code here
int count = 0;
}
if (count > 0)
return count;
if (count == 0)
return -1;
return 0;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------9) SumOfFibonacciSeries
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserMainCode.getSumOfNfibos(n));
//Console.ReadKey();
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
int first = 0, second = 1, next, c,sum=0;
}
-----------------------------------------------------------------------------------------------------------------------------------------------10) MaxSpan
using System;
class Program
int size=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<size;i++)
arr[i]=Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getMaxSpan(size,arr));
Console.ReadKey();
}
using System;
class UserProgramCode
{
int ind2 = 0, c = 0;
if (size == 1)
{
return 1;
}
if (i == 0 && c != 0)
return ind2 - i;
}
return 0;
-----------------------------------------------------------------------------------------------------------------------------------------------------------11) RemoveTens
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
public static void Main(string[] args)
{
int size,i;
size = Convert.ToInt32(Console.ReadLine());
int[] arr=new int[size];
int[] output = new int[size];
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
int count = 0, k = 0;
int[] output = new int[size];
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------12) PrintCapitalized
using System;
class Program
Console.WriteLine(UserProgramCode.printCapitalized(Console.ReadLine()));
Console.ReadKey();
using System;
using System.Linq;
class UserProgramCode
{
public static String printCapitalized(String input1)
{
input1 = input1.ToLower();
char a;
int count = 0;
string[] str = input1.Split(' ');
string output = "";
foreach (string s in str)
{
count = 0;
foreach (char ch in s)
{
a = ch;
if (count == 0)
{
if (char.IsLetter(ch))
{
a = (char)((int)ch - 32);
}
}
output = output + a;
count++;
}
output = output + " ";
}
return output;
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------13) StringManipulation
using System;
using System.Collections.Generic;
class Program
string str1=Console.ReadLine();
string str2=Console.ReadLine();
Console.WriteLine(UserProgramCode.stringManipulation(str1,str2));
Console.ReadKey();
}
using System;
using System.Collections.Generic;
class UserProgramCode
{
char[] cha = str1.ToCharArray();
foreach (char ch1 in cha)
{
if (!(char.IsLetterOrDigit(ch1)))
return "Special character found";
}
char[] ch = str2.ToCharArray();
foreach (char ch1 in ch)
{
if (!(char.IsLetterOrDigit(ch1)))
return "Special character found";
}
string output1 = " ";
Array.Reverse(ch);
string i2 = new string(ch);
if (str1.Length % 2 == 0)
{ output1 = str1.Substring(0, (str1.Length) / 2) + i2 + str1.Substring(str1.Length
/ 2); }
else
{ output1 = str1.Substring(0, ((str1.Length) / 2) + 1) + i2 +
str1.Substring((str1.Length / 2) + 1); }
return output1;
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------14) IndexPowerArray
using System;
class Program
int size=0,i;
size=Convert.ToInt32(Console.ReadLine());
for(i=0;i<size;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getSumOfPower(size,arr));
Console.ReadKey();
using System;
class UserProgramCode
{
int[] array = new int[size] ;
int sum = 0;
---------------------------------------------------------------------------------------------------------------------------------------------------------------15) CheckBatchCode
using System;
class Program
string input1,output;
input1 = Console.ReadLine();
output = UserProgramCode.checkBatch(input1);
Console.WriteLine(output);
Console.ReadLine();
using System;
class UserProgramCode
{
{
// fill code here
string city=input1.Substring(0,3);
string year = input1.Substring(3, 2);
string stream =input1.Substring(5, 2);
case "CHN":
city = "Chennai";
break;
case "CBE":
city="Coimbatore";
break;
case "KOC":
city = "Kochi";
break;
case "PUN":
city = "Pune";
break;
case "BGL":
city = "Bangalore";
break;
case "HYD":
city = "Hyderabad";
break;
case "KOL":
city = "Kolkata";
break;
}
}
else
{
return "-1";
}
output = "DotNet batch " + batch + " has joined in 20" + year + " year and is
at " + city + " Location.";
return output;
-------------------------------------------------------------------------------------------------------------------------------------------------------------16) ExtractMaxString
using System;
class Program
string str,sym;
str = Console.ReadLine();
sym = Console.ReadLine();
Console.WriteLine(output);
Console.ReadLine();
}
using System.Collections.Generic;
using System;
class UserProgramCode
{
// fill your code here
char dem = Convert.ToChar(sym);
string[] input = str.Split(dem);
int max = 0;
List<string> l = new List<string>();
l.Add("0");
foreach (var i in input)
{
if (max < i.Length)
{
max = i.Length;
l[0] = i;
}
else if (max == i.Length)
{
char i1 = Convert.ToChar(l[0].Substring(0,1));
char i2 = Convert.ToChar(i.Substring(0, 1));
if (i1 > i2)
{
max = i.Length;
l[0] = i;
}
}
}
return l[0];
}
------------------------------------------------------------------------------------------------------------------------------------------------------------17) AddDays
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace add_days
{
class Program
{
static void Main(string[] args)
{
string date, newDate;
int add;
date = Console.ReadLine();
add = Convert.ToInt32(Console.ReadLine());
newDate = UserProgramCode.addDays(date, add);
if (newDate.Equals("-1"))
{
Console.WriteLine("n value is negative");
}
else if (newDate.Equals("-2"))
{
Console.WriteLine("Invalid date format");
}
else
{
Console.WriteLine(newDate);
}
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace add_days
{
class UserProgramCode
{
public static string addDays(string date, int add)
{
DateTime newDate;
string output;
if(add <0)
{
return "-1";
}
else if(DateTime.TryParseExact(date, "MM/dd/yyyy", null,
System.Globalization.DateTimeStyles.None, out newDate) == false)
{
return "-2";
}
else
{
newDate = newDate.AddDays(add);
output = newDate.ToString("MM/dd/yyyy");
return output;
}
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------
18)PageOfVowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PageOfVowels
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
char[] c = s.ToCharArray();
int count = 0;
List<char> l = new List<char>();
int flag = 0;
for(int i=0;i<s.Length;i++)
{
if (c[i] >= 'a' && c[i] <= 'z')
{
if (c[i] == 'a' || c[i] == 'e' || c[i] == 'i' || c[i] == 'o' || c[i] == 'u')
{
if (!l.Contains(c[i]))
{
l.Add(c[i]);
}
else
{
flag = 1;
}
count++;
}
if (flag != 1)
{
if (count == 5)
{
Console.WriteLine("valid");
}
else
{
Console.WriteLine("invalid");
}
}
else
{
Console.WriteLine("invalid");
}
Console.ReadLine();
}
}
}
-------------------------------------------------------------------------------------------------------------------------------19) InsuranceCompany
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InsuranceCompany
{
class Program
{
static void Main(string[] args)
{
char health = Convert.ToChar(Console.ReadLine()) ;
int age = Convert.ToInt32(Console.ReadLine());
char gender = Convert.ToChar(Console.ReadLine());
char location = Convert.ToChar(Console.ReadLine());
int premium=0, insurance=0;
if ((health == 'E') && (age >= 25 && age <= 35) && location == 'C' &&
gender == 'M')
{
premium = 4;
insurance = 200000;
}
else if ((health == 'E') && (age >= 25 && age <= 35) && location == 'C'
&& gender == 'F')
{
premium = 3;
insurance = 100000;
}
else if ((health == 'P') && (age >= 25 && age <= 35) && location == 'V'
&& gender == 'M')
{
premium = 6;
insurance = 10000;
}
else if (age >= 60)
{
Console.WriteLine("Age Limit Exceeded");
}
else
{
Console.WriteLine("The person cannot be insured");
}
Console.WriteLine(premium);
Console.WriteLine(insurance);
Console.ReadLine();
}
}
}
--------------------------------------------------------------------------------------------------------------------20) MinimumNumber
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Min
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
int[] ar = new int[n];
}
}
--------------------------------------------------------------------------------------21) CheckCharacters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CheckCharacters
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
char [] str=s.ToCharArray();
if (str[0]==str[str.Length-1])
{
Console.WriteLine("The characters are same");
}
else
{
Console.WriteLine("The characters are different");
}
Console.ReadLine();
}
}
}
------------------------------------------------------------------------------------------------------22)SumOfDigits
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sumofdigits
{
class Program
{
public static long sumofdigi(long n)
{
long k;
long sum = 0;
while (n > 0)
{
k = n % 10;
n = n / 10;
sum = sum + k;
}
return sum;
}
while (n>9)
{
n= Program.sumofdigi(n);
}
Console.WriteLine(n);
Console.ReadLine();
}
}
}
-------------------------------------------------------------------------------------------------23) InterChangeCharacters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InterChangeChars
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string str = s;
char[] ch = s.ToCharArray();
char df = ch[0];
ch[0] = ch[ch.Length - 1];
ch[ch.Length - 1] = df;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MatchingString
{
class Program
{
static void Main(string[] args)
{
if (ch[0] == startChar)
{
list.Add(s1);
count++;
}
Console.ReadLine();
}
}
}
------------------------------------------------------------------------------25) CountOddIntegers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CountOddIntegers
{
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] n = new int[size];
int count = 0;
for (int i = 0; i < size; i++)
{
n[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < size; i++)
{
if (n[i] % 2 == 1)
{
count++;
}
}
Console.WriteLine(count);
Console.ReadLine();
}
}
}
----------------------------------------------------------------------------------------26) StringEqualCheck
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringEqualCheck
{
class Program
{
static void Main(string[] args)
{
string input1 = Console.ReadLine();
string input2 = Console.ReadLine();
int n = Convert.ToInt32(Console.ReadLine());
char[] in1 = input1.ToCharArray();
char[] in2 = input2.ToCharArray();
Array.Reverse(in2);
//string str = new string(in2);
//Console.WriteLine(str);
if (in1[n-1] == in2[n-1])
{
Console.WriteLine("The character is {0}", in1[n-1]);
}
else
{
Console.WriteLine("The character {0} and {1} does not match", in1[n-1],
in2[n-1]);
}
Console.ReadLine();
}
}
}
----------------------------------------------------------------------------------------------------------------------27) StrongNumber
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StrongNumber
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
int f=n;
int fact = 1;
for (int i = 1; i <= rem; i++)
{
fact = fact * i;
}
sum = sum + fact;
}
if (sum == f)
{
Console.WriteLine("{0} is a Strong Number", sum);
}
else
{
Console.WriteLine("Sum of all digits factorial is {0}", sum);
}
Console.ReadLine();
}
}
}
------------------------------------------------------------------------------------------------28) SecondSmallest Array Integer Number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sort
{
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] n = new int[size];
Console.WriteLine(n[1]);
Console.ReadLine();
}
}
}
---------------------------------------------------------------------------------------------29) SortElements & display half in upper & half in lower case letters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lab3
{
class Program
{
static void Main(string[] args)
{
string sr = Console.ReadLine();
OrderDemo obj = new OrderDemo();
string[] result = obj.AlphaOrder(sr);
foreach (string s in result)
{
Console.WriteLine(s);
}
Console.Read();
}
}
class OrderDemo
{
public string[] AlphaOrder(string sr)
{
string[] result=sr.Split();
Array.Sort(result);
int k=0;
foreach (string s in result)
{
int len=s.Length;
if (len % 2 == 0)
{
string s1=s.Substring(0,len/2);
string s2=s.Substring((len/2));
result[k]=s1.ToUpper()+s2.ToLower();
}
else
{
string s1 = s.Substring(0, (len / 2)+1);
string s2 = s.Substring((len / 2) + 1);
result[k] = s1.ToUpper() + s2.ToLower();
}
k++;
}
return result;
}
}
}
--------------------------------------------------------------------------------------30) removeList from another List
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lab4
{
class Program
{
static void Main(string[] args)
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
namespace Lab5
{
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = Convert.ToInt32(Console.ReadLine());
Hashtable result = new Hashtable();
HashTableDemo obj = new HashTableDemo();
result = obj.GetSquares(array);
ICollection key = result.Keys;
foreach (int k in key)
{
Console.WriteLine(k + ": " + result[k]);
}
Console.Read();
}
}
class HashTableDemo
{
public Hashtable GetSquares(int[] array)
{
Hashtable result = new Hashtable();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HandOn6SortArray
{
class Program
{
public static int ReverseDigit(int number)
{
int j;
int n = number % 10;
int k = number / 10;
if (k != 0)
{
j = n * 10 + k;
}
else
j = number;
return j;
}
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] a = new int[size];
int i = 0;
for (i = 0; i < size; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
int[] arrr=new int[size];
for (int j = 0; j < size;j++ )
{
arrr[j] = Program.ReverseDigit(a[j]);
}
Array.Sort(arrr);
foreach (int x in arrr)
{
Console.WriteLine(x);
}
Console.ReadLine();
}
}
}
-------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HandsOnLab7
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
int[] input = new int[n];
for (int i = 0; i < n; i++)
input[i] = Convert.ToInt32(Console.ReadLine());
RemoveDuplicate obj = new RemoveDuplicate();
int[] result = obj.DuplicateRemove(input);
for (int i = result.Length - 1; i >= 0; i--)//to print in descending order
Console.WriteLine(result[i]);
Console.Read();
}
}
class RemoveDuplicate
{
public int[] DuplicateRemove(int[] input)
{
List<int> list = new List<int>(input.Distinct());
//to convert to list and to make run disstrinct function
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HandsOnLab9
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
StringPositiveDemo obj = new StringPositiveDemo();
bool result = obj.CheckPositive(input);
if (result.Equals(true))
Console.WriteLine("the entered string is positive");
else
Console.WriteLine("the entered string is not positive");
Console.Read();
}
}
class StringPositiveDemo
{
public bool CheckPositive(string input)
{
int count = 0;
for (int i = 0; i < input.Length - 1; i++)
{
if (input[i] <= input[i + 1])
{
count++;
}
}
if (count == input.Length - 1)
return true;
return false;
}
}
}
---------------------------------------------------------------------------------------35) SumEvenNumbers divisible by 3 & 8
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HandsOnLab10
{
class Program
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HandsOn11
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
CubeSumDemo obj = new CubeSumDemo();
int sum = obj.FindCubeSum(n);
Console.WriteLine(sum);
Console.Read();
}
}
class CubeSumDemo
{
public int FindCubeSum(int n)
{
int sum = 0, rem;
while (n > 0)
{
rem = n % 10;
sum += (rem * rem * rem);
n /= 10;
}
return sum;
}
}
}
---------------------------------------------------------------------------37) FactFiboNacci Numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HandsOn12
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
FebFactDemo obj = new FebFactDemo();
int sum = obj.FindFebFactSum(n);
Console.WriteLine(sum);
Console.Read();
}
}
class FebFactDemo
{
public int FindFebFactSum(int n)
{
int sum = 0;
int[] feb = new int[n];
for (int i = 0; i < n; i++)
{
if (i == 0)
feb[0] = 0;
else if (i == 1)
feb[1] = 1;
else
feb[i] = feb[i - 1] + feb[i - 2];
}
foreach (int val in feb)
{
int fact = 1;
if (val == 0 || val == 1)
fact = 1;
else
{
int i = 1;
while (i <= val)
{
fact = fact * i;
i++;
}
}
sum = sum + fact; ;
}
return sum;
}
}
}
----------------------------------------------------------------------------------38) SaleDate>PurchaseDate Valid or not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HandsOn13
{
class Program
{
static void Main(string[] args)
{
DateTime dt1 = Convert.ToDateTime(Console.ReadLine());
DateTime dt2 = Convert.ToDateTime(Console.ReadLine());
VerifyDateDemo vdd = new VerifyDateDemo();
bool result = vdd.VerifyDate(dt1, dt2);
if (result.Equals(true))
Console.WriteLine("valid");
else
Console.WriteLine("not valid");
Console.ReadLine();
}
}
class VerifyDateDemo
{
public bool VerifyDate(DateTime dt1, DateTime dt2)
{
int days = dt2.Subtract(dt1).Days;
bool res;
if (days > 0)
res = true;
else
res = false;
return res;
}
}
}
----------------------------------------------------------------------------39) AdjacentChars with *
using System;
}
else
str=str+s[i];
}
if(i==s.Length-1)
str+=s[i];
return str;
}
}
-----------------------------------------------------------------------40) Permutations
using System;
class Permutation
{
static void Main(string[] args)
{
string str = "ABCD";
char[] charArry = str.ToCharArray();
permute(charArry, 0, 3);
Console.ReadKey();
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
ar1[i] = Convert.ToInt32(Console.ReadLine());
int n2 = Convert.ToInt32(Console.ReadLine());
int[] ar2 = new int[n2];
for (int i = 0; i < n2; i++)
ar2[i] = Convert.ToInt32(Console.ReadLine());
int n3 = Convert.ToInt32(Console.ReadLine());
int[] ar3 = new int[n3];
for (int i = 0; i < n3; i++)
ar3[i] = Convert.ToInt32(Console.ReadLine());
int[] result = UserMainCode.FindCommonElements(ar1, ar2, ar3);
for (int i = 0; i < result.Length;i++ )
Console.WriteLine(result[i]);
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int[] FindCommonElements(int[] ar1,int[] ar2,int[] ar3)
{
int[] c1=new int[ar1.Length];
int k=0;
for(int i=0;i<ar1.Length;i++)
{
if(ar1[i]%3==0)
{
c1[k]=ar1[i];
k++;
}
}
int[] c2=new int[ar2.Length];
k=0;
for(int i=0;i<ar2.Length;i++)
{
if(ar2[i]%3==0)
{
c2[k]=ar2[i];
k++;
}
}
int[] c3=new int[ar3.Length];
k=0;
for(int i=0;i<ar3.Length;i++)
{
if(ar3[i]%3==0)
{
c3[k]=ar3[i];
k++;
}
}
int[] result=new int[c1.Length];
int l=0;
foreach(int a in c1)
{
foreach (int b in c2)
{
foreach (int c in c3)
{
if (a == b && b == c)
{
result[l] = a;
l++;
}
}
}
}
for (int i = 0; i < result.Length; i++)
{
for (int j = i + 1; j < result.Length; j++)
{
if (result[i] < result[j])
{
int temp = result[i];
result[i] = result[j];
result[j] = temp;
}
}
}
return result;
}
---------------------------------------------------------------------------------------42) SymmetricDifference
using System;
class Program
{
public static void Main( string[] args )
{
int input1,input2;
input1 = Convert.ToInt32(Console.ReadLine());
input2 = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.symmetricDifference(inputArr1,inputArr2);
for(int i=0;i<output.Length;i++)
if(output[i]!=0)
Console.WriteLine(output[i]);
}
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class UserProgramCode
{
public static int[] symmetricDifference(int[] input1, int[] input2)
{
int negative1=0,negative2=0;
foreach (int a in input1)
{
if (a < 0)
negative1++;
}
foreach (int b in input2)
{
if (b < 0)
negative2++;
}
var union = input1.Union(input2);
var intersect = input1.Intersect(input2);
int[] res = new int[5];
if (negative1 > 0)
res[0] = -1;
else if (negative2 > 0)
res[0] = -2;
else if ((intersect.Count() == input1.Length) || intersect.Count() == 0)
{
res[0] = -3;
}
else
{
int k = 0;
foreach (int val in union)
{
if (!(res1.Contains(val)))
{
res[k] = val;
k++;
}
}
Array.Sort(res);
}
return res;
}
}
------------------------------------------------------------------------------------------------43) ValidateNumber
using System;
class Program
{
public static void Main(string[] args)
{
string num = Console.ReadLine();
class UserProgramCode
{
public static string validateNumber(string num)
{
int dash = 0, n = 0;
int length = num.Length;
char[] ch = num.ToCharArray();
if (ch[0] == '-')
{
dash++;
}
foreach (var item in ch)
if (Char.IsDigit(item))
{
n++;
}
}
if (dash == 1 && n == length - 1)
{
int x = int.Parse(num);
x = -x;
string output = x.ToString();
return output;
}
else
{
return "-1";
}
}
}
-----------------------------------------------------------------------44) ValidateVoter
using System;
class Program
{
public static void Main(string[] args)
{
class UserProgramCode
{
public static int validateVoter(string dob, string electionDate)
{
//Fill your code here
int output1;
DateTime db = new DateTime();
DateTime db1 = new DateTime();
try
{
db = DateTime.ParseExact(dob
{
output1 = 1;
}
else
{
output1 = 0;
}
}
catch
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();
}
}
--------------------------------------------------------------------------
45) LengthOfLongestString:
using System;
namespace myprograms
{
class Program
{
public static void Main()
{
int size = int.Parse(Console.ReadLine());
String[] array = new String[size];
for (int i = 0; i < size; i++)
{
array[i] = Console.ReadLine();
}
Console.WriteLine(UserProgramCode.longestWordLength(array));
Console.ReadLine();
}
}
}
using System;
namespace myprograms
{
class UserProgramCode
{
public static int longestWordLength(String[] array)
{
}
}
}
----------------------------------------------------------------------46) NextYearDay
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NextYearDay
{
class Program
{
static void Main(string[] args)
{
string input, output;
input = Console.ReadLine();
output = UserProgramCode.nextYearDay(input);
if (output == null)
{
Console.WriteLine("Invalid date");
}
Console.WriteLine(output);
Console.ReadKey();
}
}
}
using System.Text;
namespace NextYearDay
{
class UserProgramCode
{
public static string nextYearDay(string date)
{
string output="";
DateTime day;
bool check = DateTime.TryParseExact(date, "dd/MM/yyyy", null,
System.Globalization.DateTimeStyles.None, out day);
if (check == true)
{
day = day.AddYears(1);
//Console.WriteLine(day);
//day = day.DayOfWeek;
output = day.DayOfWeek.ToString();
output = output.ToLower();
return output;
}
else
{
return output;
}
}
}
}
----------------------------------------------------------------------------------------------------47) CapitalString
using System;
{
string s = Console.ReadLine();
Console.WriteLine(UserMainCode.ProcessString(s));
Console.ReadLine();
}
}
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringProcessing
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string[] str = s.Split(' ');
StringBuilder sb = new StringBuilder();
string s2 = sb.ToString();
string res = " ";
Console.WriteLine(res);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PasswordValidation
{
class Program
{
static void Main(string[] args)
{
string pwd = Console.ReadLine();
int len = pwd.Length;
{
Console.WriteLine("valid");
}
}
}
else
Console.WriteLine("invalid");
Console.ReadLine();
}
}
}
-----------------------------------------------------------------------------50) Date Difference in Days
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DateDiff
{
class Program
{
static void Main(string[] args)
{
DateTime dt1, dt2;
dt1 = Convert.ToDateTime(Console.ReadLine());
dt2 = Convert.ToDateTime(Console.ReadLine());
int res = Convert.ToInt32(Math.Abs((dt1 - dt2).TotalDays).ToString());
Console.WriteLine(res);
Console.ReadLine();
}
}
}
--------------------------------------------------------------------------------------2) Cubing
using System;
class Program
int n=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<n;i++)
value[i]=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<output.Length;i++)
Console.Write(output[i]+"\n");
}
Console.ReadLine();
}
using System;
using System.Text;
using System.Collections;
class UserProgramCode
{
int i=0,ch,c;
int ch1=0,flag=1;
int s = input1.Length;
ArrayList sb = new ArrayList();
int[] op1 = new int[s];
for (i = 0; i < s; i++)
{
if (input1[i] < 0)
{
flag = 0;
ch1 = input1[i] * input1[i];
input1[i] = ch1;
}
}
if (flag == 0)
{
for (i = 0; i < s; i++)
{
op1[i] = input1[i]; ;
}
return op1;
}
else
{
for (i = 0; i < s - 1; i++)
{
ch = input1[i] * input1[i];
if (input1[i + 1] == ch)
{
c = input1[i] * input1[i] * input1[i];
if (i == 0)
{
sb.Add(input1[i]);
sb.Add(c);
sb.Add(input1[i + 1]);
}
else
{
sb.Add(c);
sb.Add(input1[i + 1]);
}
}
else
{
if (i == 0)
{
sb.Add(input1[i]);
sb.Add(input1[i + 1]);
}
else
{
sb.Add(input1[i + 1]);
}
}
}
int len = sb.Count;
int[] op = new int[len];
i = 0;
foreach (int n in sb)
{
op[i] = n;
i++;
}
return op;
}
Donation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Donation
{
class Program
{
public static string GetDenationValue(string[] input,int add)
{
int count = 0,don=0;
List<string> sl = new List<string>();
foreach (string i in input)
{
count = 0;
foreach (char j in i)
{
if (Char.IsLetter(j) || Char.IsDigit(j))
{
count++;
}
else
{
return "-2";
}
}
if (count == i.Length)
{
if (!sl.Contains(i))
{
sl.Add(i);
}
else
{
return "-1";
}
int ad = Convert.ToInt32(i.Substring(3,3));
if (ad == add)
{
int d=Convert.ToInt32(i.Substring(6,3));
don = don + d;
}
}
}
return don.ToString();
}
static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
string[] input = new string[num];
}
}
DUPLICATE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static string removeDuplicates(string input1)
{
char[] ch = input1.ToCharArray();
char[] res = ch.Distinct().ToArray();
}
}
Email ID Validation
public static string output13;
public static void eMailValidation(string input1)
{
if (dd.IsMatch(input1))
{
output13 = "1";
}
else
{
output13 = "-1";
}
Console.WriteLine(output13);
}
}
13.eMail ID Validation
public static string output13;
public static void eMailValidation(string input1)
{
//Regex dd = new Rege:@@"^((([a-zA-Z0-9])+|[#.$%&_]*)+[@\w]+[a-zA-Z09]+[.]+([a-zA-Z]){3})+$");
Regex dd = new Rege:@@"^((([a-zA-Z0-9])+|[#.$%&_-]*)+@+[a-zA-Z0-9]+
[.]+([a-zA-Z]){3})+$");
if (dd.IsMatch(input1))
{
output13 = "1";
}
else
{
output13 = "-1";
}
Console.WriteLine(output13);
}
}
}
}
string MaxStr="";
int maxLength = 0;
string[] ar = str.Split(Convert.ToChar(sym));
if(s.Length == maxLength)
{
if (MaxStr != "")
{
MaxStr = s;
maxLength = s.Length;
}
}
else if (s.Length > maxLength)
{
MaxStr = s;
maxLength = s.Length;
}
else { }
}
return MaxStr;
}
Find Occurance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NumberOfOccurences
{
class UserProgramCode
{
public static int findOccurence(string input1,char input2)
char[] ch=sr.ToCharArray();
foreach (char ch1 in ch)
{
if (!char.IsLetter(ch1))
{ return -1; }
else
{
if (ch1 == ip2)
{ output++; }
}
}
return output;
}
}
}
Find Span of an Array
to find span of an array..
{
//Fill your code here
int i = 0; int j = 0;
int span = 1; int temp = 0;
for (i = 0; i < size; i++)
{
for (j = i+1; j < size; j++)
{
if (arr[i] == arr[j])
{
temp = j - i + 1;
if (temp > span)
{
span = temp;
}
}
}
}
return span;
}
Generate the series
int flag = 1;
int sum = 4;
if (input1 == 1)
{
sum = 1;
}
else if (input1 == 3)
{
sum = 4;
}
else if (input1 > 3)
{
for (int i = 5; i <= input1; i = i + 2)
{
if (flag == 1)
{
sum = sum - i;
flag = 0;
}
else
{
sum = sum + i;
flag = 1;
}
}
}
return (sum);
}
output = UserProgramCode.getBigDiff(input);
Console.WriteLine(output);
Console.ReadKey();
}
}
class UserProgramCode
{
public static int getBigDiff(int[] input)
{
int max, min, size, output;
size = input.Length;
max = input[0];
min = input[0];
for (int i = 1; i < size; i++)
{
if (max < input[i])
{
max = input[i];
}
if (min > input[i])
{
min = input[i];
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication23
{
class Program
{
public static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (int i = 0; i < size; i++)
arr[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getMaxSpan(size, arr));
Console.ReadLine();
}
}
class UserProgramCode
{
public static int getMaxSpan(int size, int[] arr)
{
int ind2 = 0, c = 0;
if (size == 1)
{
return 1;
}
STRING PERMUTATION
Sample i/p: abc
Output :abc,acb,bac,bca,cab,cba
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
namespace ConsoleApplication29
{
class Program
{
static void Main(string[] args)
{
string str;
str=Console.ReadLine();
int l=str.Length;
char[] charArry = str.ToCharArray();
permute(charArry, 0, l-1);
Console.ReadKey();
QUADRETIC EQUATION
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Quadretic_Equatin
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int[] ar = new int[n];
for (int i = 0; i < n; i++)
{
ar[i] = int.Parse(Console.ReadLine());
}
int[] oup = UserProgramCode.calyz(ar);
foreach (int m in oup)
{
Console.Write(m+" ");
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Quadretic_Equatin
{
class UserProgramCode
{
public static int[] calyz(int[] ar)
{
int y, z,k=0;
List<int> arr = new List<int>();
int[] di = ar.Distinct().ToArray();
COUNT WORD
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace count_word
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
string str1 = Console.ReadLine();
int ctr = 0;
namespace Duplicate_char
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
string str1 = "";
Console.WriteLine(str1);
Console.ReadLine();
}
}
}
hELLO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hel_lo
{
class Program
{
static void Main(string[] args)
{
string str=Console.ReadLine();
StringBuilder sb = new StringBuilder();
sb.Append(str[0]);
for (int i = 1; i < str.Length; i++)
{
namespace string_Encription
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
char[] ar = str.ToCharArray();
StringBuilder sb = new StringBuilder();
}
}
}
namespace gvyjv
{
class Program
{
static void Main(string[] args)
{
string i=Console.ReadLine();
string str= UserProgramCode.removeEvenVowels(i);
Console.WriteLine(str);
Console.Read();
}
}
}
using System;
using System.Text;
namespace myprograms
{
class UserProgramCode{
char[] ch = input1.ToCharArray();
int count = 1;
foreach (char i in ch)
{
if (count % 2 == 0)
{
if (!(i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'u'))
{
sb.Append(i);
count++;
}
else
{
count++;
}
}
else
{
sb.Append(i);
count++;
}
}
string output = sb.ToString();
return output;
}
}
}
REMOVETENS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
public static void Main(string[] args)
{
int size, i;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
int[] output = new int[size];
for (i = 0; i < size; i++)
arr[i] = Convert.ToInt32(Console.ReadLine());
output = removeTens(arr, size);
for (i = 0; i < size; i++)
Console.WriteLine(output[i]);
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int[] removeTens(int[] arr, int size)
{
int count = 0, k = 0;
int[] output = new int[size];
Console.WriteLine(output);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
class Program
{
public static void Main(string[] args)
{
int input2;
string input1, output;
input1 = Console.ReadLine();
input2 = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.repeatRemoveString(input1, input2);
Console.WriteLine(output);
Console.ReadLine();
}
}
class UserProgramCode
{
public static string repeatRemoveString(string input1,int input2)
{
// fill code here
if (input2 < 0)
if (len % 2 == 0)
{
for (int i = 1; i < len; i = i + 2)
{
sb.Append(abc[i]);
}
}
else
{
for (int i = 0; i < len; i = i + 2)
{
sb.Append(abc[i]);
}
}
return snew;
}
}
REPEATED INTEGERS
using System;
class Program
{
public static void Main(string[] args)
{
int size = 0, i;
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (i = 0; i < size; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
UserProgramCode.findRepeatedIntegers(size, arr);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static void findRepeatedIntegers(int size,int[] arr)
{
//Fill your code here
int f = 0,count=0;
for (int i1 = 0; i1 < size;i1++ )
{
if(arr[i1]<0)
{
f = 1;
}
}
var i = from temp in arr
orderby temp ascending
group temp by temp into temp1
where temp1.Count() > 1
select temp1.Key;
foreach (var result in i)
count++;
if (f == 1)
Console.WriteLine("Array contains negative numbers");
else if (size == count)
{
Console.WriteLine("No repeated numbers");
}
else
{
foreach (var result in i)
Console.WriteLine(result);
}
}
}
REPEATED WORDS
using System;
class Program
{
public static void Main( string[] args )
{
string input1,input2,output;
input1 = Console.ReadLine();
input2 = Console.ReadLine();
output = UserProgramCode.repeatedWords(input1,input2);
Console.WriteLine(output);
Console.ReadKey();
}
}
using System;
using System.Collections;
class UserProgramCode {
public static string repeatedWords(string input1,string input2)
{
input1 = input1 + " ";
input2 = input2 + " ";
ArrayList s1 = new ArrayList();
ArrayList s2 = new ArrayList();
ArrayList intS1 = new ArrayList();
string[] a1 = input1.Split(' ');
string[] a2 = input2.Split(' ');
int i,c=0,j,max=0,flag=0;
string str="";
s1.Add(a1[0]);
for (i = 1; i < a1.Length-1; i++)
{
if (s1.Contains(a1[i]))
return "-1";
else
s1.Add(a1[i]);
}
for (i = 0; i < a2.Length-1; i++)
s2.Add(a2[i]);
for (i = 0; i < s1.Count; i++)
{
for (c=0,j = 0; j < s2.Count; j++)
{
if (a1[i].Equals((string)s2[j],StringComparison.OrdinalIgnoreCase))
{
c++;
}
}
intS1.Add(c);
}
for (i = 0; i < intS1.Count; i++)
{
if ((int)intS1[i] == 0)
flag++;
}
if (flag == intS1.Count)
return "-2";
max = (int)intS1[0];
for (i = 0; i < intS1.Count; i++)
{
if ((int)intS1[i] > max)
{
max = (int)intS1[i];
}
}
for (i = 0; i < s1.Count; i++)
{
if ((int)intS1[i] == max)
{
str = str + a1[i] + " ";
}
}
//Console.ReadKey();
return str.ToLower();
}
}
REPLACE STRING
using System;
class Program
{
public static void Main( string[] args )
{
string inputWord=Console.ReadLine();
int position=Convert.ToInt32(Console.ReadLine());
char ch=Convert.ToChar(Console.ReadLine());
string result=UserProgramCode.replaceString(inputWord,position,ch);
if(result.Equals("-1"))
Console.WriteLine("Invalid String");
else if(result.Equals("-2"))
Console.WriteLine("Number not positive");
else if(result.Equals("-3"))
Console.WriteLine("Character not a special character");
else
Console.WriteLine(result);
}
}
using System;
class UserProgramCode
{
public static string replaceString(string inputWord, int position, char ch)
{
string inputWord1=inputWord.ToLower();
foreach (Char z in inputWord)
{
if (!(Char.IsLetterOrDigit(z) || Char.IsWhiteSpace(z)))
{
return "-1";
}
}
if (position <= 0)
{
return "-2";
}
if ((Char.IsLetterOrDigit(ch)) || Char.IsWhiteSpace(ch))
{
return "-3";
}
else
{
string[] A = inputWord1.Split(' ');
string b = string.Copy(A[position - 1]);
char[] B = b.ToCharArray();
for (int i = 0; i < b.Length; i++)
{
B[i] = ch;
}
string c = new string(B);
A[position - 1] = c;
string d = string.Join(" ", A);
return d;
}
}
}
REVERSE THE ADJACENT PAIR OF LETTERS
using System;
namespace myprograms
{
public class UserProgramCode
{
public static String swapPairs(string input)
{
}
}
}
using System;
namespace myprograms
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
Console.WriteLine(UserProgramCode.swapPairs(input));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace reverse_adjacent_letters
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
char[] ch = s.ToCharArray();
string str = "";
int flag=0;
foreach (char c in ch)
{
if (!char.IsLetter(c))
{
flag = 1;
break;
}
}
if (flag == 0)
{
for (int i = 0; i < ch.Length - 1; i++)
{
if (i % 2 == 0 && ch.Length % 2 == 0)
{
str = str + ch[i + 1].ToString() + ch[i].ToString();
}
if (ch.Length % 2 != 0)
{
if (i % 2 == 0)
{
str = str + ch[i + 1].ToString() + ch[i].ToString();
}
}
}
if (ch.Length % 2 != 0)
{
str = str + ch[ch.Length - 1];
}
Console.WriteLine(str);
Console.ReadLine();
}
else
{
Console.WriteLine("Invalid Character");
Console.ReadLine();
}
}
}
}
namespace myprograms
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
Console.WriteLine(UserProgramCode.swapPairs(input));
}
}
}
using System;
namespace myprograms
{
public class UserProgramCode
{
public static String swapPairs(string input)
{
string str = " ";
char temp;
char[] ch = input.ToCharArray();
for (int i = 0; i < input.Length-1; i++)
{
if (!char.IsLetter(ch[i]))
{
str = "Invalid Input";
goto l;
}
}
l:return str;
}
}
}
}
}
}
Reverse Substring
using System;
class Program
{
public static void Main (string[] args)
{
int l,si;
string s;
s = Console.ReadLine();
si=int.Parse(Console.ReadLine()) ;
l = int.Parse(Console.ReadLine()) ;
Console.WriteLine (UserProgramCode.reverseSubstring(s,si+1,l));
}
}
using System;
Console.WriteLine(A[i]);
}
return b;
}
}
reverse sub-string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main (string[] args)
{
int l,si;
string s;
s = Console.ReadLine();
si=int.Parse(Console.ReadLine()) ;
l = int.Parse(Console.ReadLine()) ;
Console.WriteLine (UserProgramCode.reverseSubstring(s,si,l));
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
sb.Append(ch[j]);
j++;
i++;
}
String str1 = sb.ToString();
return str1;
}
}
class Program
{
public static void Main( string[] args )
{
int salary;
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for(int i=0;i<4;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
salary = UserProgramCode.revisedSalary(arr);
Console.WriteLine(salary);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static int revisedSalary(int[] arr)
{
// fill your code here
int id = arr[0];
int grade = arr[1];
int rating = arr[2];
int sal = arr[3];
int newsal = 0;
if (id >= 100000 && id <= 500000)
{
if (grade == 1)
{
if (rating == 1)
{
newsal = (Int32)(newsal + sal * .15 + sal);
return newsal;
}
else if (rating == 2)
{
newsal = (Int32)(newsal + sal * .1 + sal);
return newsal;
}
else if (rating == 3)
{
newsal = (Int32)(newsal + sal * .05 + sal);
return newsal;
}
else
{
return -3;
}
}
else if (grade == 2)
{
if (rating == 1)
{
newsal = (Int32)(newsal + sal * .1 + sal);
return newsal;
}
else if (rating == 2)
{
newsal = (Int32)(newsal + sal * .05 + sal);
return newsal;
}
else if (rating == 3)
{
newsal = (Int32)(newsal + sal * .02 + sal);
return newsal;
}
else
{
return -3;
}
}
else if (grade == 3)
{
if (rating == 1)
{
newsal = (Int32)(newsal + sal * .07 + sal);
return newsal;
}
else if (rating == 2)
{
newsal = (Int32)(newsal + sal * .01 + sal);
return newsal;
}
else if (rating == 3)
{
newsal = (Int32)(newsal + sal * .02 + sal);
return newsal;
}
else
{
return -3;
}
}
return -2;
}
else
{
return -1;
}
}
}
roman numbersum
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace roman_numbersum
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string");
string s = Console.ReadLine();
int sum=0;
string roman = "IVXLCDMivxlcdm";
foreach (char c in s)
{
if (roman.Contains(c))
{
switch (c)
{
case 'I': sum += 1;
break;
case 'i': sum += 1;
break;
case 'X': sum += 10;
break;
case 'x': sum += 10;
break;
case 'V': sum += 5;
break;
case 'v': sum += 5;
break;
case 'L': sum += 50;
break;
case 'l': sum += 50;
break;
case 'C': sum += 100;
break;
case 'c': sum += 100;
break;
case 'D': sum += 500;
break;
case 'd': sum += 500;
break;
case 'M': sum += 1000;
break;
case 'm': sum += 1000;
break;
}
}
else
{
continue;
}
}
Console.WriteLine("sum:"+sum);
Console.ReadLine();
}
}
}
Roman to decimal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace roman_to_decimal
{
class Program
{
static void Main(string[] args)
{
int a,b,c,d,e;
switch (a)
{
case 1000: Console.Write("M");
break;
case 2000: Console.Write("MM");
break;
case 3000: Console.Write("MMM");
break;
case 4000: Console.Write("MMMM");
break;
}
switch (b)
{
case 100: Console.Write("C");
break;
case 200: Console.Write("CC");
break;
case 300: Console.Write("CCC");
break;
case 400: Console.Write("CD");
break;
case 500: Console.Write("D");
break;
case 600: Console.Write("DC");
break;
case 700: Console.Write("DCC");
break;
case 800: Console.Write("DCCC");
break;
case 900: Console.Write("CM");
break;
}
switch (c)
{
case 10: Console.Write("X");
break;
case 20: Console.Write("XX");
break;
case 30: Console.Write("XXX");
break;
case 40: Console.Write("XL");
break;
case 50: Console.Write("L");
break;
case 60: Console.Write("LX");
break;
case 70: Console.Write("LXX");
break;
case 80: Console.Write("LXXX");
break;
case 90: Console.Write("CX");
break;
}
switch (d)
{
case 1: Console.Write("I");
break;
case 2: Console.Write("II");
break;
case 3: Console.WriteLine("III");
break;
case 4: Console.Write("IV");
break;
case 5: Console.Write("V");
break;
case 6: Console.Write("VI");
break;
case 7: Console.Write("VII");
break;
case 8: Console.Write("VIII");
break;
case 9: Console.Write("IX");
break;
}
}
else
{
Console.WriteLine("invalid input");
}
Console.ReadLine();
}
}
}
Salary
using System;
class Program
{
public static void Main( string[] args )
{
int experience,oldSalary,salary;
string expertise;
experience = Convert.ToInt32(Console.ReadLine());
expertise = Console.ReadLine();
oldSalary = Convert.ToInt32(Console.ReadLine());
salary = UserProgramCode.calculateNewSalary(experience,expertise,oldSalary);
if(salary == -1)
Console.WriteLine("Invalid Experience");
else if(salary == -2)
Console.WriteLine("Invalid Technology expertise classification");
else if(salary == -3)
Console.WriteLine("Invalid Salary");
else
Console.WriteLine("Your Salary is fixed as Rs {0}",salary);
Console.ReadLine();
}
}
using System;
class Program
{
public static void Main(string[] args)
{
int experience, oldSalary, salary;
string expertise;
experience = Convert.ToInt32(Console.ReadLine());
expertise = Console.ReadLine();
oldSalary = Convert.ToInt32(Console.ReadLine());
salary = UserProgramCode.calculateNewSalary(experience, expertise,
oldSalary);
if (salary == -1)
Console.WriteLine("Invalid Experience");
else if (salary == -2)
Console.WriteLine("Invalid Technology expertise classification");
else if (salary == -3)
Console.WriteLine("Invalid Salary");
else
Console.WriteLine("Your Salary is fixed as Rs {0}", salary);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int calculateNewSalary(int experience,string expertise,int oldSalary)
{
double sal = 0,ctr=0,sa=0;
if (experience > 25 || experience < 0)
{
sa = -1;
ctr++;
}
if (expertise != "RS" && expertise != "CS")
{
sa = -2;
ctr++;
}
if (oldSalary > 100000 || oldSalary < 0)
{
sa = -3;
ctr++;
}
if(ctr==0)
{
sal = sal + (oldSalary * 0.3);
if (experience > 3 && experience <= 5)
{
sal = sal + (oldSalary * 0.05);
}
else if (experience > 5 && experience <= 8)
{
sal = sal + (oldSalary * 0.10);
}
else if (experience > 8)
{
sal = sal + (oldSalary * 0.15);
}
if(expertise=="RS")
{
sal=sal+(oldSalary*0.05);
}
sal = sal + oldSalary;
sa = Math.Round(sal);
}
return (int)sa;
}
}
sequence
using System;
class Program
{
public static void Main( string[] args )
{
string inputValue=Console.ReadLine();
int k = UserProgramCode.countSequentialChars(inputValue);
if(k == -1)
Console.WriteLine("No Repeated Words Found");
else
Console.WriteLine(k);
Console.ReadKey();
}
}
using System;
class UserProgramCode
{
public static int countSequentialChars(string input1)
{
string x = input1;
int i,c=0;
for (i = 0; i <= x.Length-3; i++)
{
if (x[i] == x[i + 1] && x[i + 1] == x[i+2])
c = 3;
else
continue;
}
if (c == 3)
return 3;
else
return -1;
}
}
Series
using System;
class Program
{
public static void Main( string[] args )
{
int input;
input = Convert.ToInt32(Console.ReadLine());
int result = UserProgramCode.addSeries(input);
Console.WriteLine(result);
Console.Read();
}
}
using System;
class UserProgramCode {
public static int addSeries(int input1) {
int i = 1, sum = 1, j = 1;
}
}
Shortest String
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ruff
{
class Program
{
static void Main(string[] args)
{
int a = int.Parse(Console.ReadLine());
List<string> str = new List<string>(a);
for (int i = 0; i < a; i++)
{
string x=Console.ReadLine();
str.Add(x);
}
char ch = char.Parse(Console.ReadLine());
string s = userProgramCode.GetshortestString(str, ch);
Console.WriteLine(s);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ruff
{
class userProgramCode
{
public static string GetshortestString(List<string> input1, char input2)
{
string outp="";
}
}
if (ctr1 != 0)
{
int min = len.Min();
for (int i = 0; i < len.Count; i++)
{
if (len[i] == min && ctr == 0)
{
outp += input1[i];
}
}
}
}
return outp;
}
}
}
shortest word
using System;
using System.Collections.Generic;
using System.Collections;
namespace myprograms
{
public class UserProgramCode
{
public static string GetshortestString(List<string> input1, char input2)
{
int i,min,c=0;string strmin;
ArrayList al = new ArrayList();
for (i = 0; i < input1.Count; i++)
{
if ((input1[i])[0] >= 'a' && (input1[i])[0] <= 'z')
{
continue;
}
else
c = 1;
}
if (c == 0)
{
for (i = 0; i < input1.Count; i++)
{
if ((input1[i])[0] == input2)
{
al.Add(input1[i]);
}
}
if (al.Count == 0)
{
return "No String Found";
}
min = ((string)al[0]).Length;
strmin = (string)al[0];
for (i = 0; i < al.Count; i++)
{
if (((string)al[i]).Length < min)
{
min = ((string)al[i]).Length;
strmin = (string)al[i];
}
}
return strmin;
}
else
return "Non Alphabets Exists";
}
}
}
using System;
using System.Collections.Generic;
namespace myprograms
{
class Program
{
static void Main(string[] args)
{
List<string> input1 = new List<string>();
int n = Convert.ToInt32(Console.ReadLine());
char secondString ;
for (int i = 0; i < n; i++)
{
input1.Add(Console.ReadLine());
}
secondString = Convert.ToChar(Console.ReadLine());
Console.WriteLine( UserProgramCode.GetshortestString(input1, secondString));
Console.ReadKey();
}
}
}
sort after a no select
using System;
using System.Collections.Generic;
namespace myprograms
{
class UserProgramCode
{
li1.Sort();
li1.Reverse();
}
else
{
Console.WriteLine("No element found");
}
return li1;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace myprograms
{
class Program
{
public static void Main(){
int size;
size = int.Parse(Console.ReadLine());
List<int> input1 = new List<int>();
for(int i=0;i<size;i++){
int v = int.Parse(Console.ReadLine());
input1.Add(v);
}
int input2 = int.Parse(Console.ReadLine());
List<int> output = new List<int>();
output = UserProgramCode.GetElements(input1,input2);
if(output.Count == 1 && output[0] == -1)
Console.WriteLine("No element found");
else
{
foreach(int i in output){
Console.WriteLine(i);
}
}
}
}
}
string Encription
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace string_Encription
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
char[] ar = str.ToCharArray();
StringBuilder sb = new StringBuilder();
char[] dar = ar.Distinct().ToArray();
}
}
}
String Manipulation
using System;
using System.Collections.Generic;
class UserProgramCode
{
class Program
{
public static void Main( string[] args )
{
string str1=Console.ReadLine();
string str2=Console.ReadLine();
Console.WriteLine(UserProgramCode.stringManipulation(str1,str2));
Console.ReadKey();
}
}
String Occurance
using System;
class UserProgramCode
{
public static int countNoOfWords(string str1,string str2)
{
string[] sub1=str1.Split(' ');
string[] sub2 = str2.Split(' ');
int ctr=0;
}
return ctr;
}
}
using System;
class Program
{
public static void Main( string[] args )
{
string str1=Console.ReadLine();
string str2=Console.ReadLine();
Console.WriteLine(UserProgramCode.countNoOfWords(str1,str2));
Console.ReadLine();
}
}
String Processing 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dumps
{
class UserMainCode
{
static void Main(string[] args)
{
getString(Console.ReadLine(), int.Parse(Console.ReadLine()));
Console.ReadKey();
}
public static void getString(string input1, int input2)
{
int c1 = 0, c2 = 0;
string p = input1;
if (input1.Length < input2)
Console.WriteLine("-3");
else
{
int i;
for (i = 0; i < p.Length; i++)
{
if (input1[i] >= '0' && input1[i] <= '9')
{
c1 = 1;
Console.WriteLine("-1");
break;
}
else if ((input1[i] >= 'a' && input1[i] <= 'z') || (input1[i] >= 'A' &&
input1[i] <= 'Z'))
{
}
else
{
c2 = 1;
Console.WriteLine("-2");
break;
}
}
if (c1 == 0 && c2 == 0)
{
string str = input1.Substring((input1.Length - input2));
for (i = 1; i <= input2; i++)
{
input1 = input1 + str;
}
Console.WriteLine(input1);
}
}
}
}
}
String Reversal
using System;
class UserProgramCode {
public static string reverseString(string input)
{
string[] sa = input.Split(' ');
string s="";
foreach (string ins in sa)
{
for (int i = ins.Length-1; i >=0;i-- )
{
int c = Convert.ToInt32(ins[i]);
if (c >= 97 && c < 122)
{
s += ins[i];
}
else
return "-1";
}
s+= " ";
}
return s;
}
}
using System;
class Program
{
public static void Main( string[] args )
{
string input = Console.ReadLine();
string output = UserProgramCode.reverseString(input);
if(output == "-1")
Console.WriteLine("Invalid Input");
else
Console.WriteLine(output);
Console.ReadKey();
}
string_having_maxnoofvowels_in_a_sentence
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace mallika_exam
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
string[] arr = str.Split(' ');
int max = 0, lenmax = 0,count;
//int pos=0,j=0;
foreach (string element in arr)
{
char[] ch = element.ToCharArray();
count = 0;
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u')
count++;
}
if (count > max)
{
max = count;
//pos = j;
lenmax = ch.Length;
}
//j++;
}
Console.ReadLine();
}
}
}
StringEncryption
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringEncryption
{
class UserProgramCode
{
public static string encrypt(string input)
{
string output="";
for(int i=0;i<input.Length;i++)
{
if (char.IsLetter(input[i]))
{
if (i % 2 == 0)
{
if (input[i] == 'z')
{
output += 'a';
}
else
{
output += (char)(input[i] + 1);
}
}
else
{
output += input[i];
}
}
}
return output;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringEncryption
{
class UserProgramCode
{
public static string encrypt(string input)
{
string output="";
for(int i=0;i<input.Length;i++)
{
if (char.IsLetter(input[i]))
{
if (i % 2 == 0)
{
if (input[i] == 'z')
{
output += 'a';
}
else
{
output += (char)(input[i] + 1);
}
}
else
{
output += input[i];
}
}
}
return output;
}
}
}
Stringfinder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int stringFinder(string str, string firststr, string secondstr)
{
//Fill your code here
int t1 = str.IndexOf(firststr);
int t2 = str.IndexOf(secondstr);
if (t1 < t2)
return 1;
else
return 2;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace stringfinder
{
class Program
{
public static void Main( string[] args )
{
string str=Console.ReadLine();
string firststr=Console.ReadLine();
string secondstr=Console.ReadLine();
int result=UserProgramCode.stringFinder(str,firststr,secondstr);
if(result==2)
Console.WriteLine("No");
else
Console.WriteLine("Yes");
}
}
}
Stringfirstupperandallotherlower
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace stringfirstupperandallotherlower
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string strn = "";
string[] a = s.Split(' ');
Console.WriteLine(strn);
Console.ReadLine();
}
}
StringOccurences
using System;
class UserProgramCode
{
public static int countNoOfWords(string str1,string str2)
{
// fill your code here
}
}
using System;
class Program
{
public static void Main( string[] args )
{
string str1=Console.ReadLine();
string str2=Console.ReadLine();
Console.WriteLine(UserProgramCode.countNoOfWords(str1,str2));
}
}
find lowest :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program2
{
class Program
{
public static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (int i = 0; i < size; i++)
arr[i] = Convert.ToInt32(Console.ReadLine());
int output = UserProgramCode.findLowest(arr);
if (output == -1)
Console.WriteLine("Negative numbers present");
else
Console.WriteLine(output);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program2
{
class UserProgramCode
{
public static int findLowest(int[] array)
{
int res=0,low=array[0];
foreach (var a in array)
{
if (a < 0)
{
res=-1;
return res;
}
else if(a<low)
{
res = a;
}
}
return res;
}
}
}
----------------------------------------------------------------------------------------FIND RESULT
using System;
namespace myprograms
{
class Program
{
Console.ReadLine();
}
}
}
using System;
namespace myprograms
{
class UserProgramCode
{
}
else if (input1 >= 65 && input2 < 45)
{
return "R";
}
else
return "F";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace finddatedifferenceinmonths
{
class Program
{
static void Main(string[] args)
{
string str1 = Console.ReadLine();
string str2=Console.ReadLine();
string format = "dd/MM/yyyy";
DateTime date1;
DateTime date2;
bool res=(DateTime.TryParseExact(str1, format, CultureInfo.InvariantCulture,
DateTimeStyles.None, out date1));
bool res1=(DateTime.TryParseExact(str2, format,
CultureInfo.InvariantCulture, DateTimeStyles.None, out date2));
int m = 0;
if(res==true && res1==true)
{
if (date1 < date2)
{
DateTime x=date1;
while (x <= date2)
{
x = x.AddMonths(1);
if(x<=date2)
m++;
}
}
else if (date2 < date1)
{
DateTime x = date2;
while (x <= date1)
{
x = x.AddMonths(1);
if (x <= date1)
m++;
}
}
}
Console.WriteLine(m);
Console.ReadLine();
}
}
}
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int[] FindCommonElements(int[] ar1, int[] ar2, int[] ar3)
{
int[] c1 = new int[ar1.Length];
int k = 0;
for (int i = 0; i < ar1.Length; i++)
{
if (ar1[i] % 3 == 0)
{
c1[k] = ar1[i];
k++;
}
}
int[] c2 = new int[ar2.Length];
k = 0;
for (int i = 0; i < ar2.Length; i++)
{
if (ar2[i] % 3 == 0)
{
c2[k] = ar2[i];
k++;
}
}
int[] c3 = new int[ar3.Length];
k = 0;
for (int i = 0; i < ar3.Length; i++)
{
if (ar3[i] % 3 == 0)
{
c3[k] = ar3[i];
k++;
}
}
int[] result = new int[c1.Length];
int l = 0;
result[l] = a;
l++;
}
}
}
if (result.Length == 0)
{
result[0] = 0;
return result;
}
for (int i = 0; i < result.Length; i++)
{
for (int j = i + 1; j < result.Length; j++)
{
if (result[i] < result[j])
{
int temp = result[i];
result[i] = result[j];
result[j] = temp;
}
}
}
return result;
}
----------------------------------------------------------------------------------------findLargestDigit
using System;
class Program
{
public static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
int result = UserProgramCode.findLargestDigit(num);
if (result == -1)
Console.WriteLine("Negative Number");
else
Console.WriteLine(result);
}
}
using System;
class UserProgramCode
{
public static int findLargestDigit(int num)
{
int temp=0,rem=0,output=0;
temp = num;
if (temp < 0)
{
return -1;
}
else
{
while (temp > 0)
{
rem = temp % 10;
if(rem>=output)
output = rem;
temp = temp / 10;
}
}
return output;
}
}
----------------------------------------------------------------------------------------findlowest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace findlowest
{
class Program
{
public static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (int i = 0; i < size; i++)
arr[i] = Convert.ToInt32(Console.ReadLine());
int output = UserProgramCode.findLowest(arr);
if (output == -1)
Console.WriteLine("Negative numbers present");
else
Console.WriteLine(output);
}
}
}
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int findLowest(int[] array)
{
//Fill your code here
int l = array.Length;
int outpt = 0, small = array[0], i, flag = 0;
for (i = 0; i < l; i++)
{
if (array[i] < 0)
{
flag = 1;
break;
}
}
if (flag == 1)
{
outpt = -1;
}
else
{
for (i = 1; i < l; i++)
{
if (array[i] < small)
small = array[i];
}
outpt = small;
}
return outpt;
}
}
----------------------------------------------------------------------------------------findResult
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace eligible
{
class Program
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.FindResult(a,b));
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
}
}
----------------------------------------------------------------------------------------FIXED POINT
using System;
class Program
{
int n = Convert.ToInt32(Console.ReadLine());
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = Convert.ToInt32(Console.ReadLine());
int result=UserProgramCode.findFixedpoint(array);
Console.WriteLine(result);
Console.Read();
using System;
class UserProgramCode
{
public static int findFixedpoint(int[] input)
{
Array.Sort(input);
int res=0;
int count=0;
foreach (int k in input)
{
//Console.WriteLine(k);
if (k < 0)
{
count++;
return -1;
}
}
if (input.Length < 2 || input.Length > 10)
{
count++;
return -3;
}
if (count == 0)
{
int i = 1;
foreach(int k in input)
{
if (k==i)
res = i-1;
i++;
}
if (res == 0)
res = -2;
}
return res;
}
}
Console.WriteLine(UserProgramCode.formNewWord(word, n));
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
return str1;
}
----------------------------------------------------------------------------------------formnewWord
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
static void Main(string[] args)
{
Console.WriteLine(UserProgramCode.formNewWord(word, n));
Console.ReadLine();
}
}
----------------------------------------------------------------------------------------GCD Array
using System;
class Program
int size,result;
size = Convert.ToInt32(Console.ReadLine());
for(int i=0;i<size;i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
result = UserProgramCode.greatestCommonDivisor(arr);
Console.WriteLine(result);
using System;
class UserProgramCode
{
public static int greatestCommonDivisor(int[] arr)
{
Array.Sort(arr);
int gcd = arr[0];
do
{
int count = 0;
for (int i = 1; i < arr.Length; i++)
{
if (arr[i] % gcd == 0)
{
count++;
}
else
break;
}
if (count == arr.Length - 1)
break;
gcd--;
} while (gcd < 1);
return gcd;
}
}
class Program
{
public static void Main(string[] args)
{
int size, val;
size = Convert.ToInt32(Console.ReadLine());
int[] array = new int[size];
for (int i = 0; i < size; i++)
{
val = Convert.ToInt32(Console.ReadLine());
array[i] = val;
}
Console.WriteLine(UserProgramCode.getBigDiff(array));
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int getBigDiff(array)
using System;
using System.Collections.Generic
;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int getBigDiff(array)
int[] array1=array;
int max,min,result;
// n = Convert.ToInt32(Console.ReadLine());
//{
// array[i] = Convert.ToInt32(Console.ReadLine());
//}
max=
min=array[0];
for(int j=1;j<array.Length;j++)
{
if(array[j]>max)
{
max = array[j];
}
else if(array[j]<min)
{
min = array[j];
}
}
return result;
----------------------------------------------------------------------------------------Get Grade
using System;
class Program
{
public static void Main( string[] args )
{
int size;
size = Convert.ToInt32(Console.ReadLine());
if (size < 0)
{
Console.WriteLine("Invalid Input");
}
int[] arr = new int[size];
for(int i = 0;i<size;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
string result = UserProgramCode.getGrade(arr);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Class16
{
public static int output;
int output = 0;
str1 = str1.ToUpper();
str2 = str2.ToUpper();
string[] st = str2.Split(' ', ',');
foreach (string s in st)
{
if (str1.Equals(s))
output++;
}
return output;
}
}
if (x > 0)
{
Console.WriteLine("output: 2");
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
namespace myprograms
class Program
for(int i=0;i<size;i++)
{
input1.Add(Console.ReadLine());
Console.WriteLine(UserProgramCode.GetLongestString(input1,input2));
using System;
using System.Collections.Generic;
namespace myprograms
{
class UserProgramCode{
public static String GetLongestString(List<String> input1,char input2){
int a = (int)input2;
int b;
if (a <= 90)
{
b = a + 32;
}
else
b = a - 32;
char c1 = Convert.ToChar(a);
char c2 = Convert.ToChar(b);
// Console.WriteLine(c2);
List<string> ls = new List<string>();
/// string[] tmp = new string[input1.Count];
int flag = 0;
String ans =null;
foreach (string s in input1)
{
foreach (char c in s)
{
if (!char.IsLetterOrDigit(c))
{
flag = 2;
break;
}
if(flag==2)
break;
}
}
if(flag !=2)
{
foreach (string s in input1)
{
if (s.StartsWith(Convert.ToString(c1)) ||
s.StartsWith(Convert.ToString(c2)))
{
ls.Add(s);
flag = 1;
}
if (flag == 1)
{
int max = ls[0].Length;
ans = ls[0];
foreach (string s in ls)
{
if (s.Length > max)
{
max = s.Length;
ans = s;
}
}
}
}
if(flag ==2)
{
return "String contains non alphabetic characters.";
}
else
return ans;
}
}
}
using System;
class Program
{
public static void Main( string[] args )
{
int size=Convert.ToInt32(Console.ReadLine());
int[] arr=new int[size];
for(int i=0;i<size;i++)
arr[i]=Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getMaxSpan(size,arr));
Console.ReadKey();
}
}
using System;
class UserProgramCode
{
public static int getMaxSpan(int size,int[] arr)
{
int ind2 = 0, c = 0;
if (size == 1)
{
return 1;
}
if (i == 0 && c != 0)
return ind2 - i;
return 0;
}
}
----------------------------------------------------------------------------------------GetAllElements
using System;
using System.Collections.Generic;
class Program
{
public static void Main( string[] args )
{
int size=Convert.ToInt32(Console.ReadLine());
List<int> li = new List<int>();
using System;
using System.Collections.Generic;
class UserProgramCode
{
public static List<int> GetAllElements(List<int> li,int size)
{
// fill your code here
List<int> outli = new List<int>();
}
else if (num > 5)
outli.Add(num);
else
continue;
}
return outli;
}
}
----------------------------------------------------------------------------------------getBigdiff
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
{
int size, val;
size = Convert.ToInt32(Console.ReadLine());
val = Convert.ToInt32(Console.ReadLine());
array[i] = val;
Console.WriteLine(UserProgramCode.getBigDiff(array));
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
max=
min=array[0];
for(int j=1;j<array.Length;j++)
{
if(array[j]>max)
{
max = array[j];
}
else if(array[j]<min)
{
min = array[j];
}
}
}
}
----------------------------------------------------------------------------------------getcount
using System;
class Program
{
public static void Main(string[] args)
{
int size = 0, i;
char ch;
size = Convert.ToInt32(Console.ReadLine());
string[] arr = new string[size];
for (i = 0; i < size; i++)
{
arr[i] = Console.ReadLine();
}
ch = Convert.ToChar(Console.ReadLine());
int f = UserProgramCode.GetCount(size, arr, ch);
if (f == -1)
{
Console.WriteLine("No elements Found");
}
else if (f == -2)
{
Console.WriteLine("Only alphabets should be given");
}
else
{
Console.WriteLine(f);
}
}
}
using System;
class UserProgramCode
{
public static int GetCount(int size,string[] arr,char ch)
{
int count=0;
{
foreach (char i in item)
{
if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z'))
{
}
else
{
return -2;
}
}
string item1=item.ToLower();
char[] a=item1.ToCharArray();
if(ch>='A' && ch<='Z')
ch=(char)((int)ch+32);
if(ch>='a' && ch<='z')
{
if(a[0]==ch)
count++;
}
else
return -2;
}
if(count>0)
return count;
if (count == 0)
return -1;
return 0;
}
----------------------------------------------------------------------------------------GetLongestString
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetLongestString
{
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt16(Console.ReadLine());
string key;
List<string> arr = new List<string>(size);
for (int i = 1; i <=size; i++)
{
arr.Add(Console.ReadLine());
}
key = Console.ReadLine();
string result = UserProgramCode.getLongestString(arr, key);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetLongestString
{
class UserProgramCode
{
public static string getLongestString(List<string> array, string key)
{
string result="";
int count = 0;
foreach (string item in array)
{
if (item.All(Char.IsLetter))
{
if (item.StartsWith(key))
{
if (item.Length > result.Length)
{
result = item;
}
count++;
}
if (count == 0)
{
result = "no elements found";
}
}
else
result = "string contains alphanumerics";
}
return result;
}
}
}
----------------------------------------------------------------------------------------getmaxspan
using System;
class Program
{
public static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (int i = 0; i < size; i++)
arr[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getMaxSpan(size, arr));
}
}
using System;
class UserProgramCode
{
public static int getMaxSpan(int size, int[] arr)
{
int ind2=0, c=0;
if (size == 1)
{
return 1;
}
if (i == 0 && c != 0)
return ind2 - i;
}
return 0;
}
----------------------------------------------------------------------------------------getWordWithMaximumVowels
using System;
class Program
{
public static void Main( string[] args )
{
string input = Console.ReadLine();
string result = UserProgramCode.getWordWithMaximumVowels(input);
Console.WriteLine(result);
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static string getWordWithMaximumVowels(string inpt)
{
string result = "";
int maxvowels = 0;
string input=inpt.ToLower();
----------------------------------------------------------------------------------------Gyrating Numbers
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserMainCode
{
public static int Gyrating(int[] ar)
{
int countup=0, countdown=0;
int n = ar.Length;
for(int i=0;i<ar.Length-1;i++)
{
if (ar[i] < 0)
return -2;
else if (ar[i] > ar[i + 1])
{
countup++;
}
else if (ar[i] < ar[i + 1])
countdown++;
else
return -1;
}
if ((countup == n - 1) || (countdown == n - 1))
{
return 1;
}
return 0;
}
}
-------------------------------------------------------------------------
image---
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace image
{
class Program
{
static void Main(string[] args)
{
string str=Console.ReadLine();
string str1=null;
int c = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i].Equals('x'))
{
c++;
continue;
}
else
str1 = str1 + str[i];
while (c != 0)
{
str1 = str1 + 'x';
c--;
}
Console.WriteLine(str1);
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace image
{
class userProgramcode
{
public static List<string> imagescount(List<string> input1)
{
int k = 0,ctr=0;
string[] ar=new string[8]{"jpeg","jfif","exif","tiff","raw","gif","bmp","png"};
List<string> outp = new List<string>();
string[] st = new string[input1.Count];
int[] sco = new int[input1.Count];
st[k] = arr[1];
sco[k] = sco[k] + 1;
k++;
}
else if (arr.Length == 2 && st.Contains(arr[1]) && ar.Contains(arr[1]) )
{
for (int p = 0; p < st.Length; p++)
{
if (st[p] == arr[1])
{
sco[p] = sco[p] + 1;
break;
}
}
}
else
{
ctr++;
}
}
if (ctr != input1.Count)
{
return outp;
}
}
}
------------------------------------------------------------------------image format
using System;
using System.Collections;
using System.Collections.Generic;
class Program
{
public static void Main( string[] args )
{
int size=0,i;
size=Convert.ToInt32(Console.ReadLine());
string[] arr = new string[size];
for(i=0;i<size;i++){
arr[i] = Console.ReadLine();
}
List<string> output = new List<string>();
output = (List<string>)UserProgramCode.countImageTypes(arr);
for(i=0;i<output.Count;i++){
Console.WriteLine(output[i]);
}
}
}
using System;
using System.Collections.Generic;
class UserProgramCode
{
public static List<string> countImageTypes(string[] input)
{
string[] a = { "jpeg", "jfif", "exif", "tiff", "raw", "gif", "bmp", "png","others" };
int[] count = new int[a.Length];
string[]input1=new string[input.Length];
int i,j;
string[] f=new string[2];
string x = "";
List<string> lt = new List<string>();
//List<string> c = null;
for (i = 0; i < input.Length; i++)
{
x = " ";
int y = input[i].IndexOf('.');
if (y == -1)
x = "others";
else
{
x = input[i].Substring((y + 1), input[i].Length - y - 1);
}
input1[i] = x;
}
for (i = 0; i < a.Length; i++)
{
for (j = 0; j < input1.Length; j++)
{
if (a[i].Equals(input1[j]))
{
count[i] = count[i] + 1;
}
}
}
for (i = 0; i < a.Length; i++)
{
if (count[i] > 0)
{
lt.Add(a[i]);
lt.Add(count[i]+"");
}
}
//Console.ReadKey();
return lt;
}
}
------------------------------------------------------------------------ImageTypes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace image
{
class Program
{
static void Main(string[] args)
{
int a = int.Parse(Console.ReadLine());
List<string> image = new List<string>();
for (int i = 0; i < a; i++)
{
image.Add(Console.ReadLine());
}
List<string> ouyp = userProgramcode.imagescount(image);
Console.WriteLine(s);
}
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace image
{
class userProgramcode
{
public static List<string> imagescount(List<string> input1)
{
int k = 0,ctr=0;
string[] ar=new string[8]{"jpeg","jfif","exif","tiff","raw","gif","bmp","png"};
List<string> outp = new List<string>();
string[] st = new string[input1.Count];
int[] sco = new int[input1.Count];
for (int j = 0; j < input1.Count; j++)
{
string[] arr = input1[j].Split('.');
if (arr.Length==2 && !st.Contains(arr[1]) && ar.Contains(arr[1]) )
{
st[k] = arr[1];
sco[k] = sco[k] + 1;
k++;
}
}
}
if (ctr != input1.Count)
{
int[] co = new int[k];
co = sco.ToArray();
sco = co.Distinct().ToArray();
Array.Sort(sco);
Array.Reverse(sco);
if (sco[m] == co[n])
{
outp.Add(st[n]);
outp.Add(sco[m].ToString());
}
}
}
}
if (ctr != 0 && ctr!=input1.Count)
{
outp.Add("Others");
outp.Add(ctr.ToString());
}
else if (ctr == input1.Count)
{
outp.Add("-1");
return outp;
}
return outp;
}
}
------------------------------------------------------------------------initial format
using System;
class Program
{
public static void Main( string[] args )
{
string name=Console.ReadLine();
string result = UserProgramCode.nameFormatter(name);
Console.WriteLine(result);
Console.Read();
}
}
using System;
class UserProgramCode
{
public static string nameFormatter(string name)
{
string result="";
string[] array = name.Split();
result = array[1] +","+ array[0].Substring(0, 1);
return result;
}
}
------------------------------------------------------------------------insuranceguide
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main(string[] args)
{
char health = Convert.ToChar(Console.ReadLine());
int age = Convert.ToInt32(Console.ReadLine());
char gender = Convert.ToChar(Console.ReadLine());
char location = Convert.ToChar(Console.ReadLine());
UserProgramCode.InsuranceGuide(health, age, gender, location);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static void InsuranceGuide(char health, int age, char gender, char location)
{
//Fill your code here
if (health == 'E' && age >= 25 && age <= 35 && location == 'C' && gender
== 'M')
{
Console.WriteLine(4);
Console.WriteLine(200000);
}
else if (health == 'E' && age >= 25 && age <= 35 && location == 'C' &&
gender == 'F')
{
Console.WriteLine(3);
Console.WriteLine(100000);
}
else if (health == 'P' && age >= 25 && age <= 35 && location == 'V' &&
gender == 'M')
{
Console.WriteLine(6);
Console.WriteLine(10000);
}
else if(age>=60)
Console.WriteLine("Age limit Exceeded");
else
Console.WriteLine("The person cannot be insured");
}
}
-------------------------------------------------------------------------
Interleaved words
Page of
Interleaved Words
Interleaved Words
Given three input strings input1,input2 and input3, write a program to check
whether input3 string is an interleaved word of input1 and input2 strings (i.e. input3
= concatenation of input1 and input2 strings,such that input2 string is
concatenated at the end of the input1 string eg. if 'game' is input1 and 'center' is
input2,input3 should be equivalent to 'gamecenter' and not 'centergame').
If its a interleaved word, then print the following :
Replace input1, input2 and input3 with the corresponding inputs. Ignore case
sensitiveness in input and use lowercase to print the output.
Business rule:
1) If input1 or input2 strings contains any number, then print -1.
2) If both input1 and input2 strings are same, then print -2.
3) If input1 or input2 contains any special characters, then print -3.
Create a class named UserProgramCode that has the following static method
Refer business rules and sample output for output formatting specifications.
Sample Input 1 :
foreign
land
foreignland
Sample Output 1 :
Sample Input 2 :
string1
set
string1set
Sample Output 2 :
-1
int s3 = s1 - s2;
var a = input1.Remove(0,s3);
output = a + input2;
}
else
{
int s3 = s2 - s1;
var a = input2.Remove(0,s3);
output = input1 + a;
}
}
return output;
}
-------------------------------------------------------------------------
ip address validation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ip_address_validation
{
class Program
{
static void Main(string[] args)
{
//
Regex reg = new Regex("([0-1][0-9][0-9]){3}|([2][0-4][0-9]){3}[.]([0-1][09][0-9]){1,3}|([2][0-4][0-9]){3}[.]([0-1][0-9][0-9]){1,3}|([2][0-4][0-9]{3})[.]([0-1][09][0-9]){3}|([2][0-4][0-9]){3}");
// Regex reg1 = new Regex("[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}|[0]
{1,2}[0-9][.][0]{1,2}[0-9][.][0]{1,2}[0-9][.][0]{1,2}[0-9]|[0-9]{3}[.][0-9]{1}[.][0-9]
{1}[.][0-9]{1}|[2][5][0-5]{1,3}[.][2][5][0-5]{1,3}[.][2][5][0-5]{1,3}[.][2][5][0-5]
{1,3}");
// Regex reg2 = new Regex(@"(\d{1})[.](\d{1})[.](\d{1,3})[.](\d{1,3})");
string s = Console.ReadLine();
Regex reg = new Regex("^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[.]([01]?[09]?[0-9]|2[0-4][0-9]|25[0-5])[.]([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[.]([01]?[0-9]?[09]|2[0-4][0-9]|25[0-5])$");
if( reg.IsMatch(s))
{
Console.WriteLine("Valid IP");
}
else
{
Console.WriteLine("Invalid Ip");
}
Console.ReadLine();
}
}
}
-------------------------------------------------------------------------
IPAddressValid
using System;
class Program
{
public static void Main( string[] args )
{
string ipadress = Console.ReadLine();
Console.WriteLine(UserProgramCode.CheckValidIp(ipadress));
Console.Read();
}
}
using System;
using System.Net;
class UserProgramCode {
public static string CheckValidIp(String input1)
{
string result="";
IPAddress ip;
if (IPAddress.TryParse(input1, out ip))
result = "Valid";
else
result = "Invalid";
return result;
// fill code here
}
}
------------------------------------------------------------------------ipValidator
using System;
class Program
{
public static void Main(string[] args)
{
String ip = Console.ReadLine();
int result = UserProgramCode.ipValidator(ip);
if (result == 1)
Console.WriteLine("Valid");
else
Console.WriteLine("Invalid");
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int ipValidator(String input)
{
//Fill your code here
string str = input;
int status = 0;
for (int i = 0; i < str.Length; i++)
{
if (!(char.IsDigit(str[i]) || str[i] == '.'))
{
status = 1;
break;
}
}
string[] sarr = str.Split('.');
if (sarr.Length != 4)
{
status = 1;
}
if (status != 1)
{
if (!(int.Parse(sarr[0]) >= 1 && int.Parse(sarr[0]) <= 255))
{
status = 1;
}
}
if (status != 1)
{
for (int j = 1; j < sarr.Length; j++)
{
if (!(int.Parse(sarr[j]) >= 0 && int.Parse(sarr[j]) <= 255))
{
status = 1;
break;
}
}
}
if (status == 1)
return 0;
else
return 1 ;
--------------------------------------------------------------------------IsNot
using System;
class Program
{
public static void Main( string[] args )
{
String str=Console.ReadLine();
Console.WriteLine(UserProgramCode.negativeString(str));
Console.ReadLine();
}
}
class UserProgramCode
{
public static string negativeString (string str)
{
string s,n;
s = str;
----------------------------------------------------------------------largestvowelword
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace largestvowelword
{
class Program
{
static void Main(string[] args)
{
string s;
s = Console.ReadLine();
string s1="aeiou";
{ count[j]++;}
}
}
int maxValue = count.Max();
Console.ReadLine();
}
}
}
----------------------------------------------------------------------LEADER
using System;
using System.Collections.Generic;
class Program
{
public static void Main( string[] args )
{
int size;
List<int> opli = new List<int>();
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = Convert.ToInt32(Console.ReadLine());
}
opli = UserProgramCode.findLeadersArray(arr);
for(int i=0;i<opli.Count;i++){
Console.WriteLine(opli[i]);
}
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
class UserProgramCode
{
public static List<int> findLeadersArray(int[] input)
{
{
count = 0;
for (int j = i + 1; j < input.Length; j++)
{
if (input[i] > input[j])
count++;
}
if (input.Length - (i + 1) == count)
list.Add(input[i]);
}
list.Add(input[input.Length - 1]);
list.Sort();
return list;
}
else
list.Add(-1);
return list;
}
}
-----------------------------------------------------------------------
Longest Palindrom
using System;
using ConsoleApplication1;
class Program
{
public static void Main( string[] args )
{
string str;
int palindromeLen;
str = Console.ReadLine();
palindromeLen = UserProgramCode.LongestPalindrome(str);
Console.WriteLine(palindromeLen);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class UserProgramCode
{
public static int LongestPalindrome(string seq)
{
int Longest = 0;
List<int> l = new List<int>();
int i = 0;
int palLen = 0;
int s = 0;
int e = 0;
while (i < seq.Length)
{
return Longest;
}
}
}
-----------------------------------------------------------------------
using System;
namespace myprograms
{
class Program
{
public static void Main()
{
int size = int.Parse(Console.ReadLine());
String[] array = new String[size];
for (int i = 0; i < size; i++)
{
array[i] = Console.ReadLine();
}
Console.WriteLine(UserProgramCode.longestWordLength(array));
}
}
}
using System;
namespace myprograms
{
class UserProgramCode
{
public static int longestWordLength(String[] array)
{
}
}
}
-----------------------------------------------------------------------
LongSpan
using System;
class Program
{
public static void Main( string[] args )
{
int n = Convert.ToInt32(Console.ReadLine());
int[] input = new int[n];
for (int i = 0; i < n; i++)
input[i] = Convert.ToInt32(Console.ReadLine());
using System;
using System.Text;
using System.Linq;
class UserProgramCode {
public static int LongSpan(int[] input)
{
int[] res = new int[input.Length];
int span = 0, maxspan = 0;
for (int i = 0; i < input.Length; i++)
{
for (int j = input.Length - 1; j > 0; j--)
{
if (input[i] == input[j])
{
span = j - 1;
if (span > maxspan)
maxspan = span;
}
}
}
return span;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program2
{
class Program
{
public static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (int i = 0; i < size; i++)
arr[i] = Convert.ToInt32(Console.ReadLine());
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program2
{
class UserProgramCode
{
public static int findLowest(int[] array)
{
int res=0,low=array[0];
foreach (var a in array)
{
if (a < 0)
{
res=-1;
return res;
}
else if(a<low)
{
res = a;
}
}
return res;
}
}
}
-----------------------------------------------------------------------
Matching String
using System;
using System.Collections.Generic;
class Program
{
public static void Main(string[] args)
{
List<string> list = new List<string>();
List<string> result = new List<string>();
int size = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < size; i++)
{
list.Add(Console.ReadLine());
}
char ch = Convert.ToChar(Console.ReadLine());
result = UserProgramCode.SortStrings(size, list, ch);
if (result[0].Equals("-1"))
Console.WriteLine("No match found");
else
{
for (int i = 0; i < result.Count; i++)
Console.WriteLine(result[i]);
}
}
}
using System;
using System.Collections.Generic;
class UserProgramCode
{
public static List<string> SortStrings(int size, List<string> li, char ch)
{
List<string> result = new List<string>();
// int size = Convert.ToInt32(Console.ReadLine());
int k = 0, count = 0;
string item;
char c = Convert.ToChar(li[i].Substring(0, 1));
if (ch == c)
{
item = li[i] + "_" + count;
result.Add(item);
k++;
}
}
return result;
}
}
----------------------------------------------------------------------Matching string(SortStrings)
using System;
using System.Collections.Generic;
class Program
{
public static void Main(string[] args)
{
List<string> list = new List<string>();
List<string> result = new List<string>();
int size = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < size; i++)
{
list.Add(Console.ReadLine());
}
char ch = Convert.ToChar(Console.ReadLine());
result = UserProgramCode.SortStrings(size, list, ch);
if (result[0].Equals("-1"))
Console.WriteLine("No match found");
else
{
for (int i = 0; i < result.Count; i++)
Console.WriteLine(result[i]);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static List<string> SortStrings(int size, List<string> li, char ch)
{
List<string> res = new List<string>();
int c = 0;
c++;
}
}
c = c - 1;
li.RemoveAt(size - 1);
if (c == 0 )
{
res.Add("-1");
return res;
}
else
{
foreach (var item in li)
{
if (item.Contains(ch))
{
res.Add(item + "_" + c);
}
}
}
return res;
----------------------------------------------------------------------maximumlengthvowel word
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace maximumlengthvowel_word
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string input");
string s = Console.ReadLine();
string[] str = s.Split(' ');
string maxstring="";
string vowel = "aieouAIEOU";
int max=0;
for (int i = 0; i < str.Length; i++)
{
int count=0;
foreach (char ch in str[i])
{
if (vowel.Contains(ch))
{
count++;
}
}
if(count> max)
{
max=count;
maxstring=str[i];
}
else
{
continue;
}
}
Console.WriteLine(maxstring);
Console.ReadLine();
}
}
}
-----------------------------------------------------------------------
MAX OF 3
using System;
int n1 = Convert.ToInt32(Console.ReadLine());
int n2 = Convert.ToInt32(Console.ReadLine());
int n3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserMainCode.FindMax(n1,n2,n3) + " is the maximum
number");
Console.Read();
}
}
using System;
----------------------------------------------------------------------MINING PROGRAM
using System;
using System;
-----------------------------------------------------------------------
MobileNumberValidation
using System;
class Program
{
public static void Main( string[] args )
{
string ipadress = Console.ReadLine();
Console.WriteLine(UserProgramCode.ValidateMobileNumber(ipadress));
Console.Read();
}
}
using System;
using System.Text.RegularExpressions;
class UserProgramCode {
public static string ValidateMobileNumber(String input1)
{//+91-9876543210
string result="";
Regex reg=new Regex(@"[+]91[-]([0-9]{10})");
if(reg.IsMatch(input1))
result = "Valid";
else
result = "Invalid";
return result;
}
}
}
}
using System;
while (true)
{
int rev = 0;
num++;
int temp=num;
while (temp != 0)
{
rev = rev * 10 + temp % 10;
temp = temp / 10;
}
if (rev == num)
{
break;
}
}
//int num = n;
//int check = 0;
//do
//{
//
++num;
//
int rev = 0;
//
//
//
int count = 0;
//
int fact = 1;
//
//
//
//
//
count++;
//
//
//
//
//
//
//
//
//
check = rev;
//}
//while (check!=num);
return num;
----------------------------------------------------------------------Move lower
using System;
using System;
int count = 0;
{
count++;
}
s= s.Replace("x", "");
Console.Write("The processed string is ");
// Console.Write(s);
for (int i = 0; i < count; i++)
{
s = s + "x";
// Console.Write("x");
}
return s;
}
}
----------------------------------------------------------------------MoveLowerx
using System;
using System;
}
----------------------------------------------------------------------Negative string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static string negativeString(string str)
{
}
else
{
b2.Append(sb+ " ");
}
}
string sr=b2.ToString();
return sr;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main(string[] args)
{
String str = Console.ReadLine();
Console.WriteLine(UserProgramCode.negativeString(str));
}
}
Console.WriteLine(output);
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System;
class UserProgramCode
{
public static int nextHighestNumber(int input)
{
if (input < 0)
return -1;
int[] outp = new int[10];
int i = 0;
int max = 0;
// fill code here
int[] arr = new int[5];
int n = input;
while (n != 0)
{
arr[i] = n % 10;
n = n / 10;
i++;
if (i > 3)
return -2;
if (arr[0] == arr[1] || arr[1] == arr[2] || arr[0] == arr[2])
return -3;
else
{
}
return max;
}
}
----------------------------------------------------------------------NEXTHIGHESTNUMBER
class UserProgramCode
{
public static int nextHighestNumber(int n)
{
int num = n;
int l =n.ToString().Length;
int next;
if (l == 1)
{
return num;
}
else if(num<0)
{
return -1;
}
else if (l > 3)
{
return -2;
}
else
{
if (l == 2)
{
int rem1 = n % 10;
n = n / 10;
next = (rem1 * 10) + n;
return next;
}
else
{
int rem1 = n % 10;
n = n / 10;
int rem2 = n % 10;
n = n / 10;
if (rem1 > rem2)
{
next = (n * 100) + (rem1 * 10) + rem2;
return next;
}
else if (n < rem1 && rem2 != rem1 )
{
next = (rem1 * 100) + (n*10) + rem2;
return next;
}
else if (n < rem2 && rem2 != rem1)
{
next = (rem2 * 100) + (n) + rem1*10;
return next;
}
else
{
return -3;
}
}
}
}
-----------------------------------------------------------------------
Next Palindrome
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class UserMainCode {
while (n > 0)
{
k= n % 10;
rev = (rev * 10) + k;
n = n / 10;
if (i==rev)
{
return i;
}
}
----------------------------------------------------------------------NextYearDay
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NextYearDay
{
class Program
{
static void Main(string[] args)
{
string input, output;
input = Console.ReadLine();
output = UserProgramCode.nextYearDay(input);
if (output == null)
{
Console.WriteLine("Invalid date");
}
Console.WriteLine(output);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NextYearDay
{
class UserProgramCode
{
public static string nextYearDay(string date)
{
string output="";
DateTime day;
bool check = DateTime.TryParseExact(date, "dd/MM/yyyy", null,
System.Globalization.DateTimeStyles.None, out day);
if (check == true)
{
day = day.AddYears(1);
//Console.WriteLine(day);
//day = day.DayOfWeek;
output = day.DayOfWeek.ToString();
output = output.ToLower();
return output;
}
else
{
return output;
}
}
}
}
----------------------------------------------------------------------next vowel next consonent
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace nextvowelnextconsonent
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string str="";
char vow =' ';
int flag = 0;
foreach (char c in s)
{
if (char.IsLetter(c))
{
if (char.IsLower(c))
{
if ("aieou".Contains(c))
{
vow = Convert.ToChar(c + 1);
str = str + vow;
continue;
}
else
{
vow = c;
if (vow != 'z')
{
while (!"aieou".Contains(vow))
{
vow++;
}
str = str + vow;
continue;
}
else
{ str = str + 'a';
continue;
}
}
}
else
{
if ("AIEOU".Contains(c))
{
vow = Convert.ToChar(c + 1);
str = str + vow;
continue;
}
else
{
vow = c;
if (vow != 'Z')
{
while (!"AIEOU".Contains(vow))
{
vow++;
}
str = str + vow;
continue;
}
else
{
str = str + 'A';
continue;
}
}
else { flag = 1; break; }
if (flag == 0)
{
Console.WriteLine(str);
}
else
{
Console.WriteLine("Invalid character");
}
Console.ReadLine();
}
}
}
----------------------------------------------------------------------nextYearDay
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Globalization;
namespace ConsoleApplication47
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string format = "dd/MM/yyyy";
DateTime date;
bool res = (DateTime.TryParseExact(s, format, CultureInfo.InvariantCulture,
DateTimeStyles.None, out date));
if (res == true)
{
date = date.AddYears(1);
string s3=date.ToShortDateString();
string s1= date.DayOfWeek.ToString();
Console.ReadLine();
}
}
}
passwordValidation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions ;
namespace Password_validate
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
Regex reg = new Regex(@"^[a-zA-Z]+[0-9]*([@]|[_]|[$])[a-zA-Z0-9]+$");
if (reg.IsMatch(str)&&str.Length >=8)
{
Console.WriteLine("valid");
}
else
{
Console.WriteLine("invalid");
}
Console.ReadLine();
}
}
}
----------------------------------------------------------------------Password encryption
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Passwordencryption
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the password");
string s = Console.ReadLine();
Console.WriteLine("enter the string to replace");
string s2 = Console.ReadLine();
string[] array = s.Split(' ');
string str = "";
int flag = 0;
if (s != string.Empty )
{
for (int i = 0; i < array.Length; i++)
{
foreach (char ch in array[i])
{
if (char.IsLetter(ch))
{
}
else
{
flag = 1;
}
}
if (!s2[0].Equals(array[i][0]))
{
int n = array[i].Length;
str = str + s2 + array[i].Substring(1, n - 1) + " ";
}
else
{
int n = array[i].Length;
str = str + Convert.ToChar((s2[0] + 1)) + "#" + array[i].Substring(1,
n - 1) + " ";
}
}
}
else
{
Console.WriteLine("Invalid password");
}
if(flag==0)
{
Console.WriteLine(str);
}
else
{
Console.WriteLine("Invalid password");
}
Console.ReadLine();
}
}
}
----------------------------------------------------------------------percentage cal
using System;
class Program
{
public static void Main( string[] args )
{
int m1=Convert.ToInt32(Console.ReadLine());
int m2=Convert.ToInt32(Console.ReadLine());
int m3=Convert.ToInt32(Console.ReadLine());
int m4=Convert.ToInt32(Console.ReadLine());
int m5=Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.calculateResult(m1,m2,m3,m4,m5));
Console.ReadLine();
}
}
using System;
class UserProgramCode
{
public static String calculateResult(int m1,int m2,int m3,int m4,int m5)
{
int sum;
int percentage=0;
sum = m1 + m2 + m3 + m4 + m5;
percentage = (sum * 100)/500;
string str=" ";
if (percentage >= 60)
{
str = "First Class";
}
else if (percentage >=50 && percentage<=59)
{
str = "2nd Class";
return str;
}
}
----------------------------------------------------------------------PERFECT NUMBER
using System;
int n = Convert.ToInt32(Console.ReadLine());
if(UserMainCode.IsPerfect(n))
Console.WriteLine("Perfect number");
else
Console.WriteLine("Not a perfect number");
Console.Read();
}
}
using System;
{
public static bool IsPerfect(int n) {
int sum = 0;
for (int i = 1; i <= n / 2; i++)
{
if (n % i == 0)
sum += i;
}
if (n == sum)
return true;
else
return false;
}
}
----------------------------------------------------------------------PERMUTATION
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dumpsMaking
{
class UserProgramCode
{
static void Main(string[] args)
{
int i, c = 0;
string str1 = "";
}
else
l.Add(str[i] + "");
}
for (i = 0; i < l.Count; i++)
{
str1 = str1 + l[i];
}
for (i = 0; i < str1.Length; i++)
{
if ((str1[i] >= 'a' && str1[i] <= 'z') || (str1[i] >= 'A' && str1[i] <= 'Z'))
{
}
else
{
c = 1;
}
}
if (c == 0)
{
List<string> lt = permString(str1);
lt.Sort();
for (i = 0; i < lt.Count; i++)
{
Console.WriteLine(lt[i]);
}
}
else
{
Console.WriteLine("Invalid Input");
}
Console.ReadLine();
}
public static List<string> permString(string input1)
{
char[] arr = input1.ToCharArray();
GetPer(arr);
return lt;
//Console.WriteLine(lt.Count);
}
static List<string> lt = new List<string>();
private static void Swap(ref char a, ref char b)
{
if (a == b) return;
{
a ^= b;
b ^= a;
a ^= b;
}
}
-----------------------------------------------------------------------
PHONE NUMBER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace phonenumber
{
class Program
{
static void Main(string[] args)
{
//Regex reg = new Regex(@"^\d{3}[-]\d{3}[-]\d{4}$");
Regex reg = new Regex(@"^(0[0-9]|1[0-2]):([0-5][0-9])([A]|[P])M$");
string str = Console.ReadLine();
if (reg.IsMatch(str))
{
Console.WriteLine("Valid");
}
else
{
Console.WriteLine("iNVALID");
}
Console.ReadLine();
}
}
}
-----------------------------------------------------------------------
POSTAL TARRIF
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PostalTariff
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
string[] str = new string[n];
for (int i = 0; i < n; i++)
{
str[i] = Console.ReadLine();
}
UserProgramCode.getPostalTariff(str);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PostalTariff
{
class UserProgramCode
{
public static void getPostalTariff(string[] input1)
{
int ctr = 0;
double c=0,sum=0;
if (ctr == 0)
{
for (int i = 0; i < input1.Length; i++)
{
c = 0;
string str = input1[i].ToUpper();
if (str.Substring(0, 2) == "BP")
{
c = c + 100;
}
else if (str.Substring(0, 2) == "CH")
{
c = c + 450;
}
else if (str.Substring(0, 2) == "OS")
{
c = c + 200;
}
if (str.Substring(2, 2) == "SP")
{
c = c + (0.3 * c);
}
sum = sum + c;
}
Console.WriteLine(sum);
}
}
}
}
----------------------------------------------------------------------POWER OF 2
using System;
----------------------------------------------------------------------PRIMITIVE TYPEWRITER
using System;
----------------------------------------------------------------------PRINT CAPITALISED
using System;
class Program
{
public static void Main()
{
Console.WriteLine(UserProgramCode.printCapitalized(Console.ReadLine()));
//Console.ReadKey();
}
}
using System;
using System.Linq;
class UserProgramCode
{
public static String printCapitalized(String input1)
{
input1 = input1.ToLower();
char a;
int count = 0;
string[] str = input1.Split(' ');
string output = "";
----------------------------------------------------------------------printcountofthemaxvowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication48
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
}
}
int maxcount = count.Max();
int maxindex = count.ToList().IndexOf(maxcount);
Console.WriteLine(maxcount);
Console.ReadLine();
}
}
}
----------------------------------------------------------------------PRINT CAPITALISED
using System;
class Program
{
public static void Main()
{
Console.WriteLine(UserProgramCode.printCapitalized(Console.ReadLine()));
//Console.ReadKey();
}
}
using System;
using System.Linq;
class UserProgramCode
{
public static String printCapitalized(String input1)
{
input1 = input1.ToLower();
char a;
int count = 0;
string[] str = input1.Split(' ');
string output = "";
foreach (string s in str)
{
count = 0;
foreach (char ch in s)
{
a = ch;
if (count == 0)
{
if (char.IsLetter(ch))
{
a = (char)((int)ch - 32);
}
}
output = output + a;
count++;
}
output = output + " ";
}
return output;
}
}
----------------------------------------------------------------------printcountofthemaxvowels
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication48
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
}
}
int maxcount = count.Max();
int maxindex = count.ToList().IndexOf(maxcount);
Console.WriteLine(maxcount);
Console.ReadLine();
}
}
}