0% found this document useful (1 vote)
895 views11 pages

AWP Practical 1-1

This document contains source code for several C# and ASP.NET programming exercises. It includes code to get user input and display output, perform basic math operations on numbers, demonstrate string methods, store and display student data, generate Fibonacci sequences, test for prime and vowel characters, use foreach loops with arrays, reverse numbers and calculate digit sums. The code provides examples of common programming tasks and concepts in C# and ASP.NET.

Uploaded by

sushil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
895 views11 pages

AWP Practical 1-1

This document contains source code for several C# and ASP.NET programming exercises. It includes code to get user input and display output, perform basic math operations on numbers, demonstrate string methods, store and display student data, generate Fibonacci sequences, test for prime and vowel characters, use foreach loops with arrays, reverse numbers and calculate digit sums. The code provides examples of common programming tasks and concepts in C# and ASP.NET.

Uploaded by

sushil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

T.Y.B.SC. (I.T.) - ASP.

NETWITHC# IT-7239
2018-2019

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.) - ASP.NETWITHC# IT-7239
2018-2019

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.) - ASP.NETWITHC# IT-7239
2018-2019

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.) - ASP.NETWITHC# IT-7239
2018-2019

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.) - ASP.NETWITHC# IT-7239
2018-2019

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.

Page 5
T.Y.B.SC. (I.T.) - ASP.NETWITHC# IT-7239
2018-2019

Source Code: - CS Code

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;
}
}
}

Page 6
T.Y.B.SC. (I.T.) - ASP.NETWITHC# IT-7239
2018-2019

public void fibo()


{
int n, f = 0, s = 1, c, next;
Console.WriteLine("Enter the no. of terms");
n = Convert.ToInt32(Console.ReadLine());
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");
}

Page 7
T.Y.B.SC. (I.T.) - ASP.NETWITHC# IT-7239
2018-2019

Console.Read();
}
public void fe()
{
string[] str = { "it", "cs", "math" };
foreach (string i in str)
{
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.) - ASP.NETWITHC# IT-7239
2018-2019

Page 9
T.Y.B.SC. (I.T.) - ASP.NETWITHC# IT-7239
2018-2019

Page 10
T.Y.B.SC. (I.T.) - ASP.NETWITHC# IT-7239
2018-2019

Page 11

You might also like