This program determines wether a given number is odd or even.
#include<stdio.h>
void main(){
int num;
clrscr();
printf("Enter number : ");
scanf("%d",&num);
if(num%2==0)
printf("%d is an even number");
else
printf("%d is an odd number");
getch();
}
output:
Enter number : 4
4 is an even number
Enter number : 71
71 is an odd number
This program finds out odd or even numbers within a range
#include<stdio.h>
void main(){
int min,max,num;
clrscr();
printf("Enter minimum range : ");
scanf("%d",&min);
printf("Enter maximum range : ");
scanf("%d",&max);
printf("\nEven numbers in given range are : ");
for(num=min;num<=max;num++)
if(num%2==0)
printf("%d ",num);
printf("\n\nOdd numbers in given range are : ");
for(num=min;num<=max;num++)
if(num%2!=0)
printf("%d ",num);
getch();
}
output:
Enter minimum range 2
Enter maximum range 20
Even numbers in given range are : 2 4 6 8 10 12 14 16 18 20
Odd numbers in given range are : 1 3 5 7 9 11 13 15 17 19
#include<stdio.h>
void main(){
int num;
clrscr();
printf("Enter number : ");
scanf("%d",&num);
if(num%2==0)
printf("%d is an even number");
else
printf("%d is an odd number");
getch();
}
output:
Enter number : 4
4 is an even number
Enter number : 71
71 is an odd number
This program finds out odd or even numbers within a range
#include<stdio.h>
void main(){
int min,max,num;
clrscr();
printf("Enter minimum range : ");
scanf("%d",&min);
printf("Enter maximum range : ");
scanf("%d",&max);
printf("\nEven numbers in given range are : ");
for(num=min;num<=max;num++)
if(num%2==0)
printf("%d ",num);
printf("\n\nOdd numbers in given range are : ");
for(num=min;num<=max;num++)
if(num%2!=0)
printf("%d ",num);
getch();
}
output:
Enter minimum range 2
Enter maximum range 20
Even numbers in given range are : 2 4 6 8 10 12 14 16 18 20
Odd numbers in given range are : 1 3 5 7 9 11 13 15 17 19
No comments:
Post a Comment