Task1 (20 CS 101)
Task1 (20 CS 101)
9/28/2023
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
{
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()
{
}
Output:
------------------------------------------------------------