If Else

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

1.

Eligible to vote :
#include<stdio.h>
void main()
{
int age;
printf("Enter your age : ");
scanf("%d",&age);
if (age >= 18)
{
printf("You are eligible to vote ^_^ !!");
}
else
{
printf("You are not eligible to vote >_< !!");
}
}

2. Given number is positive or negative :


#include<stdio.h>
void main()
{
int num;
printf("Enter a integer : ");
scanf("%d", &num);
if(num>=0)
{
printf("The given number is Positive ^_^ !!!!");
}
else
{
printf("The given number is negative >_< !!!!");
}
}

3. Amount to be paid after discount:


#include<stdio.h>
void main()
{
int items , price , discount , paid , amount, total ;
printf("Enter the price of the product : ");
scanf("%d",&price);
printf("Enter the quantity of the product : ");
scanf("%d",&items);
amount = price*items;

if (amount>1000)

{
printf("10% Discount is granted \n");
discount = amount*0.10;
total = amount-discount ;
}

else

{
printf("5% Discount is granted \n");
discount = amount*0.05;
total = amount-discount ;
}

printf("The final amount to be paid is Rs.%d ",total);

4. A given year is leap year or not:


#include<stdio.h>
void main()
{
int year;
printf("Enter a Year : ");
scanf("%d", &year);
if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
printf("The given year is leap year ^_^ !!!!");
}
else
{
printf("The given year is not a leap year >_< !!!!");
}
}
5. The given number is 3digit number or
not:
#include<stdio.h>
void main()
{
int num;
printf("Enter a num : ");
scanf("%d", &num);
if(num>99 && num<1000)
{
printf("The given number is three digit number ^_^ !!!!");
}
else
{
printf("The given number is not three digit number >_< !!!!");
}
}

You might also like