21SOECE13012 Enterprise Computing Through .
NET Framework (CE525)
Tutorial – 1
1. Write a C program to print “Hello World” on the output screen.
#include<stdio.h>
#include<conio.h>
void main()
{
//This program is to demonstrate print function
clrscr();
printf(“Hello World”);
getch();
}
Output:
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
2 : Design your profile page as given below.
Code:-
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$\n\n\n");
Console.WriteLine("Name: Dhvani J Bhesaniya\n");
Console.WriteLine("DOB: 06/12/2002\n");
Console.WriteLine("Address: 3/2 Gaiyatri nagar , bustand road
Gondal -3360311\n");
Console.WriteLine("City: Gondal\n");
Console.WriteLine("Pincode: 360311\n");
Console.WriteLine("State: Gujarat\n");
Console.WriteLine("Country: India\n");
Console.WriteLine("Email: dbhesaniya223@rku.ac.in\n");
Console.WriteLine("\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$");
}
}
}
Output:-
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
3 : Find out whether the given number is odd or even.
Code:-
using System;
namespace dotnet_sample
{
class Program
{
static void Main(string[] args)
{
int n;
Console.WriteLine("Enter a number : ");
n = int.Parse(Console.ReadLine());
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
if (n % 2 == 0)
{
Console.WriteLine(n + " is an Even nember.");
}
else
{
Console.WriteLine(n + " is an odd number.");
}
}
}
}
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.
Given code:-
namespace ConsoleApplication1
{
{
static void Main(string[] args)
{
int x;
Console.WriteLine("Enter Number : ");
x = Convert.ToInt32(str);
Console.WriteLine("Number is Even");
else
Console.Read();
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
string str = Console.ReadLine();
if (x % 2 == 0)
Console.WriteLine("Number is Odd");
}
}
}
class Program
using System;
Updated code:-
using System;
namespace ConsoleApplication1
{
class Program{
static void Main(string[] args)
{
int x;
Console.WriteLine("Enter Number : ");
Console.Read();
string str = Console.ReadLine();
x = Convert.ToInt32(str);
if (x % 2 == 0)
Console.WriteLine("Number is Odd");
else
{
Console.WriteLine("Number is Even");
}
}
}
}
Output:-
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
5 : Write output of the program. Also write comment for each line for the following
code.
Code:-
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n,fact=1;
Console.WriteLine("Enter Number : ");
Console.Read();
string str = Console.ReadLine();
n = Convert.ToInt32(str);
for (int i = 1; i <= n; i++)
{
fact = fact * i;
}
Console.WriteLine("Factorial : {0}",fact);
}
}
}
Output:-
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
6 : Write missing statement to get the desired output.
Updated code:-
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b, c, result;
Console.Write("Enter Number 1: ");
//Missing statement
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Number 2 : ");
//Missing statement
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Number 3 : ");
//Missing statement
c = Convert.ToInt32(Console.ReadLine());
result = Sum(a, b, c);
//Missing statement
Console.WriteLine("Sum : " + result);
}
static int Sum(int x, int y, int z)
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
{
int res;
res = x + y + z;
return res;
}
}
}
Output:-
7 : Predict and write the output of the given code.
Code:-
using System;
namespace While_Loop
{
class Program
{
static void Main(string[] args)
{
int num1,res, i;
Console.WriteLine("Enter a number");
num1 = Convert.ToInt32(Console.ReadLine());
i = 1; //Initialization
//Check whether condition matches or not
while (i <= 10)
{
res = num1 * i;
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
Console.WriteLine("{0} x {1} = {2}", num1, i, res);
i++; //Increment by one
}
//Console.ReadLine();
}
}
}
Output:-
8 Write a program to convert given name in upper characters.
INPUT : John F Kennedy
OUTPUT: JOHN F KENNEDY
Code:-
using System;
public class alphabet
{
public static void Main(string[] args)
{
string c;
Console.Write("Enter any alphabet: ");
c =Console.ReadLine();
string c1 = c.ToUpper();
Console.Write(c1);
}
}
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
Output:-
9 Write a Program to convert given name in toggle case.
INPUT : JoHn F kEnNedy
OUTPUT: jOhN f KeNneDY
Code:
using System;
class HelloWorld {
static void Main() {
string no,n="",chr="";
Console.WriteLine("Enter name :");
no = Console.ReadLine();
foreach (Char c in no)
{
if (Char.IsUpper(c))
{
chr = chr + c;
n = n + chr.ToLower();
}
else
{
chr = chr + c;
n = n + chr.ToUpper();
}
chr = "";
}
Console.WriteLine(n);
}
}
Output :
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
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;
namespace console2
{
class Program
{
static void Main(string[] args)
{
int n;
String no;
Console.WriteLine("Enter a mobile no :");
no = Console.ReadLine();
no = no.Remove(5, 5) + "XXXXX";
Console.WriteLine(no);
}
}
}
Output :
11 Write a Program which accepts name and gender from the user. Here, gender may have only 1
character, M or F.
Based on the gender prefix the name Mr. & Ms.
->
using System;
class HelloWorld {
static void Main() {
String name;
char a;
Console.WriteLine("Enter you name :");
name = Console.ReadLine();
Console.WriteLine("Enter Gender(M/F) :");
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
a = Convert.ToChar(Console.ReadLine());
if (a == 'M' || a == 'm')
{
name = "Mr. " + name;
}
else
{
name = "Ms." + name;
}
Console.WriteLine("Name - "+name);
Console.WriteLine("Gender - "+a);
}
}
Output:
12 Write a Program which accepts name from the user and prints the same
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
string b;
Console.Write("Enter your name : ");
b = Console.ReadLine();
Console.WriteLine(b);
Console.ReadKey();
}
}
}
Output
13) Write a Program to prints the following series
using System;
public class ArmstrongExample
{
public static void Main(string[] args)
{
int n1 = 0, n2 = 1, n3, i, number;
Console.Write("Enter the number of elements: ");
number = int.Parse(Console.ReadLine());
Console.Write(n1 + " " + n2 + " ");
for (i = 2; i < number; ++i)
{
n3 = n1 + n2;
Console.Write(n3 + " ");
n1 = n2;
n2 = n3;
}
}
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
}
Output
14 ) Write a Program which accepts no from the user and print the same in words.
using System;
public class ArmstrongExample
{
public static void Main(string[] args)
{
int n, num = 0;
Console.WriteLine("Enter any number to print in words: ");
n = Convert.ToInt32(Console.ReadLine());
while (n != 0)
{
num = (num * 10) + (n % 10);
n /= 10;
}
while (num != 0)
{
switch (num % 10)
{
case 0:
Console.Write("zero ");
break;
case 1:
Console.Write("one ");
break;
case 2:
Console.Write("two ");
break;
case 3:
Console.Write("three ");
break;
case 4:
Console.Write("four ");
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
break;
case 5:
Console.Write("five ");
break;
case 6:
Console.Write("six ");
break;
case 7:
Console.Write("seven ");
break;
case 8:
Console.Write("eight ");
break;
case 9:
Console.Write("nine ");
break;
}
num = num / 10;
}
Console.ReadLine();
}
}
Output
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
15 ) Write a Program to check whether the given no is Armstrong no or not.
using System;
public class ArmstrongExample
{
public static void Main(string[] args)
{
int n, r, sum = 0, temp;
Console.Write("Enter the Number= ");
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.");
else
Console.Write("Not Armstrong Number.");
}
}
Output
DHANKECHA PRAKASH BHARATBHAI CE