0% found this document useful (0 votes)
25 views

Coding

The document contains code for several C# programs. The first program takes user input of integer values, stores them in an array, and prints whether each value is even or odd. The second program takes student marks as input, calculates total and average, and allows the user to select printing total or average. The third program uses a foreach loop to iterate through integers, prints values, and uses continue and break statements. The fourth program demonstrates passing values to methods by value, by reference, and with out parameters.

Uploaded by

Sharavana Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Coding

The document contains code for several C# programs. The first program takes user input of integer values, stores them in an array, and prints whether each value is even or odd. The second program takes student marks as input, calculates total and average, and allows the user to select printing total or average. The third program uses a foreach loop to iterate through integers, prints values, and uses continue and break statements. The fourth program demonstrates passing values to methods by value, by reference, and with out parameters.

Uploaded by

Sharavana Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Coding: using using using using System; System.Collections.Generic; System.Linq; System.

Text;

namespace ConsoleApplication1 { class branch { static void Main(string[] args) { int a,b; Console .WriteLine ("Enter the values of a"); a=int.Parse (Console.ReadLine()); int[] n = new int[a]; Console.WriteLine("Enter the values"); for (b = 0; b < a; b++) { n[b] = int.Parse(Console.ReadLine()); } for (b = 0; b < a; b++) { if(n[b]%2==0) { Console.WriteLine(n[b]+"is EventArgs number"); } else{ Console.WriteLine(n[b]+"is odd no"); } Console.ReadLine(); } } } }

output

namespace dowhile { class Program { static void Main(string[] args) { int m1=0, m2=0, m3=0, m4=0, m5=0; float avg; int i, n=0, total=0, ch; Console.WriteLine("Student merit list"); Console.WriteLine("Enter the no of student"); n = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the marks m1,m2,m3,m4,m5"); for (i = 0; i <= n; i++) { m1 = int.Parse(Console.ReadLine()); m2 = int.Parse(Console.ReadLine()); m3 = int.Parse(Console.ReadLine()); m4 = int.Parse(Console.ReadLine()); m5 = int.Parse(Console.ReadLine()); } for (i = 0; i < n; i++) { Console.WriteLine(m1); Console.WriteLine(m2); Console.WriteLine(m3); Console.WriteLine(m4); Console.WriteLine(m5); } Console.WriteLine("Enter the choice:"); Console.WriteLine("\t1.Total\n\t2.Average\n\t3.Exit"); ch = int.Parse(Console.ReadLine()); do { switch (ch) { case 1: total = m1 + m2 + m3 + m4 + m5; Console.WriteLine(total); break; case 2: avg = total / 5; break; default: Console.WriteLine("press 3 to exit"); break; } } while (ch != 3); Console.ReadLine(); } } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int n; n = int.Parse(Console.ReadLine()); Console.WriteLine(n); foreach (int i in n) { Console.WriteLine(i); if (n < 20) {

Console.WriteLine(" " + n); continue; } if (n == 30) { Console.WriteLine(); n = n + 10; continue; } if (n > 50) { break; Console.WriteLine(" " + n); n = n + 10; } Console.ReadLine(); } } } }

METHOD: using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication2 { class Passing { static void change(int m) { m = m + 20; } static void swap(ref int x, ref int y) { int temp = x; x = y; y = temp; } static void output(out int p) { p = 1000; } static void Main(string[] args) { int l = 100; change(l); Console.WriteLine("l=" + l); int a = 100, b = 200; Console.WriteLine("BEFORE SWAPPING"); Console.WriteLine("a=" + a); Console.WriteLine("b=" + b); swap(ref a, ref b); Console.WriteLine("AFTER SWAPPING"); Console.WriteLine("a=" + a); Console.WriteLine("b=" + b); int c; output(out c); } } }

You might also like