Logical C#.Net Questions
logical questions |
1.Write a console program to print the following pattern?
11 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication21
{
class Program
{
static void Main(string[] args)
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 5; j > i; j--)
{
Console.Write(" ");
}
for (j = 1; j <= i; j++)
{
Console.Write(" "+j);
}
for (j = j - 2; j >= 1; j--)
{
Console.Write(" "+j);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
2.Write a console program to print the following pattern?
** *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
namespace triangle
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n = 6, l = 3;
for (i = 1; i <= 5; i++)
{
for (k = n; k >= 1; k--)
{
Console.Write(" ");
}
n--;
for (j = 1; j <= i; j++)
{
Console.Write(" " + "*");//i
}
Console.WriteLine("");
}
for (i = 4; i >= 1; i--)
{
for (k = l; k >= 1; k--)
{
Console.Write(" ");
}
l++;
for (j = 1; j <= i; j++)
{
Console.Write(" " + "*");//i
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
3.Write a console program to print the following pattern?
*
* *
* * *
* * * *
* * * * *
namespace triangle
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n = 6, l = 3;
for (i = 1; i <= 5; i++)
{
for (k = n; k >= 1; k--)
{
Console.Write(" ");
}
n--;
for (j = 1; j <= i; j++)
{
Console.Write(" " + "*");//i
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
* *
* * *
* * * *
* * * * *
namespace triangle
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n = 6, l = 3;
for (i = 1; i <= 5; i++)
{
for (k = n; k >= 1; k--)
{
Console.Write(" ");
}
n--;
for (j = 1; j <= i; j++)
{
Console.Write(" " + "*");//i
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
4.Write a console program to print the following pattern?
* * * * *
* * * *
* * *
* *
*
namespace triangle
{
class Program
{
static void Main(string[] args)
{
int i, j, k,l = 4;
for (i = 1; i <= 5; i++)
{
for (k = l; k >= 1; k--)
{
Console.Write(" ");
}
l++;
for (j = 1; j <= i; j++)
{
Console.Write(" " + "*");//i
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
* * * *
* * *
* *
*
namespace triangle
{
class Program
{
static void Main(string[] args)
{
int i, j, k,l = 4;
for (i = 1; i <= 5; i++)
{
for (k = l; k >= 1; k--)
{
Console.Write(" ");
}
l++;
for (j = 1; j <= i; j++)
{
Console.Write(" " + "*");//i
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
5.Write a console program to print the following pattern?
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
namespace triangle
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n = 6, l = 3;
for (i = 1; i <= 5; i++)
{
for (k = n; k >= 1; k--)
{
Console.Write(" ");
}
n--;
for (j = 1; j <= i; j++)
{
Console.Write(" " + i);//*
}
Console.WriteLine("");
}
for (i = 4; i >= 1; i--)
{
for (k = l; k >= 1; k--)
{
Console.Write(" ");
}
l++;
for (j = 1; j <= i; j++)
{
Console.Write(" " + i);//*
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
2 2
3 3 3
4 4 4 4
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
namespace triangle
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n = 6, l = 3;
for (i = 1; i <= 5; i++)
{
for (k = n; k >= 1; k--)
{
Console.Write(" ");
}
n--;
for (j = 1; j <= i; j++)
{
Console.Write(" " + i);//*
}
Console.WriteLine("");
}
for (i = 4; i >= 1; i--)
{
for (k = l; k >= 1; k--)
{
Console.Write(" ");
}
l++;
for (j = 1; j <= i; j++)
{
Console.Write(" " + i);//*
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
6.Write a console program to print the following pattern?
c
c o
c o m
c o m p
c o m p u
c o m p u t
c o m p u t e
c o m p u t e r
static void Main(string[] args)
{
Console.WriteLine("enter u r string");
string a=Console.ReadLine();
string b = null;
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<i+1;j++)
{
b = b + a[i];
Console.Write(a[j]);
}
Console.WriteLine("\n");
}
Console.ReadLine();
}
c o
c o m
c o m p
c o m p u
c o m p u t
c o m p u t e
c o m p u t e r
static void Main(string[] args)
{
Console.WriteLine("enter u r string");
string a=Console.ReadLine();
string b = null;
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<i+1;j++)
{
b = b + a[i];
Console.Write(a[j]);
}
Console.WriteLine("\n");
}
Console.ReadLine();
}
7.Write a console program to print the following pattern?
1 2 3 4 5
6
7
8
9
10 11 12 13 14 15
static void Main(string[] args)
{
int i;
for(i=1;i<=15;i++)
{
if(i<5)
{
Console.Write(i+" ");
}
else if (i <10)
{
Console.WriteLine(i + " ");
}
else
{
Console.Write(i + " ");
}
}
Console.ReadLine();
}
{
Console.WriteLine("enter a letter");
char ch = char.Parse(Console.ReadLine());
switch(ch)
{
case 'a':Console.WriteLine("it is a vowel");
break;
case 'e':Console.WriteLine("it is a vowel");
break;
case 'i':Console.WriteLine("it is a vowel");
break;
case 'o':Console.WriteLine("it is a vowel");
break;
case 'u':Console.WriteLine("it is a vowel");
break;
default:Console.WriteLine("invalid character");
break;
}
Console.ReadLine();
}
{
Console.WriteLine("enter u r name");
string a =Console.ReadLine();
string b=null;
for(int
i=a.Length-1;i>=0;i--)
{
b=b+a[i];
}
if(a==b)
{
Console.WriteLine("string is polindrome");
}
else{
Console.WriteLine("string is not a polindrome");
}
Console.ReadLine();
}
}
{
int n = 1234, m = n,sum=0;
while (n >= 1)
{
int r = n % 10;
Console.Write(r);
n = n / 10;
}
Console.ReadLine();
}
{
Console.WriteLine("enter u r range");
int n = int.Parse(Console.ReadLine());
Console.WriteLine("list of even no's are:");
int sum = 0, cnt = 0;
for (int i = 2; i <= n; i = i + 2)
{
Console.WriteLine(i);
sum = sum + i;
cnt++;
}
Console.WriteLine("sum of even numbers are:" + sum);
Console.WriteLine("number of even no's are:" + cnt);
Console.ReadLine();
}
6
7
8
9
10 11 12 13 14 15
static void Main(string[] args)
{
int i;
for(i=1;i<=15;i++)
{
if(i<5)
{
Console.Write(i+" ");
}
else if (i <10)
{
Console.WriteLine(i + " ");
}
else
{
Console.Write(i + " ");
}
}
Console.ReadLine();
}
8.Check whether given letter is vowel or not?
static void Main(string[] args){
Console.WriteLine("enter a letter");
char ch = char.Parse(Console.ReadLine());
switch(ch)
{
case 'a':Console.WriteLine("it is a vowel");
break;
case 'e':Console.WriteLine("it is a vowel");
break;
case 'i':Console.WriteLine("it is a vowel");
break;
case 'o':Console.WriteLine("it is a vowel");
break;
case 'u':Console.WriteLine("it is a vowel");
break;
default:Console.WriteLine("invalid character");
break;
}
Console.ReadLine();
}
9.Check the given string is polindrome or not?
static void Main(string[] args){
Console.WriteLine("enter u r name");
string a =Console.ReadLine();
string b=null;
for(int
i=a.Length-1;i>=0;i--)
{
b=b+a[i];
}
if(a==b)
{
Console.WriteLine("string is polindrome");
}
else{
Console.WriteLine("string is not a polindrome");
}
Console.ReadLine();
}
}
10.reverse a given number?
static void Main(string[] args){
int n = 1234, m = n,sum=0;
while (n >= 1)
{
int r = n % 10;
Console.Write(r);
n = n / 10;
}
Console.ReadLine();
}
11.Write a program for sum of & count of even numbers?
static void Main(string[] args){
Console.WriteLine("enter u r range");
int n = int.Parse(Console.ReadLine());
Console.WriteLine("list of even no's are:");
int sum = 0, cnt = 0;
for (int i = 2; i <= n; i = i + 2)
{
Console.WriteLine(i);
sum = sum + i;
cnt++;
}
Console.WriteLine("sum of even numbers are:" + sum);
Console.WriteLine("number of even no's are:" + cnt);
Console.ReadLine();
}
12.Write a console program to print the following pattern?
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
static void Main(string[] args)
{
int i=1, j=1;
while(i<=5)
{
for (j = 1; j <= i; j++)
{
Console.Write(j);
}
i++;
Console.WriteLine("");
}
Console.ReadLine();
}
Dear friends you also try your own programs and post to www.goodfriends5.com and i do any mistakes please comment on my post and also share your friends through Facebook,twitter,Google+..
1 2
1 2 3
1 2 3 4
1 2 3 4 5
static void Main(string[] args)
{
int i=1, j=1;
while(i<=5)
{
for (j = 1; j <= i; j++)
{
Console.Write(j);
}
i++;
Console.WriteLine("");
}
Console.ReadLine();
}
Dear friends you also try your own programs and post to www.goodfriends5.com and i do any mistakes please comment on my post and also share your friends through Facebook,twitter,Google+..
0 comments:
Post a Comment