#include<stdio.h>
int main()
{
int n;
printf("enter number: \n");
scanf("%d",&n);
if(n%7==0)
{
printf("%d is divisible by 7",n);
}
else
printf("%d is NOT divisible by 7",n);
}
WAP to input a character and check that it’s a vowel or a consonant.
#include<stdio.h>
int main()
{
char c;
printf("enter character: \n");
scanf("%c",&c);
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U' )
printf("vowel");
else if((c>='a' && c<='z')|| (c>='A' && c<='Z'))
printf("consonant");
else
printf("enter valid input");
}
WAP to input a character and check that it’s a small letter, capital letter, a digit or a special symbol.
#include<stdio.h>
int main()
{
char c;
printf("enter input: \n");
scanf("%c",&c);
if(c>='a' && c<='z')
{
printf("small character");
}
else if(c>='A' && c<='Z')
{
printf("capital character");
}
else if(c>='0' && c<='9')
{
printf("digit");
}
else if(c!=' ')
{
printf("special symbol");
}
}
>=60 First
50-59 Second
40-49 Third
<40 Fail
#include<stdio.h>
int main()
{
float n1,n2,n3,n4,n5;
printf("enter number of 5 subjects: \n");
scanf("%f%f%f%f%f",&n1,&n2,&n3,&n4,&n5);
float sum=n1+n2+n3+n4+n5;
float avg=(sum/5);
if(avg>=60)
{
printf("first division");
}
else if(avg>=50 && avg<=59)
{
printf("second division");
}
else if(avg>=40 && avg<=49)
{
printf("third division");
}
else if(avg<40)
{
printf("fail");
}
else
{
printf("invalid input");
}
}
WAP to input the selling price and cost price from the user and determine whether the seller has made profit or
incurred loss. Also display the value of profit or loss.
#include<stdio.h>
#include<stdlib.h>
int main()
{
float selling_price,cost_price;
printf("enter selling price and cost price: \n");
scanf("%f%f",&selling_price,&cost_price);
if(selling_price>cost_price)
{
printf("profit amount is: %.2f",selling_price-cost_price);
}
else if(selling_price<cost_price)
{
printf("loss amount is: %.2f",abs(selling_price-cost_price));
}
else if(selling_price=cost_price)
{
printf("no profit or loss");
}
else
{
printf("enter valid inputs");
}
}
WAP to input a date (dd / mm / yyyy) and check for the validity of the date.
#include<stdio.h>
int main()
{
int date,month,year;
printf("Enter date: \n");
scanf("%d",&date);
printf("Enter month: \n");
scanf("%d",&month);
printf("Enter year: \n");
scanf("%d",&year);
if ((month>=1&&month<=12)&&(year>=1))
{
if (month==2)
{
if (year%400==0 || (year%4==0&&year%100!=0))
{
if (date>=1&&date<=29)
{
printf("Valid date\n");
} else
{
printf("Invalid date\n");
}
}
else
{
if (date>=1 && date<=28)
{
printf("Valid date\n");
} else {
printf("Invalid date\n");
}
}
}
else if ((month<=7 && month%2==1) || (month>= 8 && month%2==0))
{
if (date>=1 && date<=31)
{
printf("Valid date\n");
} else
{
printf("Invalid date\n");
}
} else
{
if (date>=1 && date <=30)
{
printf("Valid date\n");
} else {
printf("Invalid date\n");
}
}
}
else
{
printf("Invalid date\n");
}
return 0;
}
WAP to find out the largest of three numbers
#include<stdio.h>
int main()
{
int x,y,z;
printf("enter three numbers: \n");
scanf("%d%d%d",&x,&y,&z);
if(x>y && x>z)
{
printf("%d is greatest",x);
}
else if(y>x && y>z)
{
printf("%d is greatest",y);
}
else if(z>x && z>y)
{
printf("%d is greatest",z);
}
else if(x==y && x==z)
{
printf("all inputs are equal");
}
else
{
printf("invalid input");
}
}
WAP to convert a small letter into capital letter and vice versa.
#include<stdio.h>
int main()
{
char c;
printf("enter character: \n");
scanf("%c",&c);
if(c>='a' && c<='z')
{
c=c-32;
printf("%c",c);
}
else if(c>='A' && c<='Z')
{
c=c+32;
printf("%c",c);
}
else
{
printf("invalid input");
}
}
#include<stdio.h>
int main()
{
int year;
int given=2001;
printf("enter year you wish to check of 1st janurary: ");
scanf("%d",&year);
int difference=year-given;
int leap=difference/4;
int nonleap=difference-leap;
int days=(leap*366)+(nonleap*365)+1;
if(days%7==0)
{
printf("sunday");
}
if(days%7==1)
{
printf("monday");
}
if(days%7==2)
{
printf("tuesday");
}
if(days%7==3)
{
printf("wednesday");
}
if(days%7==4)
{
printf("thursday");
}
if(days%7==5)
{
printf("friday");
}
if(days%7==6)
{
printf("saturday");
}
}
WAP to input the sales made by a salesman and calculate the commission according to the following conditions:
Sales Commission
1-10000 4%
10001-20000 5%
20001-30000 6%
>30000 7%
#include<stdio.h>
int main()
{
float sales,com;
printf("enter sales amount: \n");
scanf("%f",&sales);
if(sales>=1 && sales<=10000)
{
com=sales*0.4;
printf("commission:%.2f\n",com);
}
else if(sales>10000 && sales<20000)
{
com=sales*0.5;
printf("commission:%.2f\n",com);
}
else if(sales>20000 && sales<30000)
{
com=sales*0.6;
printf("commission:%.2f\n",com);
}
else if(sales>30000)
{
com=sales*0.7;
printf("commission:%.2f\n",com);
}
}
#include<stdio.h>
int main()
{
int n;
printf("enter age: \n");
scanf("%d",&n);
if(n<=12)
{
printf("child\n");
}
else if(n>12 && n<=19)
{
printf("teenager\n");
}
}
int main()
{
int year;
int given=2001;
printf("enter year you wish to check of 1st janurary: ");
scanf("%d",&year);
int difference=year-given;
int leap=difference/4;
int nonleap=difference-leap;
int days=(leap*366)+(nonleap*365)+1;
if(days%7==0)
{
printf("sunday");
}
if(days%7==1)
{
printf("monday");
}
if(days%7==2)
{
printf("tuesday");
}
if(days%7==3)
{
printf("wednesday");
}
if(days%7==4)
{
printf("thursday");
}
if(days%7==5)
{
printf("friday");
}
if(days%7==6)
{
printf("saturday");
}
}
WAP to convert the temperature according to the following conditions:
Choice Conversion
1 Fahrenheit to Celsius
2 Celsius to Fahrenheit
#include<stdio.h>
int main()
{
int x;
float f,c;
printf("press 1 to convert farenheit to celsius: \n");
printf("press 2 to convert celsius to farenheit: \n");
scanf("%d",&x);
if(x==1)
{
printf("enter temperature in farenheit: \n");
scanf("%f",&f);
c=((f-32)/9)*5;
printf("%.2f degree celcius.\n",c);
}
else if(x==2)
{
printf("enter temperature in celcius: \n");
scanf("%f",&c);
f=((c/5)*9)+32;
printf("%.2f degree farenheit.\n",f);
}
else
{
printf("invalid input\n");
}
}
WAP to input monthly salary from the user and calculate the income tax according to the following rules:
Salary income tax
>=9000 40% of the salary
7500-8999 30% of the salary
<7500 20% of the salary
#include<stdio.h>
int main()
{
float salary,tax;
printf("enter salary: \n");
scanf("%f",&salary);
if(salary>=9000 )
{
tax=0.40*salary;
}
else if(salary>=7500 && salary <=8999)
{
tax=0.30*salary;
}
else if(salary<7500)
{
tax=0.20*salary;
}
printf("TAX: %.2f\n", tax);
}
WAP to input three numbers and print them in descending order.
#include<stdio.h>
int main()
{
int x,y,z;
printf("enter three numbers: \n");
scanf("%d%d%d",&x,&y,&z);
if(x>y && x>z)
{
if(y>z)
{
printf("%d %d %d",x,y,z);
}
else
{
printf("%d %d %d",x,z,y);
}
}
else if(y>x && y>z)
{
if(x>z)
{
printf("%d %d %d",y,x,z);
}
else
{
printf("%d %d %d",y,z,x);
}
}
else if(z>x && z>y)
{
if(x>y)
{
printf("%d %d %d",z,x,y);
}
else
{
printf("%d %d %d",z,y,x);
}
}
else if(x==y && x==z)
{
printf("%d %d %d",x,y,z);
}
else
{
printf("invalid input");
}
}
#include<stdio.h>
int main()
{
float salary,hra,da;
printf("enter salary: \n");
scanf("%f",&salary);
if(salary>=5000 && salary <=10000)
{
hra=0.10*salary;
da=0.05*salary;
}
else if(salary>=5000 && salary <=10000)
{
hra=0.15*salary;
da=0.08*salary;
}
else
{
printf("please enter valid input\n");
}
printf("HRA: %.2f\n", hra);
printf("DA: %.2f\n", da);
}