Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday 22 March 2017

Simple program


In this blog, we are going to code simple program that usually asked. Many of us get confused between loops and conditions. And it is also one of the most asked interview questions.
 
Simple program by imagination hunt blogs
Simple program

In the table given below, we have listed out various simple programs.

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code these programs.

S.no.
Simple Program
1.     

Source code to check whether a number is even or odd

Number: 5, is Odd.
Number: 10, is Even.

Click to view string code

2.     

Source code to check whether a number is even or odd using ternary or conditional operator

Number: 5, is Odd.
Number: 10, is Even.

Click to view string code

3.     

Source code to print even and odd number upto n

Even number upto: 20 are:
2 4 6 8 10 12 14 16 18 20
Odd number upto: 20 are:
1 3 5 7 9 11 13 15 17 19

Click to view string code

4.     

Source code to swap number using three variables

Before swapping a is : 8
Before swapping b is : 6
After swapping a is : 6
After swapping b is : 8

Click to view string code

5.     

Source code to swap number using two variables

Before swapping a is : 8
Before swapping b is : 6
After swapping a is : 6
After swapping b is : 8

Click to view string code

6.     

Source code to check whether a number is prime or not

-1
Smallest prime number is 2
39
Not prime number

Click to view string code

7.     

Source code to print next prime number

Enter a number: 11
Next prime number: 13

Click to view string code

8.     

Source code to print prime number from x to y

Enter starting number: 1
Enter last number: 50

Output:
List of prime number:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

Click to view string code

9.     

Source code to calculator program

Enter starting number: 1
Enter last number: 50

Output:
List of prime number:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

Click to view string code

10.   

Source code to calculate factorial of a number

Enter a number: 5
Factorial of 5 is: 120

Click to view string code

11.   

Source code to print table of a number

Enter a number: 5

Table for 5
--------------------
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Click to view string code

12.   

Source code to reverse a number

Enter a number: 456
Reverse of 456 is: 654

Click to view string code

13.   

Source code to calculate number of digits

Enter a number: 456
Number of digits used in given number 456 is 3

Click to view string code

14.   

Source code to check input is a positive or negative or neutral number

Enter a number: 64
Number is positive.

Click to view string code



For any query, comment us below.

Previous – String based program

Next - Simple program #1


Click
imagination hunt to read latest blogs.

Keep learning and sharing...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...