0% found this document useful (0 votes)
19 views6 pages

Task1 (20 CS 101)

The document contains 3 programming tasks submitted by a student. The first task involves writing a program to count even and odd numbers in an array. The second task finds the largest of 3 numbers using nested if/else statements. The third task determines a student's grade based on their marks using an else if ladder.

Uploaded by

Aleeza Anjum
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)
19 views6 pages

Task1 (20 CS 101)

The document contains 3 programming tasks submitted by a student. The first task involves writing a program to count even and odd numbers in an array. The second task finds the largest of 3 numbers using nested if/else statements. The third task determines a student's grade based on their marks using an else if ladder.

Uploaded by

Aleeza Anjum
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/ 6

TASK 1

Submitted by: Aleeza Anjum


Submitted to: Sir Awais Awan
Reg No: 20-CS-101
Section: Alpha

9/28/2023

Department of Computer Science


University of Engineering & Technology Taxila
1- Write a program that counts total even & odd numbers stored in an array ‘number’.

2- using System;
3- using System.Collections.Generic;
4- using System.Linq;
5- using System.Text;
6- using System.Threading.Tasks;
7-
8- namespace Task1
9- {
10- class Program
11- {
12- static void Main(string[] args)
13- {
14- //C sharp program to count total number of even and odd elements in an array
15-
16- int size, even, odd;
17- int[] arr;
18-
19- //Input size of the array
20- Console.Write("Aleeza Anjum 20-CS-101 ");
21- Console.Write("\nEnter size of the array: ");
22- size = Convert.ToInt32(Console.ReadLine());
23-
24- //Input array elements
25- // Console.WriteLine("Enter {0} elements in array:", size);
26-
27- arr = new int[size];
28-
29- for (int i = 0; i < size; i++)
30- {
31- arr[i] = Convert.ToInt32(Console.ReadLine());
32- }
33-
34- //Assuming that there are 0 even and odd elements
35- even = 0;
36- odd = 0;
37- for (int i = 0; i < size; i++)
38- {
39- //If the current element of array is even then increment even count
40- if (arr[i] % 2 == 0)
41- {
42- even++;
43- }
44- else
45- {
46- odd++;
47- }
48- }
49-
50- Console.Write("Total even elements: {0}\n", even);
51- Console.Write("Total odd elements: {0}", odd);
52-
53- }
54- }
55-
56-
57- }
Output:

2-Write a program that finds the largest among 3 numbers using nested if else
statement.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task1
{
class Program
{

static void Main(string[] args)


{

int number1, number2, number3;


string result;
Console.Write("Aleeza Anjum 20-CS-101:\n ");
Console.Write("Input the first number :");
number1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the second number :");
number2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the third number :");
number3 = Convert.ToInt32(Console.ReadLine());

if (number1 > number2 && number1 > number3)


{
result = "The 1st Number is the greatest among three. \n";
}
else if (number2 > number1 && number2 > number3)
{
result = "The 2nd Number is the greatest among three \n";
}
else
{
result = "The 3rd Number is the greatest among three \n";
}

Console.WriteLine(result);

}
}

Output:

3-Write a program that finds the grade of a student using else if ladder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task1
{
class Program
{
public static void Main()
{

string[] studentId = { "STU01", "STU02", "STU03", "STU04", "STU05" };


int[] marks = { 76, 83, 92, 65, 34 };
Console.WriteLine("Aleeza Anjum 20-CS-101\n");
Console.WriteLine("Finds the grade for each student");
for (int i = 0; i < studentId.Length; i++)
{
if (marks[i] > 90)
{
Console.WriteLine(studentId[i] + " Grade: " + "A");
}
else if (marks[i] > 80)
{
Console.WriteLine(studentId[i] + " Grade: " + "B");
}
else if (marks[i] > 70)
{
Console.WriteLine(studentId[i] + " Grade: " + "C");
}
else if (marks[i] > 50)
{
Console.WriteLine(studentId[i] + " Grade: " + "D");
}
else
{
Console.WriteLine(studentId[i] + " Grade: " + "FAIL");
}
}
Console.ReadKey();
}
}

}
Output:

------------------------------------------------------------

You might also like