w3resource logo


C# Sharp Programming Exercises

C# Sharp Basic Declarations and Expressions : Exercises, Practice, Solution

Secondary Nav

C# Sharp Basic Exercises [14 exercises with solution]

1. Write a C# Sharp program to print Hello and your name in a separate line. Go to the editor
Expected Output :
Hello: Alexandra Abramov
Click me to see the solution

2. Write a C# Sharp program to print the sum of two numbers. Go to the editor
Click me to see the solution

3. Write a C# Sharp program to print the result of dividing two numbers. Go to the editor
Click me to see the solution

4. Write a C# Sharp program to print the result of the specified operations. Go to the editor
Test data:
• -1 + 4 * 6
• ( 35+ 5 ) % 7
• 14 + -4 * 6 / 11
• 2 + 15 / 6 * 1 - 7 % 2

Expected Output:
23
5
12
3
Click me to see the solution

5. Write a C# Sharp program to swap two numbers. Go to the editor
Test Data:
Input the First Number : 5
Input the Second Number : 6
Expected Output:
After Swapping :
First Number : 6
Second Number : 5
Click me to see the solution

6. Write a C# Sharp program to print the output of multiplication of three numbers which will be entered by the user. Go to the editor
Test Data:
Input the first number to multiply: 2
Input the second number to multiply: 3
Input the third number to multiply: 6
Expected Output:
2 x 3 x 6 = 36
Click me to see the solution

7. Write a C# Sharp program to print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user. Go to the editor
Test Data:
Input the first number: 25
Input the second number: 4
Expected Output:
25 + 4 = 29
25 - 4 = 21
25 x 4 = 100
25 / 4 = 6
25 mod 4 = 1
Click me to see the solution

8. Write a C# Sharp program that takes a number as input and print its multiplication table. Go to the editor
Test Data:
Enter the number: 5
Expected Output:
5 * 0 = 0
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
....
5 * 10 = 50
Click me to see the solution

9. Write a C# Sharp program that takes four numbers as input to calculate and print the average. Go to the editor
Test Data:
Enter the First number: 10
Enter the Second number: 15
Enter the third number: 20
Enter the four number: 30

Expected Output:
The average of 10 , 15 , 20 , 30 is: 18
Click me to see the solution

10. Write a C# Sharp program to that takes three numbers(x,y,z) as input and print the output of (x+y)·z and x·y + y·z. Go to the editor
Test Data:
Enter first number - 5
Enter second number - 6
Enter third number - 7

Expected Output:
Result of specified numbers 5, 6 and 7, (x+y)·z is 77 and x·y + y·z is 72
Click me to see the solution

11. Write a C# Sharp program that takes an age (for example 20) as input and prints something as "You look older than 20". Go to the editor
Test Data:
Enter your age - 25
Expected Output:
You look older than 25
Click me to see the solution

12. Write a C# program to that takes a number as input and display it four times in a row (separated by blank spaces), and then four times in the next row, with no separation. You should do it two times: Use Console. Write and then use {0}. Go to the editor
Test Data:
Enter a digit: 25
Expected Output:
25 25 25 25
25252525
25 25 25 25
25252525
Click me to see the solution

13. Write a C# program that takes a number as input and then displays a rectangle of 3 columns wide and 5 rows tall using that digit. Go to the editor
Test Data:
Enter a number: 5
Expected Output:
555
5 5
5 5
5 5
555
Click me to see the solution

14. Write a C# program to convert from celsius degrees to Kelvin and Fahrenheit. Go to the editor
Test Data:
Enter the amount of celsius: 30
Expected Output:
Kelvin = 303
Fahrenheit = 86
Click me to see the solution

C# Sharp Practice online


public class Exercise1
{
    public static void Main( )
    {
         System.Console.WriteLine("Hello");
       
    }
}

List of Exercises with Solutions :



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number