0% found this document useful (0 votes)
75 views11 pages

AWT Assignment 1

The document contains 10 code examples of C# programs that demonstrate various programming concepts like functions, classes, methods, input/output, loops, and conditionals. The code examples range from simple math programs to printing company information to drawing shapes.

Uploaded by

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

AWT Assignment 1

The document contains 10 code examples of C# programs that demonstrate various programming concepts like functions, classes, methods, input/output, loops, and conditionals. The code examples range from simple math programs to printing company information to drawing shapes.

Uploaded by

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

AWT Assignment 1

Jaladhi Sonagara
1991106
1>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static int sum(int num1, int num2, int num3)
{
int total;
total = num1 + num2 + num3;
return total;
}
static void Main(string[] args)
{
Console.Write("\n\nFunction to calculate the sum of two numbers :\n");
Console.Write("--------------------------------------------------\n");
Console.Write("Enter a number1: ");
int n1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a number2: ");
int n2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a number3: ");
int n3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nThe sum of three numbers is : {0} \n", sum(n1, n2, n3));
}
}
}
Output:
2>
using System;
public class Exercise5
{
public static void Main()
{
double r, per_cir;
double PI = 3.14;
Console.WriteLine("Input the radius of the circle : ");
r = Convert.ToDouble(Console.ReadLine());
per_cir = 2 * PI * r;
Console.WriteLine("Perimeter of Circle : {0}", per_cir);
Console.Read();
}
}
Output:
3>
using System;
class PrintCompanyInformation
{
static void Main()
{
Console.Write("Please write your company name: ");
string companyName = Console.ReadLine();
Console.Write("Please write your company address: ");
string companyAddress = Console.ReadLine();
Console.Write("Please write your phone number: ");
long phoneNumber = long.Parse(Console.ReadLine());
Console.Write("Please write your fax number: ");
long faxNumber = long.Parse(Console.ReadLine());
Console.Write("Please write your company web-site: ");
string webSite = Console.ReadLine();
Console.Write("Please write Manager's first name: ");
string firstName = Console.ReadLine();
Console.Write("Please write Manager's last name: ");
string lastName = Console.ReadLine();
Console.Write("Please write Manager's age: ");
byte ageManager = byte.Parse(Console.ReadLine());
Console.Write("Please write Manager's phone: ");
long phoneManager = long.Parse(Console.ReadLine());
Console.WriteLine("{0}", companyName);
Console.WriteLine("Adress: {0}", companyAddress);
Console.WriteLine("Tel. {0}", phoneNumber);
Console.WriteLine("Fax. {0}", faxNumber);
Console.WriteLine("Web-site: {0}", webSite);
Console.WriteLine("Manager: {0}" + " " + "{1}" + " " + "(age: {2}," + " " + "tel.: {3})",
firstName,
lastName, ageManager, phoneManager);
}
}
Output:

4>
using System;
public class MaximumNumber
{
public static void Main()
{
int[] arr1 = new int[100];
int i, mx, n;
Console.Write("\n\nFind maximum and minimum element in an array :\n");
Console.Write("--------------------------------------------------\n");
Console.Write("Input the number of elements to be stored in the array :");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("Input {0} elements in the array :\n", n);
for (i = 0; i < n; i++)
{
Console.Write("element - {0} : ", i);
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
mx = arr1[0];

for (i = 1; i < n; i++)


{
if (arr1[i] > mx)
{
mx = arr1[i];
}
}
Console.Write("Maximum element is : {0}\n", mx);

}
}
Output:

5>
using System;
namespace Q5
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter first number: ");
int a = Int32.Parse(Console.ReadLine());
Console.Write("Enter second number: ");
int b = Int32.Parse(Console.ReadLine());

Console.WriteLine("{0} >= {1}", Math.Max(a, b), Math.Min(a, b));


}
}
}

Output:

6>
using System;
public class Exercise4
{
public static void Main()
{
int i, n, sum = 0;
double avg;
Console.Write("\n\n");
Console.Write("Read 10 numbers and calculate sum and average:\n");
Console.Write("----------------------------------------------");
Console.Write("\n\n");
Console.Write("Input the 10 numbers : \n");
for (i = 1; i <= 10; i++)
{
Console.Write("Number-{0} :", i);
n = Convert.ToInt32(Console.ReadLine());
sum += n;
}
avg = sum / 10.0;
Console.Write("The sum of 10 no is : {0}\nThe Average is : {1}\n", sum, avg);
}
}
Output:

7>
using System;
public class Exercise8
{
public static void Main()
{
int num1, num2, num3;
Console.Write("\n\n");
Console.Write("Find the largest of three numbers:\n");
Console.Write("------------------------------------");
Console.Write("\n\n");
Console.Write("Input the 1st number :");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the 2nd number :");
num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the 3rd number :");
num3 = Convert.ToInt32(Console.ReadLine());
if (num1 > num2)
{
if (num1 > num3)
{
Console.Write("The 1st Number is the greatest among three. \n\n");
}
else
{
Console.Write("The 3rd Number is the greatest among three. \n\n");
}
}
else if (num2 > num3)
Console.Write("The 2nd Number is the greatest among three \n\n");
else
Console.Write("The 3rd Number is the greatest among three \n\n");
}
}
Output:

8>
using System;
public class Exercise4
{
public static void Main()
{
int i, n, sum = 0;
double avg;
Console.Write("\n\n");
Console.Write("Read 10 numbers and calculate sum and average:\n");
Console.Write("----------------------------------------------");
Console.Write("\n\n");
Console.Write("Input the 10 numbers : \n");
for (i = 1; i <= 10; i++)
{
Console.Write("Number-{0} :", i);
n = Convert.ToInt32(Console.ReadLine());
sum += n;
}
avg = sum / 10.0;
Console.Write("The sum of 10 no is : {0}\nThe Average is : {1}\n", sum, avg);
}
}
Output:

9>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _8.PrintNNumbers
{
class Program
{
static void Main()
{
int n;
Console.Write("Enter the first number n:");
bool isnInt = int.TryParse(Console.ReadLine(), out n);
if (isnInt)
{
for (int i = 1; i <= n; i++)
{
Console.WriteLine(i);
}
}
else
{
Console.WriteLine("Not a valid entry! n is not an integer!");
}
}
}
}
Output:
10>
using System;
class IsoscelesTriangle
{
static void Main()
{
char a = '\u00A9';
Console.WriteLine(" " + " " + a + " ");
Console.WriteLine(" " + a + " " + a + " ");
Console.WriteLine(" " + a + " " + " " + " " + a + " ");
Console.WriteLine(a + " " + a + " " + a + " " + a);
}
}
Output:

You might also like