0% found this document useful (0 votes)
4 views9 pages

Prac1 AWP

Uploaded by

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

Prac1 AWP

Uploaded by

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

TYIT A Advance web programming

PRACTICAL NO.1
a) Aim : Enter 4 number and find the product of the same.

➢ Code:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine("Roll No 742 - TYIT A");


int num1, num2, num3, num4, prod;
Console.Write("Enter number 1:");
num1 = Int32.Parse(Console.ReadLine());
Console.Write("Enter number 2:");
num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 3:");
num3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 4:");
num4 = Convert.ToInt32(Console.ReadLine());
prod = num1 * num2 * num3 * num4;
Console.WriteLine(num1 + "*" + num2 + "*" + num3 + "*" + num4 + "=" + prod);
Console.ReadKey();
}

⮚ Output:

Sem 5 Roll no : 739


TYIT A Advance web programming

b) Aim: Create an application to demonstrate String operation

⮚ Code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApp2_stringopperatio

internal class Program

static void Main(string[] args)

//Concatenation

Console.Write("739 pranav kadam \n");

Console.Write("Enter string 1:");

string words = Console.ReadLine();

Console.Write("Enter string 2:");

string words2 = Console.ReadLine();

string words3 = words + " " + words2;

Console.Write(words3);

//Length of given string

Console.Write(" Enter name:");

string name = Console.ReadLine();

int length = +name.Length;

Console.WriteLine("Length: " + length);

//Comparison

string str1 = "hello";

string str2 = "hello";

string str3 = "no hello";

Sem 5 Roll no : 739


TYIT A Advance web programming

// compare str1 and str2

Boolean result1 = str1.Equals(str2);

Console.WriteLine("str1 and str2 are equal: " + result1);

//compare str1 and str3

Boolean result2 = str1.Equals(str3);

Console.WriteLine("str1 and str3 are equal: " +

result2); object[] array = { "Neha", "Jyoti" };

// Using Join method

// Here separator is ', '( comma )

string s1 = string.Join(", ", array);

Console.WriteLine("Value of string s1 is : " + s1);

Console.ReadKey();

⮚ Output:

Sem 5 Roll no : 739


TYIT A Advance web programming

c) Create an application to demonstrate the following operations:

⮚ Aim: Write program using conditional statements & loops:

i. Aim: Generate Fibonacci series.

⮚Code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace prac1111

internal class Program

static void Main(string[] args)

Console.WriteLine("739 pranav kadam");

int a = 0, b = 1, c, n, counter;

Console.Write("enter the number:");

n = int.Parse(Console.ReadLine());

counter = 2;

Console.Write(a + "\n" + b);

while (counter <= n)

c = a + b;

if (counter >= n)

break;

Console.Write("\n" + c);

a = b; b = c;

counter++;

Sem 5 Roll no : 739


TYIT A Advance web programming

Console.ReadKey();

⮚ Output:

Sem 5 Roll no : 739


TYIT A Advance web programming

ii. Aim: Check whether the given number is “Prime” or not.


⮚ Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace prac1111
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("739 pranav kadam");
int n, counter;
Console.WriteLine("Enter the number:");
n = int.Parse(Console.ReadLine());
for (counter = 2; counter <= n / 2; counter++)
{
if (n % counter == 0)
break;
}
if (n <= 1)
Console.WriteLine(n + " neither prime nor composite");
else if (counter > n / 2) Console.WriteLine(n + " is prime");
else
Console.WriteLine(n + " is not prime");
Console.ReadKey();

}
}
}

⮚ Output:

Sem 5 Roll no : 739


TYIT A Advance web programming

iii. Aim: Check Whether the given character is Vowel or Not.


⮚ Code:

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

namespace prac1111
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("739 pranav kadam");
char ch;
Console.WriteLine("Enter the character:");
ch = (char)Console.Read();
switch (ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
Console.WriteLine(ch + " is vowel.");
break;
default:
Console.WriteLine(ch + " is consonant");
break;
}
Console.ReadKey();
}
}
}⮚ Output:

Sem 5 Roll no : 739


TYIT A Advance web programming

iv. Aim : Reverse given number & Find the sum of it.

⮚ Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace prac1111
{
internal class Program
{
static void Main(string[] args)
{

Console.WriteLine("739 pranav kadam");


int n, actual_n, revnum = 0, digit, sumdigit = 0;
Console.Write("enter the number:");
n = int.Parse(Console.ReadLine());
actual_n = n;
while (n > 0)
{
digit = n % 10;
revnum = revnum * 10 + digit;
sumdigit = sumdigit + digit;
n = n / 10;
}
Console.WriteLine("Reverse number of " + actual_n + " is " + revnum);
Console.WriteLine("Sum of the dighits of original number is: " + sumdigit);
Console.ReadKey();
}
}
}

⮚ Output:

Sem 5 Roll no : 739


TYIT A Advance web programming

v. Aim : Use of foreach loop with array


⮚ Code:

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

namespace prac1111
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("739 pranav kadam");
string[] str = { "sakshi", "pranav", "IT" };
foreach (String s in str)
{
Console.WriteLine(s);
}
Console.ReadKey();

}
}
}

⮚ Output:

Sem 5 Roll no : 739

You might also like