कुछ और उदाहरण
*/ Program to check whether the number is Even or Odd */
#include<stdio.h>
#include<conio.h>
int main(void)
{
int number;
clrscr();
printf("Enter a number");
scanf("%d",&number);
if (number %2 ==0)
{
printf("Even Number");
}
else
{
printf("Odd Number");
}
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main(void)
{
int number;
clrscr();
printf("Enter a number");
scanf("%d",&number);
if (number %2 ==0)
{
printf("Even Number");
}
else
{
printf("Odd Number");
}
getch();
return 0;
}
Output :
Enter a number 10
Even Numberदोबारा रन कराने पर
Enter a number 3
Odd Number
Use of Logical Operator
*/ Program to check whether the year leap year or not */
#include<stdio.h>
#include<conio.h>
int main(void)
{
int year;
clrscr();
printf("Enter the year");
scanf("%d",&year);
if (year %4 ==0&& year %100!=0) || (year%400==0))
{
printf("Leap Year");
}
else
{
printf("Not a Leap Year");
}
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main(void)
{
int year;
clrscr();
printf("Enter the year");
scanf("%d",&year);
if (year %4 ==0&& year %100!=0) || (year%400==0))
{
printf("Leap Year");
}
else
{
printf("Not a Leap Year");
}
getch();
return 0;
}
Output :
Enter the year
Leap Yearदोबारा रन कराने पर
Enter the year
Not a Leap year
Program
/* Divisibility Test */
#include<stdio.h>
#include<conio.h>
int main(void)
{
int number;
clrscr();
printf("Enter the number for divisibility test ");
scanf("%d",&number);
if (number %2 ==0&& number %3==0)
{
printf("Number divisible by 2 & 3");
}
else
{
printf("Not divisible by 2 & 3");
}
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main(void)
{
int number;
clrscr();
printf("Enter the number for divisibility test ");
scanf("%d",&number);
if (number %2 ==0&& number %3==0)
{
printf("Number divisible by 2 & 3");
}
else
{
printf("Not divisible by 2 & 3");
}
getch();
return 0;
}
Output :
Enter the number for divisibility test 18
Number divisible by 2 & 3दोबारा रन कराने पर
Enter the number for divisibility test 10
Not divisible by 2 & 3NEXT : Nested if -else
PREVIOUS : if - else statement
c प्रोग्रामिंग कोडर कोडर्स के लिए
ReplyDeleteमेमोरी और रियलक्लेट नमूना कोड आवंटित करें