Wednesday, May 13, 2020
C program to make a calculator using the switch statement.
Tuesday, May 12, 2020
check whether a given number is even or odd? If the number is an even number, print it's square.
C program to check whether a given number is even or odd? if the number is even number, print it's square...
#include<stdio.h>
#include<conio.h>
void main()
{
int num, squ;
printf("enter number = ");
scanf("%d",& num);
if(num%2==0)
{
printf("The number is Even");
squ = num*num;
printf("\nsquare of this even number is %d", squ);
}
else
printf("The number is Odd");
getch();
}
Output:
Click Here for, All Important Questions with Answers
Click here for, C Programs
Switch Versus if-else Ladder
Q. What is the difference between the Switch statement and if- else ladder statements?|
S.No. |
Switch statement |
If- else-if ladder statements |
|
|
Instead of using the if-else-if Ladder
control statement, the Switch Statement is available in program C for
Handling multiple choices. In Switch statement three keywords are used
switch, case, and default. we can use integer. constant. but we can not use floating
point and string constants.
|
This
is a type of nesting in which there is an if...else statement in every else
part except the last else part. This type nesting is called the else if
Ladder Statement.
|
|
|
Syntax: Switch(expression) { case constant 1: statement; break; case constant 2: statement; break; case
constant 3: statement; break; default; statement }
|
Syntax: if(Condition
1)
Statement A; else if(Condition
2)
Statement B; else if(Condition
3)
Statement C;
else if(Condition 4)
Statement C;
else
Statement D;
|
|
3. |
It’s also called cases control
statement. |
It’s also called loader if
statement.
|
|
4. |
In switch statements we use
switch keyword. |
Here we use else if keywords.
|
|
5. |
It is easy to use &
understand. |
It is complex statements.
|
|
6. |
It can have different cases for
different conditions. |
But there is no different cases
for different conditions. |
|
7. |
In this statement, we can not use
relational & logical operators. |
In this we can use relational
& logical statements.
|
|
8. |
#include<stdio.h> #include<stdio.h> void main() { int ch; printf("\n1.
press ch=1 for monday. \n2. press ch=2 for tuesday.\n3. press ch=3 for
wednesday. \n4.press ch=4 for thursday. \n5.press ch=5 for friday.\n6.press
ch=6 for saturday. \n7. press ch=7 for sunday.");
printf("\n
enetr your choice =");
scanf("%d", &ch); switch(ch) {
case 1:
printf("today is monday");
break;
case 2:
printf("today is tuesday");
break;
case 3:
printf("today is wednesday");
break;
case 4:
printf("today is thursday");
break;
case 5:
printf("today is friday");
break;
case 6:
printf("today is saturday");
break;
case 7:
printf("today is sunday");
break;
default:
printf("wrong choice Try Again!!!"); }
getch();
}
Output: |
#include<stdio.h> #include<stdio.h> void main() { int
ch;
printf("\n1. press ch=1 for monday. \n2. press ch=2 for tuesday.\n3.
press ch=3 for wednesday. \n4.press ch=4 for thursday. \n5.press ch=5 for
friday.\n6.press ch=6 for saturday. \n7. press ch=7 for sunday.");
printf("\n enetr your choice =");
scanf("%d", &ch);
if(ch==1) {
printf("today is monday"); } else
if(ch==2) {
printf("today is tuesday"); } else
if(ch==3) {
printf("today is wednesday"); } else
if(ch==4) {
printf("today is thursday"); } else
if(ch==5) {
printf("today is friday"); } else
if(ch==6) {
printf("today is saturday"); } else
if(ch==7) {
printf("today is sunday"); }
getch(); } Output:
|
Tuesday, May 5, 2020
C Program to Print Day Name of Week using Else If ladder
Friday, May 1, 2020
Program How to calculate Gross salary of employee
Calculate Gross Salary
Write a program to calculate gross salary of employee, basic salary is enter by the user, da is calculated on the basic of the following criteria.| bsal | da |
| below 5000 | 10% of bsal |
| 5000-10000 | 15% of bsal |
| 10000-20000 | 20% of bsal |
| 20000-above | 40% of bsal |
* Click here, Simple Program to calculate gross salary of employee
*Click here, to Control Statement- if else statement
Sunday, April 26, 2020
C Program to find the Largest Number among three numbers
/* Print the Largest Number*/
Saturday, April 25, 2020
The else if ladder
The else if ladder
- The else if Ladder Statement:
This is a type of nesting in which there is an if...else statement in every else part except the last else part. This type nesting is called the else if Ladder Statement.
-
C program to check whether a given number is even or odd? if the number is even number, print it's square... #include<stdio.h> ...
-
/*Operators And Expressions*/ An operators specifies an operation to be performed that yields a value. operators are essential to form...
-
/* Calculation of simple interest*/ #include<stdio.h> #include<conio.h> void main() { int p, t; float r, si; clrscr();...
C program to make a calculator using the switch statement.
/*perform arithmetic calculation on integers in C language*/ #include<stdio.h> #include<conio.h> void main() { char op; ...





