w3resource logo


C# Sharp Programming Exercises

C# Sharp Data Types : Exercises, Practice, Solution

Secondary Nav

C# Sharp Data Types Exercises [11 exercises with solution]

1. Write a C# Sharp program that takes three letters as input and display them in reverse order. Go to the editor
Test Data
Enter letter: b
Enter letter: a
Enter letter: t
Expected Output :
t a b
Click me to see the solution

2. Write a C# Sharp program that takes a number and a width also a number, as input and then displays a triangle of that width, using that number. Go to the editor
Test Data
Enter a number: 6
Enter the desired width: 6
Expected Output :

666666                                                      
66666                                                           
6666                                                                  
666                                                        
66                                                                  
6 
Click me to see the solution

3. Write a C# Sharp program that takes userid and password as input (type string). After 3 wrong attempts, user will be rejected. Go to the editor
Click me to see the solution

4. Write a C# Sharp program that takes two numbers as input and perform an operation (+,-,*,x,/) on them and displays the result of that operation. Go to the editor

Test Data
Input first number: 20
Input operation: -
Input second number: 12
Expected Output :
20 - 12 = 8
Click me to see the solution

5. Write a C# Sharp program that takes the radius of a circle as input and calculate the perimeter and area of the circle. Go to the editor

Test Data
Input the radius of the circle :
12
Expected Output :
Perimeter of Circle : 75.36
Click me to see the solution

6. Write a C# Sharp program to display certain values of the function x = y2 + 2y + 1 (using integer numbers for y , ranging from -5 to +5). Go to the editor
Click me to see the solution

7. Write a C# Sharp program that takes distance and time as input and displays the speed in kilometers per hour and miles per hour. Go to the editor
Test Data:
Input distance(meters): 50000
Input timeSec(hour): 1
Input timeSec(minutes): 35
Input timeSec(seconds): 56
Expected Output:
Your speed in meters/sec is 8.686588
Your speed in km/h is 31.27172
Your speed in miles/h is 19.4355
Click me to see the solution

8. Write a C# Sharp program that takes the radius of a sphere as input and calculate and display the surface and volume of the sphere. Go to the editor
Test Data:
Radius: 5
Expected Output:
314.1593
392.6991
Click me to see the solution

9. Write a C# Sharp program that takes a character as input and check the input (lowercase) is a vowel, a digit, or any other symbol. Go to the editor
Test Data:
Input a symbol: a
Expected Output:
It's a lowercase vowel.

Click me to see the solution

10. Write a C# Sharp program that takes two numbers as input and returns true or false when both numbers are even or odd. Go to the editor
Click me to see the solution

11. Write a C# Sharp program that takes a decimal number as input and displays its equivalent in binary form. Go to the editor
Test Data:
Number to convert (or "end")? 25
Expected Output:
Binary: 11001

Click me to see the solution

C# Sharp Practice online





List of Exercises with Solutions :



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