Coding Written Test Programs
Coding Written Test Programs
Coding
Written
Test
by
Mr.R.N Reddy
RN Reddy IT School
Online/Classroom Training’s
For more details
Phone: +91 9866183094, 7989886175
E-Mail: [email protected]
Visit: www.rnreddyitschool.co
FB Page: - www.facebook.com/Reddyitschool 1
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
LOGICAL
PROGRAMS
2
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Output: Sum is : 15
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
int n = int.Parse(Console.ReadLine());
int sum = 0;
sum = sum + i;
Console.ReadLine();
solution:
3
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("Enter ur range:");
int n = int.Parse(Console.ReadLine());
int mul = 1;
mul = mul * i;
Console.ReadLine();
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
4
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.WriteLine("Enter ur range:");
int n = int.Parse(Console.ReadLine());
int fac = 1;
fac = fac * i;
Console.ReadLine();
4.Write a console program to swap two numbers and print swapped Numbers?
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int temp = a;
a = b;
b = temp;
Console.ReadLine();
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
{
6
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
a = a + b;
b = a - b;
a = a - b;
Console.ReadLine();
6.Write a console program to print 5 table based on input from the user.
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("Enter Ur number");
int n = int.Parse(Console.ReadLine());
{
7
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.ReadLine();
output:
Enter Ur number
5 Table is :
5*1=5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
solution:
using System;
namespace RNREDDYLogicalprograms
8
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
class Program
Console.WriteLine("Enter ur number:");
int n = int.Parse(Console.ReadLine());
int ctr = 0;
if (n % i == 0)
ctr++;
break;
if (ctr == 0)
else
Console.ReadLine();
}
9
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("Enter ur number:");
int n = int.Parse(Console.ReadLine());
if (n % 2 == 1)
else
Console.ReadLine();
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("Enter ur number:");
int n = int.Parse(Console.ReadLine());
if (n % 2 == 0)
else
Console.ReadLine();
10.Write a console program to check weather given number is even no’s, sum of even
numbers,
11
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
10
Sum is : 30
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("Enter Ur range:");
int n = int.Parse(Console.ReadLine());
if (i % 2 == 0)
Console.WriteLine(i);
sum = sum + i;
12
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
count++;
Console.ReadLine();
11.Write a console program to check weather given number is even no’s, sum of even
numbers, no of even numbers within given range?
Sum is : 9
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
13
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.WriteLine("Enter Ur range:");
int n = int.Parse(Console.ReadLine());
if (i % 2 != 0)
Console.WriteLine(i);
sum = sum + i;
count++;
Console.ReadLine();
Op: sum is : 55
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
{
14
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.WriteLine("Enter ur number:");
int n = int.Parse(Console.ReadLine());
int sum = 0;
int sqr = i * i;
Console.ReadLine();
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
15
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.WriteLine("Enter ur number:");
int n = int.Parse(Console.ReadLine());
fac = fac * j;
fac = 1;
Console.ReadLine();
Ip : Enter ur range: 15
Op: 0 1 1 2 3 5 8 13
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
int a = 0, b = 1, c = 0;
int n = int.Parse(Console.ReadLine());
while (a <= n)
c = a + b;
a = b;
b = c;
Console.ReadLine();
15.Write a console program to print Fibonacci series up to given range and display
sum of Fibonacci series and no of Fibonacci series up to given range.
Op: 0 1 1 2 3 5 8
sum is: 33
no of numbers are: 7
solution:
using System;
namespace RNREDDYLogicalprograms
17
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
class Program
int a = 0, b = 1, c = 0;
int n = int.Parse(Console.ReadLine());
while (a <= n)
c = a + b;
a = b;
b = c;
sum = sum + a;
count++;
Console.ReadLine();
Enter Number : 50
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
int n, i, k, r, temp;
n = int.Parse(Console.ReadLine());
temp = i; r = 0;
while (temp != 0)
k = temp % 10;
r = r * 10 + k;
if (r == i)
Console.ReadLine();
19
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Armstrong Number.
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
n= int.Parse(Console.ReadLine());
temp=n;
while (n>0)
r=n%10;
sum=sum+(r*r*r);
n=n/10;
if (temp==sum)
Console.Write("Armstrong Number.");
20
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
else
Console.ReadLine();
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("Enter ur number:");
int rem = 0;
int rev = 0;
while (num != 0)
Console.ReadLine();
op: It is a palindrome
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("Enter ur number:");
int n = int.Parse(Console.ReadLine());
while (n != 0)
rem = n % 10;
n = n / 10;
}
22
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
if (temp == revnum)
Console.WriteLine("It is a palindrome");
else
Console.ReadLine();
20.Write a program which takes an integer number and adds all the digit in the
number, it should return a single digit in the end.
input : 5643
output: 9
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("Enter ur Number:");
23
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
int n = int.Parse(Console.ReadLine());
int sum = 0;
while (n > 9)
sum = 0;
while (n > 0)
int rem;
rem = n % 10;
n = n / 10;
n = sum;
Console.ReadLine();
output : 1111011
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
24
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
int num;
num = int.Parse(Console.ReadLine());
int quot;
quot = num / 2;
num = quot;
Console.ReadLine();
2 3 5 7 11 13 17 19 23 29
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int n = int.Parse(Console.ReadLine());
int count = 0;
if (i % j == 0)
count++;
if (count == 2)
Console.Write(i+" ");
primecount++;
26
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
n++;
if (primecount == temp)
break;
Console.ReadLine();
Maximum Number = 9
Minimum Number = 1
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
{
27
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
if (a > max)
max = a;
if (a < min)
min = a;
Console.ReadLine();
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
int x = Int32.Parse(Console.ReadLine());
int sum = 0, r;
28
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
while (x != 0)
r = x % 10;
x = x / 10;
Console.ReadLine();
6 is a perfect number
solution:
using System;
namespace RNREDDYLogicalprograms
class Program
number = int.Parse(Console.ReadLine());
n = number;
if (number % i == 0)
sum = sum + i;
if (sum == n)
else
Console.ReadLine();
30
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
PATTERN
PROGRAMS
(NUMBER PATTERNS &
SYMBOL PATTERNS)
31
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
output:
22
333
4444
55555
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine();
Console.ReadLine();
32
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
output:
12
123
1234
12345
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine();
Console.ReadLine();
}
33
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
output:
55555
4444
333
22
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("\n");
Console.ReadLine();
}
34
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
output:
12345
1234
123
12
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("\n");
Console.ReadLine();
}
35
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
OP:
12
123
1234
12345
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("enter ur range");
int r = int.Parse(Console.ReadLine());
Console.WriteLine();
36
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.ReadLine();
output:
22
333
4444
55555
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("enter ur range");
int r = int.Parse(Console.ReadLine());
{
37
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.WriteLine();
Console.ReadLine();
op:
23
456
7 8 9 10
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int k = 1;
{
38
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
k++;
Console.WriteLine("\n");
Console.ReadLine();
output:
23
456
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("enter ur range");
39
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
int r = int.Parse(Console.ReadLine());
int k = 1;
if (k > r)
break;
k++;
Console.WriteLine();
if (k > r)
break;
Console.ReadLine();
output:
21 20 19 18 17 16
15 14 13 12 11
10 9 8 7
654
32
1
40
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Solution:
using System;
namespace RNREDDYLogicalprograms
class Program
Console.WriteLine("enter ur range");
int n= int.Parse(Console.ReadLine());
int k = n;
k--;
Console.WriteLine();
if (k == 0)
break;
Console.ReadLine();
41
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Output:
**
***
****
*****
******
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y;
Console.Write("*");
Console.WriteLine();
Console.ReadLine();
}
42
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Output:
**
***
****
*****
******
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y, z;
Console.Write(" ");
{
43
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.Write("*");
Console.WriteLine();
Console.ReadLine();
Output:
*****
****
***
**
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y;
Console.Write("*");
Console.WriteLine();
Console.ReadLine();
Output:
*****
****
***
**
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y, z;
{
45
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.Write(" ");
Console.Write("*");
Console.WriteLine();
Console.ReadLine();
Output:
***
*****
*******
46
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y, z;
Console.Write(" ");
Console.Write("*");
Console.WriteLine();
Console.ReadLine();
47
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Output:
*********
*******
*****
***
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y, z;
Console.Write(" ");
Console.Write("*");
Console.WriteLine();
Console.ReadLine();
Output:
**
* *
* *
*********
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y;
{
49
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.Write(" ");
if (x == 5 || y == 1 || y == (2 * x - 1))
Console.Write("*");
else
Console.Write(" ");
Console.WriteLine();
Console.ReadLine();
50
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Output:
BB
CCC
DDDD
EEEEE
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y;
int z = 5;
Console.Write((char)(x + 64));
Console.WriteLine("");
Console.ReadLine();
51
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Output:
ABCDE
BCDE
CDE
DE
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y;
int z = 5;
Console.Write((char)(y + 64));
Console.WriteLine();
52
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.ReadLine();
Output:
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int x, y;
int z = 6;
{
53
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.Write(" ");
Console.Write((char)(y + 64));
Console.Write((char)(y + 64));
Console.WriteLine();
Console.ReadLine();
01
010
1010
10101
Solution:-
using System;
namespace RNREDDYLogicalprograms
{
54
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
class Program
input = int.Parse(Console.ReadLine());
if (lastInt == 1)
Console.Write("0");
lastInt = 0;
else if (lastInt == 0)
Console.Write("1");
lastInt = 1;
Console.Write("\n");
Console.ReadLine();
}
55
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Output:
45
345
2345
12345
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
{ Console.Write(col); }
Console.Write("\n");
Console.ReadLine();
}
56
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Enter Number : 5
eio
uaeio
uaeioua
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
int index = 0;
Console.Write(" ");
else
{
57
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.Write(arr[index]);
index++;
if (index == input)
index = 0;
Console.WriteLine();
Console.ReadLine();
Input:5
Output:
1 2 3 4 5
16 6
15 7
14 8
13 12 11 10 9
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.Write("Enter a no.:");
int n = int.Parse(Console.ReadLine());
int r = n * 4 - 4, count = 1;
if (row == 1 || col == n)
if (col <= 9)
else
count++;
if (r <= 9)
else
r--;
else
}
59
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.ReadLine();
Input: 5
output:
123454321
12344321
123 321
12 21
1 1
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.Write("Enter a number:");
Console.WriteLine("\nPattern: \n");
60
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.Write(col);
else
Console.Write(" ");
Console.Write(col);
else
Console.Write(" ");
Console.WriteLine();
Console.ReadLine();
Enter a No.:
11
121
1331
61
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Solution:-
using System;
namespace RNREDDYLogicalprograms
class Program
Console.Write("Enter a No.:");
Console.Write(" ");
int count = 1;
Console.WriteLine();
Console.ReadLine();
62
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
STRING
HANDLING
PROGRAMS
63
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Output: good
Solution:
int count = 0;
word = s;
count = s.Length;
Console.WriteLine(word);
Console.ReadLine();
Solution:
temp = ch + temp;
Console.WriteLine(strrev);
Console.ReadLine();
output: 4
solution:
class Program
string str;
int wrd, l;
Console.Write("------------------------------------------------------\n");
str = Console.ReadLine();
l = 0;
wrd = 1;
tab character*/
wrd++;
l++;
Console.ReadLine();
4.Write a function that given two string s1 and s2, it will return s1 minus s2 and it has
to use same location without using pre defined functions.
Input:enter string s1
abcd8
enter string s2
Output:acd8
66
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Solution:
class Program
Console.WriteLine("Enter string1:");
string s1 = Console.ReadLine();
string s2 = Console.ReadLine();
Console.ReadLine();
Input:aaabbcccc
Output:c
Solution:
class Program
string str;
int i = 0, max, l;
int ascii;
Console.Write("--------------------------------------------------\n");
str = Console.ReadLine();
l = str.Length;
ch_fre[i] = 0;
i = 0;
while (i < l)
ascii = (int)str[i];
ch_fre[ascii] += 1;
i++;
// Console.Write("{0} ",(char)65);
max = 0;
if (i != 32)
max = i;
Console.ReadLine();
6.Write a program to print frequency of each character in a given string when count a
character like below
output: r-2 n-1 e-1 d-2 y-1 s-1 t-1 i-1 c-1 h-1 o-2 l-1
solution:
class Program
Console.Write("Enter String.");
Console.Write(input[0] + "-");
int count = 0;
if (input[0] == input[j])
count++;
69
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.ReadLine();
7.Write a Program to copy ‘n’ number of characters from one string to another at
position ‘p’
N: 2
P: 8
Solution:
class Program
string s1 = Console.ReadLine();
string s2 = Console.ReadLine();
char[] c = s2.ToCharArray();
if (i == pos - 1)
Console.Write(" ");
Console.Write(s1[j]);
Console.Write(" ");
Console.Write(c[i]);
Console.ReadLine();
8.Swap neighbour char in string, for Example string “TAPAN” would be ATAPN
Input:TAPAN
Output:ATAPN
Solution:
class Program
Console.WriteLine("Enter a string:");
string s = Console.ReadLine();
char[] c = s.ToCharArray();
int n;
char temp;
71
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
if (c.Length % 2 == 0)
n = c.Length;
else
n = c.Length - 1;
temp = c[i];
c[i + 1] = temp;
Console.Write(c[i]);
Console.Write(c[i + 1]);
if (n < c.Length)
Console.WriteLine(c[c.Length - 1]);
Console.ReadLine();
72
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
9.How will you find the longest palindrome in a String? i.e., if the string is XMADAMY
your palindrome in a String? i.e., if the string is XMADAMY your code should print
MADAM.
Input:XMADAMY
Output:MADAM
Solution:
class Program
leftIndex = currentIndex - 1;
rightIndex = currentIndex + 1;
if (input[leftIndex] != input[rightIndex])
break;
paliList.Add(currentPalindrome);
leftIndex--;
73
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
rightIndex++;
return x;
Console.WriteLine(longestPalindrome);
Console.ReadLine();
Vowels : 4
Consonants is : 6
No of Words is : 2
Solution:
int vowels = 0;
int consonants = 0;
int words = 1;
if (chr[i] == 32)
words++;
continue;
else
if (chr[i] == 'a' || chr[i] == 'e' || chr[i] == 'i' || chr[i] == 'o' || chr[i] == 'u' ||
chr[i] == 'A' || chr[i] == 'E' || chr[i] == 'I' || chr[i] == 'O' || chr[i] == 'U')
vowels++;
else
consonants++;
Console.ReadLine();
solution:
using System;
class Program
{
static void Main()
{
string value1 = RemoveDuplicateChars("Csharpstar");
Console.WriteLine(value1);
}
static string RemoveDuplicateChars(string key)
{
string table = "";
string result = "";
foreach (char value in key)
{
if (table.IndexOf(value) == -1)
{
table += value;
result += value;
}
}
return result;
}
}
solution:
using System;
namespace Anagram
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter first word:");
76
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Array.Sort(char1);
Array.Sort(char2);
if (NewWord1 == NewWord2)
{
Console.WriteLine("Yes! Words \"{0}\" and \"{1}\" are Anagrams", word1, word2);
}
else
{
Console.WriteLine("No! Words \"{0}\" and \"{1}\" are not Anagrams", word1,
word2);
}
Console.ReadLine();
}
}
}
solution:
using System;
namespace consoleapp4
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter ur string");
string s=Console.ReadLine();
string rev = null;
for(int i = s.Length-1;i>=0 ; i--)
{
rev=rev+s[i];
}
Console.WriteLine("reverse string is:"+rev);
if (s==rev)
Console.WriteLine("it is a palindrome");
else
77
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
solution:
using System;
public class GFG
{
static bool uniqueCharacters(String str)
{
for (int i = 0; i < str.Length; i++)
for (int j = i + 1; j < str.Length; j++)
if (str[i] == str[j])
return false;
return true;
}
public static void Main()
{
Console.WriteLine("enter ur input");
string input = Console.ReadLine();
if (uniqueCharacters(input) == true)
Console.WriteLine("The String " + input
+ " has all unique characters");
else
Console.WriteLine("The String " + input
+ " has duplicate characters");
Console.ReadLine();
}
}
ab
bc
abc
solution:
using System;
class GFG
{
static void find_substrings(string input_string)
78
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
{
int j = 0;
int i = 0;
for (i = 1; i <= input_string.Length; i++)
{
for (j = 0; j <= input_string.Length - i; j++)
{
Console.WriteLine(input_string.Substring(j, i));
}
}
}
public static void Main()
{
string input_string;
input_string = Console.ReadLine();
find_substrings(input_string);
Console.ReadLine();
}
}
solution:
using System;
if (s.IndexOf(s[i], s.IndexOf(s[i]) + 1)
== -1)
{
Console.Write(
"First non-repeating character is "
+ s[i]);
break;
}
}
return;
79
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
}
internal static void Main()
{
Console.WriteLine("enter ur string");
string s = Console.ReadLine();
FirstNonRepeat(s);
Console.ReadLine();
}
}
17.How to remove special characters from String?
input:$c!sh$arp&st%ar
output:csharpstar
solution:
using System;
public class Program
{
public static void Main(string[] args)
{
string str = "$c!sh$arp&st%ar";
Console.WriteLine(RemoveSpecialChars(str));
Console.ReadLine();
}
public static string RemoveSpecialChars(string str)
{
// Create a string array and add the special characters you want to remove
string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";",
"_", "(", ")", ":", "|", "[", "]" };
//Iterate the number of times based on the String array length.
for (int i = 0; i < chars.Length; i++)
{
if (str.Contains(chars[i]))
{
str = str.Replace(chars[i], "");
}
}
return str;
}
}
solution:
using System;
class GFG
{
static void reverseStr(String str)
80
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
{
int n = str.Length;
char[] ch = str.ToCharArray();
char temp;
Solution:
using System.Text;using System;
using System.Threading.Tasks;
namespace ConsoleApp15
{
internal class Program
{
static void Main(string[] args)
{
// create string
string str2 = "Programming";
Console.WriteLine("string str2: " + str2);
Console.ReadLine();
}
}
}
using System;
namespace CsharpString
// create string
string str1 = "C# Programming";
string str2 = "C# Programming";
string str3 = "Programiz";
Console.ReadLine();
}
}
}
21.write the code for this series?
input:aaabbcccc
output:a3b2c4
solution:
class program
{
static void main(string[]args)
{
Console.Write("enter ur string:");
string s=Console.ReadLine();
char[]ch=s.TocharArray();
Con22sole.Write(" ");
for(int i=0;i<ch.length;i++);
{
int count=1;
82
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
if(ch[i]!='@';)
{
Console.Write(ch[i]);
for(int j=i+1;j<ch.length;j++)
{
if(s[i]==s[j])
{
count++;ch[j]='@';
}
}
Console.Write(count);
}
}
Console.ReadLine();
}
}
}
22.string in numbers pattern?
output:enter ur srting
interview
i
in
int
inte
inter
interv
intervi
intervie
interview
solution:
namespace ConsoleApp6
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter ur srting");
string str = Console.ReadLine();
for(int i=0;i<str.Length; i++)
{
for(int j=0;j<=i; j++)
{
Console.Write(str[j]+" ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
83
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Solution:
namespace ConsoleApp19
{
internal class Program
{
static void Main(string[] args)
{
// create string
string str = "C# Programming";
Console.WriteLine("string: " + str);
Console.ReadLine();
}
}
}
24.Write a Program to Sort a List of Names in Alphabetical Order
Output:
Abs
Edward
Ram
Rose
Sita
Solution:
names.Add("Ram");
names.Add("Rose");
names.Add("Abs");
names.Add("Edward");
names.Add("Sita");
names.Sort();
Console.WriteLine("Output: \n");
Console.WriteLine(s);
Console.ReadLine();
input: amazon
output: mazano
solution:
string s = Console.ReadLine();
{
85
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
Console.Write(c[i]); break;
break;
c[i + 1] = temp;
Console.ReadLine();
86
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752
RN Reddy IT School
RN Reddy IT School
Online/Classroom Training’s
87
ADDRESS: Flat no:102, KVR Enclave, above Bata showroom, left side of Sathyam theatre Ameerpet
Hyderabad-500016, Phone: 9866183094, 79898861752