Credit: Sahil Ajmeri
1 . Write a program to accept number of seconds and display its
corresponding hours, minutes and seconds
#include<stdio.h>
#include<conio.h>
void main()
{
int sec , min , hour;
clrscr();
printf("Enter
Seconds : ");
scanf("%d",&sec);
hour=sec/3600;
sec=sec%3600;
min=sec/60;
sec=sec%60;
printf("\n\n\n\t\t%d
hours %d minutes %d
seconds",hour,min,sec);
getch();
}
2. Write a C program to find the maximum from given three numbers (Using
Nested IF).
#include<stdio.h>
#include<conio.h>
void main()
{
int no_1 , no_2 , no_3;
clrscr();
printf("Enter value of
Number 1 : ");
scanf("%d",&no_1);
printf("\nEnter value
of Number 2 : ");
scanf("%d",&no_2);
printf("\nEnter value
of Number 3 : ");
scanf("%d",&no_3);
if(no_3>=no_2)
{
if(no_2>=no_3)
{
printf("\nNumber
%d is Maximum",no_2);
}
else
{
printf("\nNumber
%d is Maximum",no_3);
}
}
else
{
if(no_1>=no_2)
{
printf("\nNumber
%d is Maximum",no_1);
}
else
{
printf("\nNumber
%d is Maximum",no_2);
}
}
getch();
}
3. Write a C program to find that the accepted no is Negative, Positive
or Zero
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("Enter
Number :
");
scanf("%d",&no);
if(no>0)
{
printf("\n\tNumber
is positive");
}
else if(no<0)
{
printf("\n\tNumber
is negative");
}
else
{
printf("\n\tNumber
is neither positive nor negative");
}
getch();
}
4. Write a program to check given year is a Leap year or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter Year
: ");
scanf("%d",&year);
if(year%4==0)
{
printf("\n%d
is an leap year",year);
}
else
{
printf("\n%d is not an leap year",year);
}
getch();
}
5. Write a C program to find minimum from given 3 numbers (Using
Conditional Operator).
#include<stdio.h>
#include<conio.h>
void main()
{
int n1 , n2 , n3 , temp ,
min ;
clrscr();
printf("Enter value of
1st number :
");
scanf("%d",&n1);
printf("\nEnter value
of 2nd number :
");
scanf("%d",&n2);
printf("\nEnter value
of 3rd number :
");
scanf("%d",&n3);
temp = (a<b) ? a : b;
min = (c<temp) ? c : temp;
printf("\n\n\tThe
minimum of three is %d",min);
getch();
}
6. Write a C program to find the maximum from given three numbers
(Without using Nested if, or Logical Operator, Or Conditional operators).
#include<stdio.h>
#include<conio.h>
void main()
{
int n1 , n2 , n3;
clrscr();
printf("Enter Number
1 value : ");
scanf("%d",&n1);
printf("\nEnter Number
2 value : ");
scanf("%d",&n2);
printf("\nEnter Number
3 value : ");
scanf("%d",&n3);
printf("\n\n\nThe
biggest value is : %d
",(n1>n2&&n1>n3?n1:n2>n3?n2:n3));
getch();
}
7. Take marks from the user and print grade accordingly( >=75 marks –
Distinction, <75 and >=60 marks – First, <60 and >=50 – Second,
<50 and >=35 – Pass, <35 – Fail) using if … else if….else statement
and also by using logical operators).
#include<stdio.h>
#include<conio.h>
void main()
{
int marks;
clrscr();
printf("Enter your
marks to know your result : ");
scanf("%d",&marks);
if(marks>=75)
{
printf("\nDistinction");
}
else if(marks<75
&& marks>=60)
{
printf("\nFirst
Class");
}
else
if(marks<60 && marks>=50)
{
printf("\nSecond
Class");
}
else
if(marks<50 && marks>=35)
{
printf("\nPass
Class");
}
else
{
printf("\nFail");
}
getch();
}
8. Take 2 numbers from the user and print the greater number (Number can
be equal)
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2;
clrscr();
printf("Enter two
numbers : ");
scanf("%d
%d",&n1,&n2);
if(n1>=n2)
{
printf("\n%d
number is greater",n1);
}
else
{
printf("\n%d
number is greater",n2);
}
getch();
}
9. Write a program to check whether the blood donor is eligible or not
for donating blood. The conditions laid down are as under. Use if statement. a)
Age should be above 18 yrs but not more than 55 yrs.
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf("Enter your age
: ");
scanf("%d",&age);
if(age>=18 ! age<=55)
{
printf("\nYour
are eligible for donating blood");
}
else
{
printf("\nYour
are not eligible for donating blood");
}
getch();
}
10. Write a program to calculate bill of a job work done as follows. Use
if else statement. a) Rate of typing 3 Rs/page b) Printing of 1st copy
5Rs/pages & later every copy 3Rs/page. The user should enter the number of
pages and print out copies he/she wants
#include<stdio.h>
#include<conio.h>
void main()
{
int pages, rate, copy,
total;
clrscr();
printf("\nEnter number
of Pages: ");
scanf("%d",
&pages);
rate = pages * 3;
if(pages < 1)
{
printf("\nIt's
Free");
}
else
{
copy = pages * 3;
}
total = rate + copy + 5;
printf("\n\nTotal cost
of Print = %d", total);
getch();
}
11. The ABC Insurance Company Ltd. Offers the following three categories of car
insurance policy to car owners: • Category A, here the basic premium is
calculated as 2% of the car’s value. • Category B, here the basic premium is
calculated as 3% of the car’s value. • Category C, here the basic premium is
calculated as 5% of the car’s value.
#include<stdio.h>
#include<conio.h>
void main()
{
long int v,c,a;
clrscr();
printf("Enter value of
car :
");
scanf("%ld",&v);
printf("\n\nChosse
category of your car\n\t\t");
printf("\nPress 1 for
Category A");
printf("\nPress 2 for
Category B");
printf("\npress 3 for
Category C");
printf("\n\n\t\tYour
Answer :
");
scanf("%ld",&c);
switch(c)
{
case 1:
printf("\nYour
basic premium is %ld ",v*2/100);
break;
case 2:
printf("\nYour
basic premium is %ld ",v*3/100);
break;
case 3:
printf("\nYour
basic premium is %ld ",v*3/100);
break;
default:
printf("\n\n\nEnter valid choice");
}
getch();
}
12. Write a program to implement calculator using switch case.
#include<stdio.h>
#include<conio.h>
void main()
{
int choice , a , b;
clrscr();
printf("Enter value of
A : ");
scanf("%d",&a);
printf("\nEnter value
of B : ");
scanf("%d",&b);
printf("\n\nSelect
your Choice\n ");
printf("\n\tPress 1
for Addition");
printf("\n\tPress 2
for Substraction");
printf("\n\tPress 3
for Multiplication");
printf("\n\tPress 4
for Division");
printf("\n\tPress 5
for Modulo");
printf("\n\n\t\tYour
Answer : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n\n\t\tYour
Addition = %d",a+b);
break;
case 2:
printf("\n\n\t\tYour
Substraction = %d",a-b);
break;
case 3:
printf("\n\n\t\tYour
Multiplication = %d",a*b);
break;
case 4:
printf("\n\n\t\tYour
Division = %d",a/b);
break;
case 5:
printf("\n\n\t\t\tYour Modulo =
%d",a%b);
break;
default:
printf("\n\n\nEnter valid Choice");
}
getch();
}
No comments:
Post a Comment