C# Sharp Function : Exercises, Practice, Solution
C# Sharp Function [12 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 program in C# Sharp to create a user defined function.
Expected Output :
Welcome Friends!
Have a nice day!
Click me to see the solution
2. Write a program in C# Sharp to create a user defined function with parameters.
Test Data :
Please input a name : John
Expected Output :
Welcome friend John !
Have a nice day!
Click me to see the solution
3. Write a program in C# Sharp to create a function for the sum of two numbers.
Test Data :
Enter a number: 15
Enter another number: 16
Expected Output :
The sum of two numbers is : 31
Click me to see the solution
4. Write a program in C# Sharp to create a function to input a string and count the number of spaces within the string.
Test Data :
Please input a string : This is a test string.
Expected Output :
"This is a test string." contains 4 spaces
Click me to see the solution
5. Write a program in C# Sharp to calculate the sum of elements in an array.
Test Data :
Input 5 elements in the array :
element - 0 : 5
element - 1 : 7
element - 2 : 3
element - 3 : 2
element - 4 : 9
Expected Output :
The sum of the elements of the array is 26
Click me to see the solution
6. Write a program in C# Sharp to create a function to swap two integer numbers.
Test Data :
Enter a number: 5
Enter another number: 6
Expected Output :
Now the 1st number is : 6 , and the 2nd number is : 5
Click me to see the solution
7. Write a program in C# Sharp to create a function to calculate the result of raising an integer number to another.
Test Data :
Input Base number: 3
Input the Exponent : 2
Expected Output :
So, the number 3 ^ (to the power) 2 = 9
Click me to see the solution
8. Write a program in C# Sharp to create a function to display the n number Fibonacci sequence.
Test Data :
Input number of Fibonacci Series : 5
Expected Output :
The Fibonacci series of 5 numbers is :
0 1 1 2 3
Click me to see the solution
9. Write a program in C# Sharp to create a function to check whether a number is prime or not.
Test Data :
Input a number : 31
Expected Output :
31 is a prime number
Click me to see the solution
10. Write a program in C# Sharp to create a function to calculate the sum of the individual digits of a given number.
Test Data :
Enter a number: 1234
Expected Output :
The sum of the digits of the number 1234 is : 10
Click me to see the solution
11. Write a program in C# Sharp to create a recursive function to find the factorial of a given number.
Test Data :
Enter a number: 5
Expected Output :
The factorial of 5! is 120
Click me to see the solution
12. Write a program in C# Sharp to create a recursive function to calculate the Fibonacci number of a specific term.
Test Data :
Enter a number: 10
Expected Output :
The Fibonacci of 10 th term is 55
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics