Sunteți pe pagina 1din 10

T.Y.B.Sc. (I.T.

) – Advanced Web Programming –Paper (III) [Your Roll No]

Practical No: [1]: Working with basic C# and ASP .NET

a) Create an application that obtains four int values from the user and displays the
product.

Source Code: - CS Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplDiv2
{
class product
{
Static void Main (string [] args)
{
Console.WriteLine ("enter1st no’s");
int a = Convert.ToInt32 (Console.ReadLine());

Console.WriteLine ("enter 2nd no");


int b = Convert.ToInt32 (Console.ReadLine());

Console.WriteLine ("enter 3rd no");


int c = Convert.ToInt32 (Console.ReadLine ());

Console.WriteLine ("enter 4th no");


int d = Convert.ToInt32 (Console.ReadLine ());

Console.WriteLine (a*b*c*d);
Console.ReadLine ();
}
}
}

Output:-

Page 1
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

b) Create an application to demonstrate string operations.

Source Code: - CS Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleAppDiv2

class @string

static void Main(string[] args)

Page 2
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

String S1 = "good handwriting", ans;

String S2 = "topper";

String S3 = " ";

ans = S1.ToUpper();

Console.WriteLine(ans);

ans = S1.Trim();

Console.WriteLine(ans);

ans = S1.Insert(2, "p");

Console.WriteLine(ans);

ans = S1.ToLower();

Console.WriteLine(ans);

ans = String.Concat(S1,S2);

Console.WriteLine(ans);

bool b=S1.EndsWith("g");

Console.WriteLine(b);

int a=S2.CompareTo(S1);

Console.WriteLine(a);

S3=String.Copy(S1);

Console.WriteLine(S3);

Console.Read();

Output:-

Page 3
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

c) Create an application that receives the (Student Id, Student Name, Course Name, Date of
Birth) information from a set of students. The application should also display the information
of all the students once the data entered.

Source Code: - CS Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppDiv2
{
class STUDENT
{
static void Main(string[] args)
{
int s_id, i;
string name, cname, DOB;
int[] id = new int[10];
string[] s_name = new string[10];
string[] c_name = new string[10];
string[] D_O_B = new string[10];
for (i = 0; i < 2; i++)
{
Console.WriteLine("enter student ID");
s_id = Convert.ToInt32(Console.ReadLine());
id[i] = s_id;

Console.WriteLine("enter student name");


name = Console.ReadLine();
s_name[i] = name;

Page 4
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

Console.WriteLine("enter student cname");


cname = Console.ReadLine();
c_name[i] = cname;

Console.WriteLine("enter student DOB");


DOB = Console.ReadLine();
D_O_B[i] = DOB;
}
for (i = 0; i < 2; i++)
{
Console.WriteLine("id: {0} s_name:{1} c_name:{2} D_O_B:{3}", id[i],
s_name[i], c_name[i], D_O_B[i]);
}
Console.ReadKey();
}
}
}

Output:-

d) Create an application to demonstrate following operations


i. Generate Fibonacci series. ii. Test for prime numbers.
iii. Test for vowels. iv. Use of foreach loop with arrays
v. Reverse a number and find sum of digits of a number.

Source Code: - CS Code

Page 5
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppDiv2
{
class p1e3
{
static void Main(string[] args)
{
p1e3 p = new p1e3();
int a;
Console.WriteLine("1.Fibonacci 2.Prime or not 3.Vowel 4.for-each loop
5.Sum of digits of number 6.Reverse");
Console.WriteLine("Enter your choice");
a = Convert.ToInt32(Console.ReadLine());
switch (a)
{
case 1:
{
p.fibo();
break;
}
case 2:
{
p.prime();
break;
}
case 3:
{
p.vowel();
break;
}
case 4:
{
p.fe();
break;
}
case 5:
{
p.sum();
break;
}
case 6:
{
p.reverse();
break;
}
default:
{
Console.WriteLine("Try again");
break;
}
}
}
public void fibo()
{
int n, f = 0, s = 1, c, next;
Console.WriteLine("Enter the no. of terms");
n = Convert.ToInt32(Console.ReadLine());

Page 6
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

Console.WriteLine("Fibbo series");
for (c = 0; c < n; c++)
{
if (c <= 1)
{
next = c;
}
else
{
next = f + s;
f = s;
s = next;
}
Console.WriteLine("{0}", next);
}
Console.ReadLine();
}
public void prime()
{
int n, flag = 0;
int p = 2;
Console.WriteLine("Enter a number");
n = Convert.ToInt32(Console.ReadLine());
while (n != p)
{
if (n % p == 1)
{
flag++;
}

p++;
}
if (flag == 1)
{
Console.WriteLine("Number is not prime");
}
else
{
Console.WriteLine("Number is prime");
}
Console.ReadLine();
}
public void vowel()
{
char t;
Console.WriteLine("enter an alphabet");
t = Convert.ToChar(Console.ReadLine());
if (t == 'a' || t == 'e' || t == 'i' || t == 'o' || t == 'u')
{
Console.WriteLine("the character is a vowel");
}
else
{
Console.WriteLine("not a vowel");
}
Console.Read();
}
public void fe()
{
string[] str = { "it", "cs", "math" };
foreach (string i in str)
{

Page 7
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

Console.WriteLine(i);
Console.Read();
}

public void reverse()


{
int n,reverse=0,rem;
Console.Write("enter a number:" );
n=int.Parse(Console.ReadLine());
while (n!= 0)
{
rem=n % 10;
reverse=reverse*10+rem;
n/=10;
}
Console.Write("reversed number:" +reverse);
Console.Read();
}

public void sum()


{
int num, sum = 0, r;
Console.WriteLine("enter a number:");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
r = num % 10;
num = num / 10;
sum = sum + r;

}
Console.WriteLine("sum of digits of the number:");
Console.Read();
}
}
}

Output:-

Page 8
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

Page 9
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

Page 10

S-ar putea să vă placă și