1.
Program to convert seconds into hours, minutes and seconds
#include<stdio.h>
#include<conio.h>
void main()
{
int sec, hour, min;
clrscr();
printf(“Enter seconds”);
scanf(“%d”, &sec);
hour=sec/3600;
sec=sec%3600;
min=sec/60;
sec=sec%60;
printf(“Number of hours=%d\n”, hour);
printf(“Number of minutes=%d\n”, min);
printf(“Number of seconds=%d”, sec);
getch();
}
2. Program to check whether a character is letter, digit or special character
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“Enter a character”);
scanf(“%c”, &ch);
if((ch>= ‘A’ && ch<= ‘Z’) || (ch>= ‘a’ && ch<= ‘z’))
printf(“Its a letter”);
else
if(ch>= ‘0’ && ch<= ‘9’)
printf(“Its a digit”);
else
printf(“Its a special character”);
getch();
}
3. Program to check whether given number is even or odd
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“Enter a number”);
scanf(“%d”, &n);
if(n%2==0)
printf(“Its even”);
else
printf(“Its odd”);
getch();
}
4. Program to check whether given number is positive, negative or zero
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“Enter a number”);
scanf(“%d”, &n);
if(n>0)
printf(“Its positive”);
if(n<0)
printf(“Its negative”);
if(n==0)
printf(“Its zero”);
getch();
}
5. Program to enter age and verify eligibility for voting
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf(“Enter age: ”);
scanf(“%d”, &age);
if(age>=18)
printf(“Person is eligible to vote”);
else
printf(“Person is not eligible to vote”);
getch();
}
6. Program to check whether given character is uppercase or lowercase
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“Enter a character”);
scanf(“%c”, &ch)
if (ch>= ‘A’ && ch<= ‘Z’)
printf(“Letter is uppercase”);
else if (ch>= ‘a’ && ch<= ‘z’)
printf(“Letter is lowercase”);
else
printf(“Invalid input”);
getch();
}
7. Program to take week number and display the day of the week
#include<stdio.h>
#include<conio.h>
void main()
{
Int wn;
clrscr();
printf(“Enter week number”);
scanf(“%d”, &wn);
if(wn==1)
printf(“Sunday”);
else if(wn==2)
printf(“Monday”);
else if(wn==3)
printf(“Tuesday”);
else if(wn==4)
printf(“Wednesday”);
else if(wn==5)
printf(“Thursday”);
else if(wn==6)
printf(“Friday”);
else if(wn==7)
printf(“Saturday”)
else
printf(“Invalid position”);
getch();
}
8. Program to take month number and check for season
#include<stdio.h>
#include<conio.h>
void main()
{
int mn;
clrscr();
printf(“Enter month number”);
scanf(“%d”, &mn);
if(mn==12 || mn==1|| mn==2)
printf(“Winter”);
else if(mn>=3 && mn<=5)
printf(“Spring”);
else if(mn>=6 && mn<=8)
printf(“Summer”);
else if(mn>=9 && mn<=11)
printf(“Autumn”);
else
printf(“Bogus month”)
getch();
}
9. Program to display the grade
#include<stdio.h>
#include<conio.h>
void main()
{
Int m;
clrscr();
printf(“Enter marks”);
scanf(“%d”, &m);
if(m>25)
printf(“F”);
else if(m>=25 && m<45)
print(“E”);
else if(m>=45 && m<50)
print(“D”);
else if(m>=50 && m<60)
print(“C”);
else if(m>=60 && m<80)
print(“B”);
else if(m>=80 && m<100)
print(“A”);
else
printf(“Invalid”);
getch();
}
[Link] to calculate percentage of attendance
#include<stdio.h>
#include<conio.h>
void main()
{
int ch,ca;
float perc;
clrscr();
printf(“Enter number of classes held”);
scanf(“%d”, &ch);
printf(“Enter number of classes attended”)
scanf(“%d”, &ca);
perc=(100.0*ca)/ch;
printf(“Percentage of attendance=%f\n”,perc);
if(perc>=75)
printf(”Allowed to appear”);
else
printf(“Not allowed to appear”);
getch();
}
[Link] to display the number of days in a month
#include<stdio.h>
#include<conio.h>
void main()
{
int mn;
clrscr();
printf(“Enter month number”);
scanf(“%d”, &mn);
if(mn==2)
printf(“28 days”);
else if(mn==1 || mn==3 || mn==5 || mn==7 || mn==8 || mn==10 || mn==12)
printf(“31 days”);
else if(mn==4 || mn==6 || mn==9 || mn==11)
printf(“30 days”);
else
printf(“Invalid month number”);
getch();
}
[Link] to check for person’s height
#include<stdio.h>
#include<conio.h>
void main()
{
int h;
clrscr();
printf(“Enter height in centimeter”);
scanf(“%d”, &h);
if(h<150)
printf(“Person is dwarf”);
else if(h>=150 && h<=165)
printf(“Person is average height”);
else
printf(“Tall”);
getch();
}
[Link] to check for eligibility for certain course
#include<stdio.h>
#include<conio.h>
void main()
{
int m, p, c, total, tmp;
clrscr();
printf(“Enter marks of maths, physics and chemistry”);
scanf(“%d%d%d”, &m, &p, &c);
total=m+p+c;
tmp=m+p;
if(m>=65 && p>=55 && c>=50)
{
If(total>=180 || tmp>=140)
{
printf(“Eligible”);
}
Else
printf(“Not eligible”);
}
getch();
}
[Link] to read temperature in centigrade and display suitable
message
#include<stdio.h>
#include<conio.h>
void main()
{
int t;
clrscr();
printf(“Enter temperature”);
scanf(“%d”,&t);
if (t<0)
printf(“Freezing weather”);
else if(t>=0 && t<10)
printf(“Very cold”);
else if(t>=10 && t<20)
printf(“Cold”);
else if(t>=20 && t<30)
printf(“Normal”);
else if(t>=30 && t<=40)
printf(“Hot”);
else
printf(“Very hot”);
getch();
}
[Link] to input marks in 5 subjects, calculate total, percentage and
grade according to the following
A: >=90
B: >=80
C: >=70
D: >=60
E: >=40
F: <40
#include<stdio.h>
#include<conio.h>
void main()
{
int m1,m2,m3,m4,m5,total;
float perc;
clrscr();
printf(“Enter marks in five subjects”);
scanf(“%d%d%d%d%d”, &m1, &m2, &m3, &m4, &m5);
total=m1+m2+m3+m4+m5;
perc=total/5.0;
printf(“Total=%d\n”, total);
printf(“Percentage=%f\n”, perc);
if(perc>=90)
printf(“Grade=A”);
else if(perc<90 && perc>=80)
printf(“Grade=B”)
else if(perc<80 && perc>=70)
printf(“Grade=C”)
else if(perc<70 && perc>=60)
printf(“Grade=D”)
else if(perc<60 && perc>=40)
printf(“Grade=E”)
else
printf(“Grade=F”)
getch();
}