QUESTION PROBLEM
Title
Question
Write a program to check whether the age of the employee is between 20 and 60?
Is the above question correct?
Write a program to check whether the age of the employee is between 20 and 59?
Or this one
C-and-Cpp Nested-If-And-Switch-Statement 08-09 min 0-10 sec
Answers:
Hello Vigneshwar,
Your question is not clear. Are you finding it difficult to write a program that calculates upto age 60?
#include <stdio.h>
void main()
{
int x, y;
printf ("enter the age between 20 to 60") ;
scanf ("%d, &y) ;
x=y/10;
switch(x)
{
case 2:
printf ("age of employ between 20 to 29");
break;
case 3:
printf ("age of employ between 30to39") ;
break;
case 4:
printf ("age of employ between 40to49") ;
break;
case 5:
printf ("age of employ between 50to59");
break;
default:
printf ("invalid number") ;
break;
}
getch() ;
}
By nested if
#include<stdio.h>
int main()
{
int a;
printf("enter the age of employee between 20to59:");
scand("%d",&a);
if(a/10==2)
{
printf("age of employee in between 20 to 29\n");
}
else if (a/10==3)
{
printf(" age of employee in between 30to39\n");
}
else if(a/10==4)
{
printf("age of employee in between 40to49\n");
}
else if (a/10==5)
{
printf("age of employee in between 50to59\n");
}
else
{
printf("age of employee not in range\n");
}
return 0;
}
//Assignment 7
// program using by switch case statement
#include<stdio.h>
void main()
{
int x, y;
printf(" enter the age between 20 to 59\n");
scanf("%d", &y);
x=y/10;
switch(x)
{
case 2:
printf(" age of employee between 20 to 29\n");
break;
case 3:
printf(" age of employee between 30 to 39 \n");
break;
case 4:
printf(" age of employee between 40 to 49 \n");
break;
case 5:
printf(" age of employee between 50 to 59 \n");
break;
default:
printf("Invalid age\n");
break;
}
getch();
}
Output as follows
y=55
x=5
age of employee between 50 to 59
By using switch case , assignment 7
#include <stdio.h>
void main ()
{
int a,b;
printf ("enter the age between 20 to 59\n");
scanf ("%d",&b);
a=b/10;
switch (a)
{
case 2:
printf ("age of the employee between 20 to 29\n");
break ;
case 3:
printf ("age of the employee between 30 to 39\n");
break ;
case 4:
printf ("age of the employee between 40 to 49\n");
break;
case 5:
printf ("age of the employee between 50 to 59\n");
break ;
default:
printf ("invalid age \n");
break;
}
getch ();
}
Output as follows
b= 35
a=3
Age of the employee between 30 to 39
Assignment -7
By using switch case Statement
#include<stdio.h>
void main ()
{
int a,b;
printf("enter the age between 20 to59\n");
scanf("%d",&b);
a=b/10;
switch (a)
{
case 2:
printf("age of employee between 20 to 29\n");
break;
case 3:
printf("age of employee between 30 to 39\n");
break;
case 4:
printf("age of employee between 40 to 49\n");
break;
case 5:
printf("age of employee between 50 to 59\n");
break;
default:
printf("invalid age\n");
break;
}
getch();
}
Output is as follows
b=25
a=2
age of employee between 20 to 29
//Assignment 7
// program using by switch case statement
#include<stdio.h>
void main()
{
int x, y;
printf(" enter the age between 20 to 59\n");
scanf("%d", &y);
x=y/10;
switch(x)
{
case 2:
printf(" age of employee between 20 to 29\n");
break;
case 3:
printf(" age of employee between 30 to 39 \n");
break;
case 4:
printf(" age of employee between 40 to 49 \n");
break;
case 5:
printf(" age of employee between 50 to 59 \n");
break;
default:
printf("Invalid age\n");
break;
}
getch();
}
Output as follows
y=55
x=5
age of employee between 50 to 59
Hii, I think we can write a code with the help of the information in the video and the pervious video.
I hope the code below might help you or if some one else is having the same doubt. We just have to add the decimal value .2 before %d for the code to read after 6 so that it will read only for the quotient 6.00 and rest which are above that will not be excepted.
#include <stdio.h>
int main()
{
int a;
printf("enter the age between 20 to 60\n");
scanf(".2%d",&a);
//for age less than 20
if(a/10==1)
{
printf("the age is less than the permitted age\n");
}
//for age 20 to 29
else if(a/10==2)
{
printf("the age group is between 20 to 29\n");
}
//for age 30 to 39
else if(a/10==3)
{
printf("the age group is between 30 to 39\n");
}
//for age 40 to 49
else if(a/10==4)
{
printf("the age group is between 40 to 49\n");
}
//for age 50 to 59
else if(a/10==5)
{
printf("the age group is between 50 to 59\n");
}
//for age 60
else if(a/10==6.00)
{
printf("the age group is 60\n");
}
//for age 61 and above
else
{
printf("the age is not in range\n");
}
return 0;
}
<font size="4">Program in c by switch case:</font>
#include <stdio.h>
int main()
{
int x, y;
printf("Enter the age of employee between 20 to 60:");
scanf("%d",&y);
x=y/10;
switch (x)
{
case 2:
printf("The age of the employee is in the range of 20 to 29\n");
break;
case 3:
printf("The age of the employee is in the range of 30 to 39\n");
break;
case 4:
printf("The age of the employee is in the range of 40 to 49\n");
break;
case 5:
printf("The age of the employee is in the range of 50 to 59\n");
break;
default:
printf("invalid age range \n");
}
return 0;
}
output:
Enter the age of employee between 20 to 60: 37
The age of the employee is in the range of 30 to 39
<font size="4">Program in c by using nested if:</font>
#include <stdio.h>
int main()
{
int x, y;
printf("Enter the age of employee between 20 to 60:");
scanf("%d",&y);
if(y/10==2)
{
printf("The age of the employee is in the range of 20 to 29\n");
}
else if(y/10==3)
{
printf("The age of the employee is in the range of 30 to 39\n");
}
else if(y/10==4)
{
printf("The age of the employee is in the range of 40 to 49\n");
}
else if(y/10==5)
{
printf("The age of the employee is in the range of 50 to 59\n");
}
else
{
printf("invalid age range\n");
}
return 0;
}
output:
Enter the age of employee between 20 to 60 : 57
The age of the employee is in the range of 50 to 59
<font size="4">program in cpp using nested if:</font>
#include <iostream>
using namespace std;
int main()
{
int x, y;
cout<<"Enter the age of employee between 20 to 60: ";
cin>>y;
if(y/10==2)
{
cout<<"The age of the employee is in the range of 20 to 29\n";
}
else if(y/10==3)
{
cout<<"The age of the employee is the range of 30 to 39\n";
}
else if(y/10==4)
{
cout<<"The age of the employee is in the range of 40 to 49\n";
}
else if(y/10==5)
{
cout<<"The age of the employee is in the range of 50 to 59\n";
}
else
{
cout<<"invalid age range\n";
}
return 0;
}
output:
Enter the age of employee between 20 to 60: 48
The age of the employee is in the range of 40 to 49
<font size="4">Program in cpp using switch case:</font>
#include <iostream>
using namespace std;
int main()
{
int x, y;
cout<<"Enter the age of employee between 20 to 60: ";
cin>>y;
x=y/10;
switch (x)
{
case 2:
cout<<"The age of the employee is in the range of 20 to 29\n";
break;
case 3:
cout<<"The age of the employee is in the range of 30 to 39\n";
break;
case 4:
cout<<"The age of the employee is in the range of 40 to 49\n";
break;
case 5:
cout<<"The age of the employee is in the range of 50 to 59\n";
break;
default:
cout<<"invalid age range \n";
}
return 0;
}
output:
Enter the age of employee between 20 to 60: 38
The age of the employee is in the range of 30 to 39
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("enter the age of employee");
scanf("%d",&a);
if(a<20)
printf("the employee age is not in between 20 to 60);
elseif(a==20)
printf("the employee age is 20")
else
printf("the employee age is in between 20 to 60")
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("enter the age of employee");
scanf("%d",&a);
if(a<20)
printf("the employee age is not in between 20 to 60);
elseif(a==20)
printf("the employee age is 20")
else
printf("the employee age is in between 20 to 60")
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("enter the age of employee");
scanf("%d",&a);
if(a<20)
printf("the employee age is not in between 20 to 60);
elseif(a==20)
printf("the employee age is 20")
else
printf("the employee age is in between 20 to 60")
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("enter the age of employee");
scanf("%d",&a);
if(a<20)
printf("the employee age is not in between 20 to 60);
elseif(a==20)
printf("the employee age is 20")
else
printf("the employee age is in between 20 to 60")
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("enter the age of employee");
scanf("%d",&a);
if(a<20)
printf("the employee age is not in between 20 to 60);
elseif(a==20)
printf("the employee age is 20")
else
printf("the employee age is in between 20 to 60")
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("enter the age of employee");
scanf("%d",&a);
if(a<20)
printf("the employee age is not in between 20 to 60);
elseif(a==20)
printf("the employee age is 20")
else
printf("the employee age is in between 20 to 60")
}
// program to check whether the age of the employee is between 20 and 60
#include<stdio.h>#include<conio.h>
void main()
{
int a;
printf("enter the age of employee");
scanf("%d",&a);
if(a<20)
printf("the employee age is not in between 20 to 60);
elseif(a==20)
printf("the employee age is 20");
else
printf("the employee age is in between 20 to 60");
getch();
}
// program to check whether the age of the employee is between 22 and 58
#include<stdio.h>#include<conio.h>
void main()
{
int a;
printf("enter the age of employee");
scanf("%d",&a);
if(a<22)
printf("the employee age is not in between 20 to 60);
elseif(a==22)
printf("the employee age is 22");
else
printf("the employee age is in between 22 to 58");
getch();
}
Login to add comment