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)
{
[Link]("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$\n\n\n");
[Link]("Name: Dhvani J Bhesaniya\n");
[Link]("DOB: 06/12/2002\n");
[Link]("Address: 3/2 Gaiyatri nagar , bustand road
Gondal -3360311\n");
[Link]("City: Gondal\n");
[Link]("Pincode: 360311\n");
[Link]("State: Gujarat\n");
[Link]("Country: India\n");
[Link]("Email: dbhesaniya223@[Link]\n");
[Link]("\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;
[Link]("Enter a number : ");
n = [Link]([Link]());
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
if (n % 2 == 0)
{
[Link](n + " is an Even nember.");
}
else
{
[Link](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;
[Link]("Enter Number : ");
x = Convert.ToInt32(str);
[Link]("Number is Even");
else
[Link]();
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
string str = [Link]();
if (x % 2 == 0)
[Link]("Number is Odd");
}
}
}
class Program
using System;
Updated code:-
using System;
namespace ConsoleApplication1
{
class Program{
static void Main(string[] args)
{
int x;
[Link]("Enter Number : ");
[Link]();
string str = [Link]();
x = Convert.ToInt32(str);
if (x % 2 == 0)
[Link]("Number is Odd");
else
{
[Link]("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;
[Link]("Enter Number : ");
[Link]();
string str = [Link]();
n = Convert.ToInt32(str);
for (int i = 1; i <= n; i++)
{
fact = fact * i;
}
[Link]("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;
[Link]("Enter Number 1: ");
//Missing statement
a = Convert.ToInt32([Link]());
[Link]("Enter Number 2 : ");
//Missing statement
b = Convert.ToInt32([Link]());
[Link]("Enter Number 3 : ");
//Missing statement
c = Convert.ToInt32([Link]());
result = Sum(a, b, c);
//Missing statement
[Link]("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;
[Link]("Enter a number");
num1 = Convert.ToInt32([Link]());
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)
[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.
INPUT : John F Kennedy
OUTPUT: JOHN F KENNEDY
Code:-
using System;
public class alphabet
{
public static void Main(string[] args)
{
string c;
[Link]("Enter any alphabet: ");
c =[Link]();
string c1 = [Link]();
[Link](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="";
[Link]("Enter name :");
no = [Link]();
foreach (Char c in no)
{
if ([Link](c))
{
chr = chr + c;
n = n + [Link]();
}
else
{
chr = chr + c;
n = n + [Link]();
}
chr = "";
}
[Link](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;
[Link]("Enter a mobile no :");
no = [Link]();
no = [Link](5, 5) + "XXXXX";
[Link](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;
[Link]("Enter you name :");
name = [Link]();
[Link]("Enter Gender(M/F) :");
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
a = [Link]([Link]());
if (a == 'M' || a == 'm')
{
name = "Mr. " + name;
}
else
{
name = "Ms." + name;
}
[Link]("Name - "+name);
[Link]("Gender - "+a);
}
}
Output:
12 Write a Program which accepts name from the user and prints the same
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
string b;
[Link]("Enter your name : ");
b = [Link]();
[Link](b);
[Link]();
}
}
}
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;
[Link]("Enter the number of elements: ");
number = [Link]([Link]());
[Link](n1 + " " + n2 + " ");
for (i = 2; i < number; ++i)
{
n3 = n1 + n2;
[Link](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;
[Link]("Enter any number to print in words: ");
n = Convert.ToInt32([Link]());
while (n != 0)
{
num = (num * 10) + (n % 10);
n /= 10;
}
while (num != 0)
{
switch (num % 10)
{
case 0:
[Link]("zero ");
break;
case 1:
[Link]("one ");
break;
case 2:
[Link]("two ");
break;
case 3:
[Link]("three ");
break;
case 4:
[Link]("four ");
DHANKECHA PRAKASH BHARATBHAI CE
21SOECE13012 Enterprise Computing Through .NET Framework (CE525)
break;
case 5:
[Link]("five ");
break;
case 6:
[Link]("six ");
break;
case 7:
[Link]("seven ");
break;
case 8:
[Link]("eight ");
break;
case 9:
[Link]("nine ");
break;
}
num = num / 10;
}
[Link]();
}
}
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;
[Link]("Enter the Number= ");
n = [Link]([Link]());
temp = n;
while (n > 0)
{
r = n % 10;
sum = sum + (r * r * r);
n = n / 10;
}
if (temp == sum)
[Link]("Armstrong Number.");
else
[Link]("Not Armstrong Number.");
}
}
Output
DHANKECHA PRAKASH BHARATBHAI CE