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

Complete 20 Beginner DotNet Programs

The document contains 20 beginner C#/.NET programs, each demonstrating fundamental programming concepts such as input/output, control structures, loops, and functions. Examples include a 'Hello World' program, arithmetic operations, string manipulation, and basic algorithms like Fibonacci and palindrome checks. These programs serve as practical exercises for learning C# syntax and programming logic.

Uploaded by

padmahyd2405
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)
13 views6 pages

Complete 20 Beginner DotNet Programs

The document contains 20 beginner C#/.NET programs, each demonstrating fundamental programming concepts such as input/output, control structures, loops, and functions. Examples include a 'Hello World' program, arithmetic operations, string manipulation, and basic algorithms like Fibonacci and palindrome checks. These programs serve as practical exercises for learning C# syntax and programming logic.

Uploaded by

padmahyd2405
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/ 6

20 Beginner C#/.

NET Programs

1. Hello World
using System;

class Program {
static void Main(string[] args) {
Console.WriteLine("Hello, World!");
}
}

2. Add Two Numbers


using System;

class Program {
static void Main(string[] args) {
int a = 5, b = 3;
int sum = a + b;
Console.WriteLine("Sum: " + sum);
}
}

3. If-Else Example
using System;

class Program {
static void Main(string[] args) {
int num = 10;
if (num > 0)
Console.WriteLine("Positive");
else
Console.WriteLine("Non-positive");
}
}

4. For Loop Example


using System;

class Program {
static void Main(string[] args) {
for (int i = 1; i <= 5; i++)
Console.WriteLine("Number: " + i);
}
}

5. While Loop Example


using System;

class Program {
static void Main(string[] args) {
int i = 1;
while (i <= 5) {
Console.WriteLine("Count: " + i);
i++;
}
}
}

6. String Concatenation
using System;

class Program {
static void Main(string[] args) {
string first = "Hello";
string second = "World";
Console.WriteLine(first + " " + second);
}
}

7. Array Example
using System;

class Program {
static void Main(string[] args) {
int[] numbers = { 1, 2, 3, 4, 5 };
foreach (int num in numbers)
Console.WriteLine(num);
}
}

8. Switch Case
using System;

class Program {
static void Main(string[] args) {
int day = 3;
switch (day) {
case 1: Console.WriteLine("Monday"); break;
case 2: Console.WriteLine("Tuesday"); break;
case 3: Console.WriteLine("Wednesday"); break;
default: Console.WriteLine("Other day"); break;
}
}
}

9. Function Example
using System;

class Program {
static void Greet(string name) {
Console.WriteLine("Hello " + name);
}

static void Main(string[] args) {


Greet("Padma");
}
}

10. Read Input


using System;

class Program {
static void Main(string[] args) {
Console.Write("Enter name: ");
string name = Console.ReadLine();
Console.WriteLine("Hi " + name);
}
}

11. Multiply Two Numbers


using System;

class Program {
static void Main(string[] args) {
int a = 4, b = 5;
Console.WriteLine("Product: " + (a * b));
}
}

12. Division with Check


using System;

class Program {
static void Main(string[] args) {
int a = 10, b = 2;
if (b != 0)
Console.WriteLine("Quotient: " + (a / b));
else
Console.WriteLine("Cannot divide by zero");
}
}

13. Find Largest Number


using System;

class Program {
static void Main(string[] args) {
int a = 15, b = 25;
int max = (a > b) ? a : b;
Console.WriteLine("Largest: " + max);
}
}

14. Even or Odd


using System;

class Program {
static void Main(string[] args) {
int number = 7;
if (number % 2 == 0)
Console.WriteLine("Even");
else
Console.WriteLine("Odd");
}
}

15. Factorial Using Loop


using System;

class Program {
static void Main(string[] args) {
int num = 5;
int fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
Console.WriteLine("Factorial: " + fact);
}
}

16. Reverse a String


using System;

class Program {
static void Main(string[] args) {
string str = "Padma";
char[] charArray = str.ToCharArray();
Array.Reverse(charArray);
Console.WriteLine(new string(charArray));
}
}

17. Count Vowels


using System;

class Program {
static void Main(string[] args) {
string str = "Hello World";
int count = 0;
foreach (char c in str.ToLower()) {
if ("aeiou".Contains(c)) count++;
}
Console.WriteLine("Vowel Count: " + count);
}
}

18. Fibonacci Series


using System;

class Program {
static void Main(string[] args) {
int n1 = 0, n2 = 1, n3, i;
Console.Write(n1 + " " + n2 + " ");
for (i = 2; i < 10; ++i) {
n3 = n1 + n2;
Console.Write(n3 + " ");
n1 = n2;
n2 = n3;
}
}
}

19. Palindrome Check


using System;

class Program {
static void Main(string[] args) {
string str = "madam";
string rev = new string(str.Reverse().ToArray());
if (str == rev)
Console.WriteLine("Palindrome");
else
Console.WriteLine("Not Palindrome");
}
}

20. Simple Calculator


using System;

class Program {
static void Main(string[] args) {
int a = 20, b = 10;
Console.WriteLine("Add: " + (a + b));
Console.WriteLine("Subtract: " + (a - b));
Console.WriteLine("Multiply: " + (a * b));
Console.WriteLine("Divide: " + (a / b));
}
}

You might also like