w3resource

C# Sharp Data Types : Exercises, Practice, Solution

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

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a C# Sharp program that takes three letters and displays them in reverse order.
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. It then displays a triangle of that width using that number.
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 (string type). After 3 unsuccessful attempts, the user will be rejected.
Click me to see the solution

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

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 calculates the perimeter and area of the circle.

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).
Click me to see the solution

7. Write a C# Sharp program that takes distance and time as input and displays speed in kilometres per hour and miles per hour.
Test Data:
Input distance(metres): 50000
Input timeSec(hour): 1
Input timeSec(minutes): 35
Input timeSec(seconds): 56
Expected Output:
Your speed in metres/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 calculates and displays the surface and volume of the sphere.
Test Data:
Radius: 2
Expected Output:
50.26548
33.51032
Click me to see the solution

9. Write a C# Sharp program that takes a character as input and checks if it is a vowel, a digit, or any other symbol.
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.
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.
Test Data:
Number to convert (or "end")? 25
Expected Output:
Binary: 11001

Click me to see the solution

C# Sharp Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/csharp-exercises/data-types/index.php