Tutorial 1
Tutorial 1
Tutorial 1
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("ABHAY SHUKLA");
Console.WriteLine("hello world!!");
Console.ReadLine();
}
}
}
Output:
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("ABHAY");
Console.WriteLine("Enter Your Name : ");
string name = Console.ReadLine();
Output:
3.Find out whether the given number is odd or even
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
Console.WriteLine("Enter One Number : ");
int num =Convert.ToInt32(Console.ReadLine());
if (num%2 == 0 )
{
Console.WriteLine("Number is Even");
}
else
{
Console.WriteLine("Number is odd");
}
Console.ReadLine();
}
}
}
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 System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
int num;
Console.WriteLine("Enter One Number : ");
num =Convert.ToInt32(Console.ReadLine());
if (num%2 == 0 )
{
Console.WriteLine("Number is Even");
}
else
{
Console.WriteLine("Number is odd");
}
Console.ReadLine();
}
}
}
Output:
5. Write output of the program. Also write comment for each line for the following
code.
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
int n, fact = 1;
Console.ReadLine();
}
}
}
Output:
namespace ConsoleApp2
{
internal class Program
{
static int Sum(int x, int y, int z)
{
Console.WriteLine("Abhay");
int res;
res = x + y + z;
return res;
}
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int c = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(result);
Console.Read();
Output:
namespace ConsoleApp2
{
internal class Program
{
Console.WriteLine("Enter a number");
num1 = Convert.ToInt32(Console.ReadLine());
i = 1; //Initialization
}
}
Output:
8. Write a program to convert given name in upper characters.
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
Output:
namespace ConsoleApp2
{
internal class Program
{
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 System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
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 System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
Output:
12. Write a Program which accepts name from the user and prints the same
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
Output:
namespace ConsoleApp2
{
internal class Program
{
14.Write 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 System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
private static string[] digits = { "zero", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine" };
static void Main(string[] args)
{
Console.WriteLine("Abhay");
int number;
Console.WriteLine("Enter a number: ");
number = int.Parse(Console.ReadLine());
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
int number, temp, sum = 0;
Console.WriteLine("Enter a number: ");
number = int.Parse(Console.ReadLine());
temp = number;
while (temp > 0)
{
int digit = temp % 10;
sum += digit * digit * digit;
temp = temp / 10;
}
if (number == sum)
{
Console.WriteLine(number + " is an Armstrong number.");
}
else
{
Console.WriteLine(number + " is not an Armstrong number.");
}
Console.ReadLine();
}
}
}
Output:
16.Write a program to display a pattern like a right angle triangle using an asterisk
The pattern like :
*
**
***
****
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
int rows;
Console.WriteLine("Enter the number of rows: ");
rows = int.Parse(Console.ReadLine());
Output:
17. Write a Program to generate following output.
1
12
123
1234
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
int rows;
Console.WriteLine("Enter the number of rows: ");
rows = int.Parse(Console.ReadLine());
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 System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
Console.WriteLine("Enter the number of row : ");
int rows = int.Parse(Console.ReadLine());
int number = 1;
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Output:
19. Write a program to make such a pattern as a pyramid with an asterisk.
*
**
***
****
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
Console.WriteLine("Enter the number of row : ");
int rows = int.Parse(Console.ReadLine());
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Output:
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abhay");
Console.WriteLine("Enter the number of row : ");
int rows = int.Parse(Console.ReadLine());
Console.WriteLine();
}
Console.ReadLine();
}
}
}
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 System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
Console.WriteLine("Abhay");
Console.Write("enter the digit : ");
int n =Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
int m = n;
int sum = 0;
for (int i = 0; i < n; i++)
{
Console.Write(m+" + ");
sum=sum+m;
m = m * 10 + n;
}
Console.WriteLine();
Console.WriteLine("the sum = " + sum);
Console.ReadLine();
}
}
}
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("abhay");
Console.WriteLine("Enter number of row : ");
Console.WriteLine();
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Output: