Following are programs for if, if-else, if-else ladder, switch and ternary operator
//Program to check password using if :-
//Program to check password using if :-
#include<stdio.h>
#include<conio.h>
{
int PASS=0123;
int user=7887,p=0,u=0;
printf("Hello\n\n Enter your username id =");
scanf("%d",&u);
printf("Enter password");
scanf("%d",&p); 
if(p==PASS && u==user )
{
printf("Welcome !!");
}
getch();
}
//Program to check password using if-else:-
}
  
#include<stdio.h>
#include<conio.h>
void main()
{
int PASS=0123;
int user=7887,p=0,u=0;
printf("Hello\n\n Enter your username id =");
scanf("%d",&u);
printf("Enter password");
scanf("%d",&p); 
if(p==PASS && u==user )
{
printf("Welcome !!");
}
else
{
printf("Invalid Entry");
}
getch();}
//Program to print month using else-if ladder :-
#include<stdio.h>
void main()
{
int day=0;
printf("enter day number");
scanf("%d",&day);
if(day==1)
printf("Monday");
else if (day==2)
printf("tuesday");
else if (day==2)
printf("wednesday");
else if (day==2)
printf("thursday");
else if (day==2)
printf("friday");
else if (day==2)
printf("saturday");
else if (day==2)
printf("Sunday");
else
printf("Invalid entry...try again !!");
 }
//Program to print day using switch case :-
#include<stdio.h>
void main()
{
int day=0;
printf("enter day number");
scanf("%d",&day);
case 1 :printf("Monday");
            break;
case 2: printf("tuesday");
             break;
case 3 :printf("wednesday");
            break;
case 4 :printf("thursday");
              break
;case 5 :printf("friday");
               break;
case 6: printf("saturday");
              break;
case 7 :printf("Sunday");
              break;
default : printf("Invalid entry...try again !!");
               
 break;
 }
//Program of ternary operator Programs:-
There are programs of Object-Oriented Programming, Operators (logical, arithmetic ,relational,etc) ,exception handling , inheritance ,string operations ,etc
No comments:
Post a Comment