Part 1 - Basic C# programming Problem and Solutions
Part 3 - Basic C# Programming Problem and Solutions
Today I am writing this article for the beginners who have just begun programming in the C# language. I have solved all the basic problems of the C# programming. Today I will show you Part 2 of my article series Basic C# Programming Problems. It contain 15 problems.
Problem 16
Write a program that takes one value from the user and checks whether the entered value is a character, integer or special symbol.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Problem16 {
class Problem16 {
static void Main(string[] args) {
char a;
int b;
Console.WriteLine("Enter A Value:");
a = Convert.ToChar(Console.ReadLine());
b = (int) a;
if (b >= 65 && b <= 90) {
a = (char) b;
Console.WriteLine("Entered Value Is Character:" + a);
}
if (b >= 97 && b <= 122) {
Console.WriteLine("Entered Value Is Character:" + a);
}
if (b >= 48 && b <= 57) {
Console.WriteLine("Entered Value Is Integer:" + a);
}
if (b == 0 && b <= 47 || b >= 58 && b <= 64 || b >= 91 && b <= 96 || b >= 123 && b <= 127) {
Console.WriteLine("Entered Value Is Special Symbols:");
}
Console.ReadKey();
}
}
}
Output

Problem 17
Write a program that takes an integer as an input from the user and prints if it is a prime or composite number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Problem17 {
class Problem17 {
static void Main(string[] args) {
int num;
int i = 2;
Console.WriteLine("Enter A Number:");
num = Convert.ToInt32(Console.ReadLine());
while (i < num) {
if (num % i == 0) {
Console.WriteLine("Entered Number Is A Composite Number.");
break;
}
i++;
}
if (i == num) {
Console.WriteLine("Entered Number Is A Prime Number.");
}
if (num == 0 || num == 1) {
Console.WriteLine("Entered Number Is Not A Composite Number Nor A Prime Number.");
}
Console.ReadKey();
}
}
}
Output

Problem 18
Write a program that prints the Fibonacci series using a loop.
1 1 2 3 5 8 13 21 34 …
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Problem18 {
class Problem18 {
static void Main(string[] args) {
int num;
int next;
int first = 0;
int second = 1;
Console.WriteLine("Enter The Number Of Terms Of Fibonacci Series You Want:");
num = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < num; i++) {
if (i <= 1) {
next = i;
} else {
next = first + second;
first = second;
second = next;
}
Console.Write(next);
Console.Write(" ");
}
Console.ReadKey();
}
}
}
Output

Problem 19
Write a program using a for loop that prints the following output on the screen.
*
**
***
****
***
**
*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Problem19
{
class Problem19
{
static void Main(string[] args)
{
Console.WriteLine("\t\tName: Ehtesham Mehmood\n\t\tRoll No: 11014119-131\n\t\tSection: AE\n \t\t UOG\n");
for (int i = 0; i < 4; i++)
{
for (int j = 0; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine("\n");
}
for (int i = 0; i <= 2; i++)
{
for (int j = 3; j > i; j--)
{
Console.Write("*");
}
Console.WriteLine("\n");
}
Console.ReadKey();
}
}
}
Output

Problem 20
Write a program using a for loop that prints the following output on the screen.
*
***
*****
*******
*********
***********
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Problem20
{
class Problem20
{
static void Main(string[] args)
{
int num;
int k = 0;
Console.WriteLine("Enter The Value To Draw A Rectangle Shape:");
num = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < num; i++)
{
for (int j = 0; j <= k; j++)
{
Console.Write("*");
}
Console.WriteLine("\n");
k += 2;
}
Console.ReadKey();
}
}
}
Output

Problem 21
Write a program to print all Armstrong numbers between 1 and 500. If the sum of the cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = (1 * 1 * 1) + (5 * 5 * 5) + (3 * 3 * 3).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Problem21
{
class Problem21
{
static void Main(string[] args)
{
int FirstDigit, SecondDigit, LastDigit, num;
Console.WriteLine("All Armstrong Numbers Between 1 And 500.\n");
for (int i = 1; i <= 500; i++)
{
num = i;
LastDigit = num % 10;
num = num / 10;
SecondDigit = num % 10;
num = num / 10;
FirstDigit = num % 10;
if ((FirstDigit * FirstDigit * FirstDigit) + (SecondDigit * SecondDigit * SecondDigit) + (LastDigit * LastDigit * LastDigit) == i)
{
Console.WriteLine("This Is A Armstrong Number:" + i);
}
}
Console.ReadKey();
}
}
}
Output

Problem 22
Write a program using a for loop that prints the following output on the screen.
$$$$$$$$$$$
$ $
$ $
$ $
$$$$$$$$$$
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Problem22
{
class Problem22
{
static void Main(string[] args)
{
int check1 = 1;
int check2 = 2;
int check3 = 3;
for (int a = 1; a <= 11; a++)
{
Console.Write("$");
}
Console.WriteLine("\n");
for (int b = 1; b <= 3; b++)
{
for (int c = 1; c <= 1; c++)
{
Console.Write("$");
}
if (b == check1)
{
for (int d = 1; d <= 9; d++)
{
Console.Write(" ");
}
}
if (b == check2)
{
for (int d = 1; d <= 8; d++)
{
Console.Write(" ");
}
}
if (b == check3)
{
for (int d = 1; d <= 8; d++)
{
Console.Write(" ");
}
}
Console.Write("$");
Console.WriteLine("\n");
}
for (int e = 1; e <= 10; e++)
{
Console.Write("$");
}
Console.ReadKey();
}
}
}
Output

Problem 23
Write a program using a loop that takes one value n from the user and shows the factorial of all prime numbers that are less then n, for example if n = 10 then the program will print the factorial of 2, 3, 5 and 7.









Numan MazharPosted Nov 22, 2016, 2:17 AM
Salam. it is very helpful me. Plz tell me where are you collect these problems.