Tutorial – 1
1. Write a program to print “Hello World”.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
[Link]("ABHAY SHUKLA");
[Link]("hello world!!");
[Link]();
}
}
}
Output:
[Link] your profile page as given below.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Name: Ramesh Tamkuity
DOB: 15/10/1991
Address: 4, xyx society, Kalawad Road
City: Rajkot
Pincode: 360 001
State: Gujarat
Country: India
Email: abc@[Link]
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("ABHAY");
[Link]("Enter Your Name : ");
string name = [Link]();
[Link]("Enter Your DOB : ");
string DOB = ([Link]());
[Link]("Enter Your Adress : ");
string adress = [Link]();
[Link]("Enter Your Pincode : ");
int pincode = Convert.ToInt32([Link]());
[Link]("Enter Your State : ");
string state = [Link]();
[Link]("Enter Your Country : ");
string country = [Link]();
[Link]("Enter Your Email Adress : ");
string email = [Link]();
[Link]("Name : " + name);
[Link]("DOB : " + DOB);
[Link]("Adress : " + adress);
[Link]("Pincode : " + pincode);
[Link]("State : " + state);
[Link]("Country : " + country);
[Link]("Email : " + email);
[Link]();
}
}
}
Output:
[Link] out whether the given number is odd or even
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter One Number : ");
int num =Convert.ToInt32([Link]());
if (num%2 == 0 )
{
[Link]("Number is Even");
}
else
{
[Link]("Number is odd");
}
[Link]();
}
}
}
Output:
4. Rearrange the given code to correct the program. The resultant program will be to
input a number and print whether the given number is odd or even.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
int num;
[Link]("Enter One Number : ");
num =Convert.ToInt32([Link]());
if (num%2 == 0 )
{
[Link]("Number is Even");
}
else
{
[Link]("Number is odd");
}
[Link]();
}
}
}
Output:
5. Write output of the program. Also write comment for each line for the following
code.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
int n, fact = 1;
[Link]("Enter Number : ");
string str = [Link](); // taking input from user
n = Convert.ToInt32(str); // convert sring to intrger
for (int i = 1; i <= n; i++)
fact = fact * i; //claculate the fectorial of given number
}
[Link]("Factorial : {0}", fact); // giving output
[Link]();
}
}
}
Output:
6. Write missing statement to get the desired output.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static int Sum(int x, int y, int z)
{
[Link]("Abhay");
int res;
res = x + y + z;
return res;
}
static void Main(string[] args)
{
[Link]("Enter Number 1: ");
int a = Convert.ToInt32([Link]());
[Link]("Enter Number 2 : ");
int b = Convert.ToInt32([Link]());
[Link]("Enter Number 3 : ");
int c = Convert.ToInt32([Link]());
int result = Sum(a, b, c);
[Link](result);
[Link]();
Output:
7. Predict and write the output of the given code.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
int num1, res, i;
[Link]("Enter a number");
num1 = Convert.ToInt32([Link]());
i = 1; //Initialization
//Check whether condition matches or not
while (i <= 10)
{
res = num1 * i;
[Link]("{0} x {1} = {2}", num1, i, res);
i++; //Increment by one
}
[Link]();
}
}
}
Output:
8. Write a program to convert given name in upper characters.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter One String : ");
string st = [Link]();
st = [Link]();
[Link](st);
[Link]();
}
Output:
9. Write a Program to convert given name in toggle case
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter One String : ");
string st = [Link]();
st = [Link]();
[Link](st);
[Link]();
}
Output:
10. Write a Program which accepts mobile no as a string from the user and converts the
last 5 digits into X.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter your mobile number : ");
string mobileNumber = [Link]();
int lastIndex = [Link] - 5;
string lastFiveDigits = [Link](lastIndex);
string newMobileNumber = [Link](lastFiveDigits, "XXXXX");
[Link](newMobileNumber);
[Link]();
}
}
}
Output:
11. Write a Program which accepts name and gender from the user. Here, gender may
have only 1 character, M or F.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter your name : ");
string name = [Link]();
[Link]("Enter your gender (M/F) : ");
string gender = [Link]();
if (gender == "M")
{
[Link]("Mr. " + name);
}
else if (gender == "F")
{
[Link]("Ms. " + name);
}
else
{
[Link]("invelid choice");
}
[Link]();
}
}
}
Output:
12. Write a Program which accepts name from the user and prints the same
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter your name : ");
string name = [Link]();
[Link](name);
[Link]();
}
}
Output:
13. Write a Program to prints the following series
0 1 1 2 3 5 8 13 21 34 55
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
int n1 = 0, n2 = 1, n3;
[Link]("0,1");
for (int i = 2; i < 11; i++)
{
n3 = n1 + n2;
[Link](",{0}", n3);
n1 = n2;
n2 = n3;
}
[Link]();
}
}
}
Output:
[Link] a Program which accepts no from the user and print the same in words.
INPUT : 98732
OUTPUT: Nine Eight Seven Three Two
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
private static string[] digits = { "zero", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine" };
static void Main(string[] args)
{
[Link]("Abhay");
int number;
[Link]("Enter a number: ");
number = [Link]([Link]());
string words = "";
while (number > 0)
{
int digit = number % 10;
words = digits[digit] + " " + words;
number = number / 10;
}
[Link]("The number in words is: " + words);
[Link]();
}
}
}
Output:
15. Write a Program to check whether the given no is Armstrong no or not.
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
int number, temp, sum = 0;
[Link]("Enter a number: ");
number = [Link]([Link]());
temp = number;
while (temp > 0)
{
int digit = temp % 10;
sum += digit * digit * digit;
temp = temp / 10;
}
if (number == sum)
{
[Link](number + " is an Armstrong number.");
}
else
{
[Link](number + " is not an Armstrong number.");
}
[Link]();
}
}
}
Output:
[Link] a program to display a pattern like a right angle triangle using an asterisk
The pattern like :
*
**
***
****
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
int rows;
[Link]("Enter the number of rows: ");
rows = [Link]([Link]());
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link]("*");
}
[Link]();
}
[Link]();
}
}
}
Output:
17. Write a Program to generate following output.
1
12
123
1234
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
int rows;
[Link]("Enter the number of rows: ");
rows = [Link]([Link]());
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link](j);
}
[Link]();
}
[Link]();
}
}
}
Output:
18. Write a program to make such a pattern like a right angle triangle with the number
increased by 1.
1
23
456
7 8 9 10
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter the number of row : ");
int rows = [Link]([Link]());
int number = 1;
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link]("{0} ", number++);
}
[Link]();
}
[Link]();
}
}
}
Output:
19. Write a program to make such a pattern as a pyramid with an asterisk.
*
**
***
****
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter the number of row : ");
int rows = [Link]([Link]());
for (int i = 1; i <= rows; i++)
{
for (int j = rows - i; j >= 1; j--)
{
[Link](" ");
}
for (int j = 1; j <= 2 * i - 1; j++)
{
[Link]("*");
}
[Link]();
}
[Link]();
}
}
}
Output:
20. Write a program to make a pyramid pattern with numbers increased by 1.
1
23
456
7 8 9 10
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Abhay");
[Link]("Enter the number of row : ");
int rows = [Link]([Link]());
for (int i = 1; i <= rows; i++)
{
for (int j = rows - i; j >= 1; j--)
{
[Link](" ");
}
for (int j = 1; j <= 2 * i - 1; j++)
{
[Link](j);
}
[Link]();
}
[Link]();
}
}
}
Output:
21. Write a program to find the sum of the series 5 +55 + 555 + 5555 + .. n terms.
Test Data :
Input the number of terms : 4
Input number : 5
Expected Output :
5 + 55 + 555 + 5555
The Sum is : 6170
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
[Link]("Abhay");
[Link]("enter the digit : ");
int n =Convert.ToInt32([Link]());
[Link]();
int m = n;
int sum = 0;
for (int i = 0; i < n; i++)
{
[Link](m+" + ");
sum=sum+m;
m = m * 10 + n;
}
[Link]();
[Link]("the sum = " + sum);
[Link]();
}
}
}
22. Write a program to display a pattern like a diamond.
*
***
*****
*******
*********
*******
*****
***
*
Code:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
[Link]("abhay");
[Link]("Enter number of row : ");
int rows = [Link]([Link]());
[Link]();
for (int i = 1; i <= rows; i++)
{
for (int j = rows - i; j >= 1; j--)
{
[Link](" ");
}
for (int j = 1; j <= 2 * i - 1; j++)
{
[Link]("*");
}
[Link]();
}
for (int i = rows - 1; i >= 1; i--)
{
for (int j = rows - i; j >= 1; j--)
{
[Link](" ");
}
for (int j = 1; j <= 2 * i - 1; j++)
{
[Link]("*");
}
[Link]();
}
[Link]();
}
}
}
Output: