At the end of this lesson-
- 1. You will be able to write a program for determining an integer number is whether even or odd.
- 2. You will be able to write a program for determining a number is whether positive or negative.
- 3. You will be able to write a program for determining a year is whether leap year or not leap year.
- 4. You will be able to write a program for determining larger number between two numbers.
- 5. You will be able to write a program for determining LCM of two integer numbers.
- 6. You will be able to write a program for determining GCD of two integer numbers.
- 7. You will be able to write a program for determining the smallest number among three numbers.
- 8. You will be able to write a program for determining the middle number among three numbers.
- 9. You will be able to write a program for determining the largest number among three numbers.
1. A program for determining an integer number is whether even or odd.
#include<stdio.h>
#include<conio.h>
main()
{
int n;
printf("Enter a number: ");
scanf("%d", &n);
if (n%2==0)
printf("\nThe number %d is even.",n);
else
printf("\nThe number %d is odd.",n);
getch();
}
2. A program for determining a number is whether positive or negative.
#include<stdio.h>
#include<conio.h>
main()
{
int n;
printf("Enter a number: ");
scanf("%d", &n);
if (n>=0)
printf("\nThe number %d is positive.",n);
else
printf("\nThe number %d is Negative.",n);
getch();
}
3. A program for determining a year is whether leap year or not leap year.
#include<stdio.h>
#include<conio.h>
main()
{
int y;
printf("Enter a year:");
scanf("%d",&y);
if ((y%400==0)||((y%100!=0)&&(y%4==0)))
printf("%d is a Leap year", y);
else
printf("%d is not a Leap year", y);
getch();
}
4. A program for determining larger number between two numbers.
#include<stdio.h>
#include<conio.h>
main()
{
int a, b;
printf(“Enter 1st value :”);
scanf("%d",&a);
printf(“Enter 2nd value :”);
scanf("%d",&b);
if(a>b)
printf("Largest Number is : %d", a);
else
printf("Largest Number is: %d", b);
getch();
}
5. A program for determining LCM of two integer numbers.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,l;
printf("Enter the two numbers: ");
scanf("%d %d",&a,&b);
if(a>b)
l=a;
else
l=b;
again:
if(l%a==0 && l%b==0)
printf("LCM of %d and %d is %d",a,b,l);
else
{
l=l+1;
goto again;
}
getch();
}
6. A program for determining GCD of two integer numbers.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,s;
printf("Enter the two numbers: ");
scanf("%d %d",&a,&b);
if(a<b)
s=a;
else
s=b;
again:
if(a%s==0 && b%s==0)
printf("GCD of %d and %d is %d",a,b,s);
else
{
s=s-1;
goto again;
}
getch();
}
7. A program for determining the smallest number among three numbers.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
printf("Enter three integer numbers:");
scanf("%d %d %d", &a, &b, &c);
if(a<b)
{
if(a<c)
printf("\n Smallest number is: %d", a);
else
printf("\n Smallest number is: %d", c);
}
else
{
if(b<c)
printf("\n Smallest number is: %d", b);
else
printf("\n Smallest number is: %d", c);
}
getch();
}
8. A program for determining the middle number among three numbers.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
printf("Enter three integer numbers:");
scanf("%d %d %d", &a, &b, &c);
if(a>b)
{
if(b>c)
printf("%d is middle one",b);
else if(c>a)
printf("%d is middle one",a);
else
printf("%d is middle one",c);
}
else
{
if(b<c)
printf("%d is middle one",b);
else if(c<a)
printf("%d is middle one",a);
else
printf("%d is middle one",c);
}
getch();
}
9. A program for determining the largest number among three numbers.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
printf("Enter three integer numbers:");
scanf("%d %d %d", &a, &b, &c);
if(a>b)
{
if(a>c)
printf("\n Largest number is: %d", a);
else
printf("\n Largest number is: %d", c);
}
else
{
if(b>c)
printf("\n Largest number is: %d", b);
else
printf("\n Largest number is: %d", c);
}
getch();
}
Lesson Evaluation-
Knowledge Based Questions:
Comprehension Based Questions:
Creative Questions:
Multiple Choice Questions:
Written by,
- Mizanur Rahman (Mizan)
- Lecturer of ICT, Shaheed Bir Uttam Lt. Anwar Girls’ College ,Dhaka Cantonment
- Author at www.edupointbd.com
- Software Engineer at mands IT
- Former Lecturer of ICT, Cambrian College, Dhaka
- Email: mizanjust@gmail.com
- Cell: 01724351470