Showing posts with label if else. Show all posts
Showing posts with label if else. Show all posts

Wednesday, September 23, 2015

Using if else construct in C - II

#include <stdio.h>
#include <conio.h>

void main ()
{
                clrscr();
                int a;
                printf("FORTUNE TELLER\n");
                printf("please Enter a number between 1 and 5:\t");
                scanf("%d", &a);
                if (a==1)
                {
                                printf("You will have a nice day\n");
                }
                else if (a==2)
                {
                                printf("You will meet some one special today\n");
                }
                else if (a==3)
                {
                                printf("You will win a lottery today\n");
                }
                else if (a==4)
                {
                                printf("You will get a special gift today\n");
                }
                else if (a==5)
                {
                                printf("You will find your true love today today\n");
                }
                else
                {
                                printf("Please enter a number between 1 and 5\n");
                }
                getch();
}
Output:  
FORTUNE TELLER
Enter a number between 1 and 5:   5
You will find true love today.


Using if else construct in C

#include <stdio.h>
#include <conio.h>
void main
{
                clrscr();
                int a;
                printf("Please enter a number: \n");
                scanf("%d",&a);
                if
                                (a<20)
                {
                                printf("%d is less than 20\n", a);
                }
                else
                {
                                printf("%d is greater than 20\n", a);
                }
                getch();
}

Output:  
Please enter a number: 22
22 is greater than 20.