Sie sind auf Seite 1von 11

(/)

[C] Attempt the following:


(a) If cost price and selling price of an item is input through the keyboard, write a program
to determine whether the seller has made profit or incurred loss. Also determine how
much profit he made or loss he incurred.
#include<stdio.h>
#include<conio.h>
main()
{
int cp,sp,l,p; //cp=cost price,sp=selling price,l=loss,p=profit
clrscr();
printf("Enter Cost Price of an item : RS ");
scanf("%d",&cp);
printf("Enter Selling Price of an item : RS ");
scanf("%d",&sp);
if(cp>sp) // Loop for Loss
{
l=cp-sp;
printf("You have made LOSS. Your Loss is RS %d",l);
}
else if(sp>cp) // Loop for Profit
{
p=sp-cp;
printf("You have gain PROFIT. Your Profit is RS %d",p);
}
else if(sp=cp) // Loop for no Loss no Profit
{
printf("You have neither Loss nor Profit");
}
getch();
}
(b) Any integer is input through the keyboard. Write a program to find out whether it is an
odd number or even number.
#include<stdio.h>
#include<conio.h>
main()
{
int num; // num=number
clrscr();
printf("Enter any integer to know weather its is Even or Odd : ");
scanf("%d",&num);
if(num%2==0)
{
printf("%d is Even number",num);
}
else
{
printf("%d is Odd number",num);
}
getch();
}
(c) Any year is input through the keyboard. Write a program to determine whether the year
is a leap year or not. (Hint: Use the % (modulus) operator)
#include<stdio.h>
#include<conio.h>
main()
{
int year;
clrscr();
printf("Enter any year : ");
scanf("%d",&year);
if(year%4==0)
printf("%d is a leap year.",year);
else
printf("%d is not a leap year.",year);
getch();
}
(d) According to the Gregorian calendar, it was Monday on the date 01/01/1900. If any year
is input through the keyboard write a program to find out what is the day on 1st January
of this year.
Coming Soon...
(e) A five-digit number is entered through the keyboard. Write a program to obtain the
reversed number and to determine whether the original and reversed numbers are equal
or not.
main()
{
int a,b,c,d,e,f,g,i,j;
clrscr();
printf("Enter the five digit number\n");
scanf("%d",&a);
b=a%10;
c=a/10;
d=c%10;
e=c/10;
f=e%10;
g=e/10;
i=g%10;
j=g/10;
printf("The reverse number is %d%d%d%d%d",b,d,f,i,j);
printf("\nThe original and reverse number is not equal");
getch();
}
(f) If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to
determine the youngest of the three.
main()
{
int ram, shyam, ajay;
clrscr();
printf("Enter ages of Ram, Shayam, Ajay\n");
scanf("%d %d %d", &ram, &shyam, &ajay);
if (ram<shyam)
{
if (ram<ajay)
printf("Ram is younger.");
else
printf("Ajay is younger");
}
else
{
if (shyam<ajay)
printf("Shayam is younger");
else
printf("Ajay is younger");
}
getch();
}
(g) Write a program to check whether a triangle is valid or not, when the three angles of
the triangle are entered through the keyboard. A triangle is valid if the sum of all the three
angles is equal to 180 degrees.
#include<stdio.h>
#include<conio.h>
main()
{
float a1,a2,a3,sum; //a1=angle1,a2=angle2,a3=angle3,sum=sum of all angles
clrscr();
printf("Enter three angle of a triangle : ");
scanf("%f%f%f",&a1,&a2,&a3);
sum=a1+a2+a3;
if(sum==180)
{
printf("Triangle is Valid.");
}
else
{
printf("Triangle is invalid.");
}
getch();
}
(h) Find the absolute value of a number entered through the keyboard.
void main( )
Submitted by Rahul Raina
{
int i, j;
printf ("Enter number : ");
scanf ("%d", &i);
if(i<0)
j = -i;
else
j = i;
printf ("%d", j);
getch();
}
(i) Given the length and breadth of a rectangle, write a program to find whether the area of
the rectangle is greater than its perimeter. For example, the area of the rectangle with
length = 5 and breadth = 4 is greater than its perimeter
#include<stdio.h>
#include<conio.h>
main()
{
int l,b,a,p; // l=length,b=breadth,a=area,p=perimeter of rectangle
clrscr();
printf("Enter Length of a rectangle : ");
scanf("%d",&l);
printf("Enter Breadth of a rectangle : ");
scanf("%d",&b);
p=2*(l+b);
a=l*b;
if(a>p)
{ // "\n" is use for new line
printf("\nYes! Area[%d] is greater that its perimeter[%d]",a,p);
}
else
{
printf("\nNo! Area[%d] is not greater that its perimeter[%d]",a,p);
}
getch();
}
(j) Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the
three points fall on one straight line.
#include<stdio.h>
#include<conio.h>
main()
{
int x1,y1,x2,y2,x3,y3,m1,m2; // m1=slope 1,m2=slope 2
clrscr();
printf("Enter coordinates of 1st point (x1,y1) : ");
scanf("%d%d",&x1,&y1);
printf("Enter coordinates of 2nd point (x2,y2) : ");
scanf("%d%d",&x2,&y2);
printf("Enter coordinates of 3rd point (x3,y3) : ");
scanf("%d%d",&x3,&y3);
m1=(y2-y1)/(x2-x1);
m2=(y3-y2)/(x3-x2);
if(m1==m2)
{
printf("The given point fall on one straight line.");
}
else
{
printf("The given point does not fall on one straight line.");
}
getch();
}
(k) Given the coordinates (x, y) of a center of a circle and its radius, write a program which
will determine whether a point lies inside the circle, on the circle or outside the circle.
(Hint: Use sqrt( ) and pow( ) functions)
Coming Soon...
(l) Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or at the
origin, viz. (0, 0).
#include<stdio.h>
#include<conio.h>
main()
{
int x,y;
clrscr();
printf("Enter coordinates of a point (x,y) = ");
scanf("%d%d",&x,&y);
if(x==0&&y!=0)
{
printf("The point lies on y axis.");
}
else if(y==0&&x!=0)
{
printf("The point lies on x axis.");
}
else if(x==0&&y==0)
{
printf("The point lies on origin.");
}
getch();
}
[G] Attempt the following:
(a) Any year is entered through the keyboard, write a program to determine whether the
year is leap or not. Use the logical operators && and ||.
#include<stdio.h>
#include<conio.h>
main()
{
int year;
clrscr();
printf("Enter any year : ");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||year%400==0)
{
printf("%d is a Leap Year.");
}
else
{
printf("%d is not a Leap Year.");
}
getch();
}
(b) Any character is entered through the keyboard, write a program to determine whether
the character entered is a capital letter, a small case letter, a digit or a special symbol. The
following table shows the range of ASCII values for various characters. Characters ASCII
Values for various characters.
#include<stdio.h>
#include<conio.h>
main()
{
char a;
clrscr();
printf("Enter any single letter, digit or special symbol : ");
scanf("%c",&a);
if(a>=65&&a<=90)
{
printf("You entered a CAPITAL LETTER.\n");
}
if(a>=97&&a<=122)
{
printf("You entered a SMALL LETTER.\n");
}
if(a>=48&&a<=57)
{
printf("You entered a DIGIT.\n");
}
if((a>=0&&a<=47)||(a>=58&&a<=64)||(a>=91&&a<=96)||(a>=123&&a<=127))
{
printf("You entered an SPECIAL SYMBOL.\n");
}
getch();
}
(c) A certain grade of steel is graded according to the following conditions:
(i) Hardness must be greater than 50
(ii) Carbon content must be less than 0.7
(iii) Tensile strength must be greater than 5600
The grades are as follows:
Grade is 10 if all three conditions are met
Grade is 9 if conditions (i) and (ii) are met
Grade is 8 if conditions (ii) and (iii) are met
Grade is 7 if conditions (i) and (iii) are met
Grade is 6 if only one condition is met
Grade is 5 if none of the conditions are met
Write a program, which will require the user to give values of hardness, carbon content
and tensile strength of the steel under consideration and output the grade of the steel.
#include<stdio.h>
#include<conio.h>
main()
{
float hard,carbon,tensile;
clrscr();
printf("Enter Hardness of steel : ");
scanf("%f",&hard);
printf("Enter Carbon content of steel : ");
scanf("%f",&carbon);
printf("Enter Trnsile strength of steel : ");
scanf("%f",&tensile);
if(hard>50&&carbon<0.7&&tensile>5600)
printf("\nThe grade of steel is 10");
else if(hard>50&&carbon<0.7)
printf("\nThe grade of steel is 9");
else if(carbon<0.7&&tensile>5600)
printf("\nThe grade of steel is 8");
else if(hard>50&&tensile>5600)
printf("\nThe grade of steel is 7");
else if(hard>50||carbon<0.7||tensile>5600)
printf("\nThe grade of steel is 6");
else
printf("\nThe grade of steel is 5");
getch();
}
(d) A library charges a fine for every book returned late. For first 5 days the fine is 50 paise,
for 6-10 days fine is one rupee and above 10 days fine is 5 rupees. If you return the book
after 30 days your membership will be cancelled. Write a program to accept the number of
days the member is late to return the book and display the fine or the appropriate
message.
#include<stdio.h>
#include<conio.h>
main()
{
int days;
clrscr();
printf("Enter the number of days the member is late to return the book : ");
scanf("%d",&days);
if(days<=5)
printf("\nYou must pay 50 paisa fine..."); // '\n' is used for new line
else if(days>=6&&days<=10)
printf("\nYou must pay 1 rupee fine...");
else if(days>10&&days<30)
printf("\nYou must pay 5 rupees fine...");
else if(days>=30)
printf("\nYour membership is cancelled...");
getch();
}
(e) If the three sides of a triangle are entered through the keyboard, write a program to
check whether the triangle is valid or not. The triangle is valid if the sum of two sides is
greater than the largest of the three sides.
#include<stdio.h>
#include<conio.h>
main()
{
float s1,s2,s3; //s1=side1,s2=side2,s3=side3
clrscr();
printf("Enter three sides of triangle in ascending order:\n");
scanf("%f%f%f",&s1,&s2,&s3);
if(s1+s2>s3)
printf("\nThe triangle is valid.");
else
printf("\nThe triangle is invalid.");
getch();
}
(f) If the three sides of a triangle are entered through the keyboard, write a program to
check whether the triangle is isosceles, equilateral, scalene or right angled triangle.
#include<stdio.h>
#include<conio.h>
main()
{
float a1,a2,a3; //a1=angle1,a2=angle2,a3=angle3
clrscr();
printf("Enter three angles of a triangle:\n");
scanf("%f%f%f",&a1,&a2,&a3);
if((a1+a2+a3)==180)
{
if(a1==a2&&a1==a3&&a2==a3)
printf("\nThe triangle is Equilateral.");
else if(a1==a2||a1==a3||a2==a3)
printf("\nThe triangle is Isosceles.");
else if(a1==90||a2==90||a3==90)
printf("\nThe triangle is Right Angled.");
else if(a1!=a2&&a1!=a3&&a2!=a3)
printf("\nThe triangle is Scalene");
}
else
printf("The triangle is not valid");
getch();
}
(g) In a company, worker efficiency is determined on the basis of the time required for a
worker to complete a particular job. If the time taken by the worker is between 2 3 hours,
then the worker is said to be highly efficient. If the time required by the worker is between
3 4 hours, then the worker is ordered to improve speed. If the time taken is between 4 5
hours, the worker is given training to improve his speed, and if the time taken by the
worker is more than 5 hours, then the worker has to leave the company. If the time taken
by the worker is input through the keyboard, find the efficiency of the worker.
#include<stdio.h>
#include<conio.h>
main()
{
float h; //h=hours
clrscr();
printf("Enter the time taken by the worker (In Hours) : ");
scanf("%f",&h);
if(h>=2&&h<=3)
printf("\nWorker is highly efficient.");
else if(h>=3&&h<=4)
printf("\nWorker should improve his speed.");
else if(h>=4&&h<=5)
printf("\nWorker should take training to improve the speed.");
else if(h>=5)
printf("\nWorker has to leave the company.");
getch();
}
(h) The policy followed by a company to process customer orders is given by the following
rules:
(a) If a customer order is less than or equal to that in stock and has credit is OK, supply
has requirement.
(b) If has credit is not OK do not supply. Send him intimation.
(c) If has credit is Ok but the item in stock is less than has order, supply what is in stock.
Intimate to him data the balance will be shipped.
Write a C program to implement the company policy.
Coming Soon...
[K] Attempt the following:
(a) Using conditional operators determine:
(1) Whether the character entered through the keyboard is a lower case alphabet or not.
#include<stdio.h>
#include<conio.h>
main()
{
char ch; //ch=character
clrscr();
printf("Enter any charcter to find out weather it is lower case or not : ");
scanf("%c",&ch);
(ch>=97&&ch<=122?printf("\nThe input character is lower case."):printf("\nThe input
character is not lower case."));
getch();
}
(2) Whether a character entered through the keyboard is a special symbol or not.
#include<stdio.h>
#include<conio.h>
main()
{
char ch; //ch=character
clrscr();
printf("Enter any charcter to find out weather it is special symbol or not : ");
scanf("%c",&ch);
((ch>=0&&ch<=47)||(ch>=58&&ch<=64)||(ch>=91&&ch<=96)||(ch>=123&&ch<=127)?
printf("\nThe input character is special symbol."):printf("\nThe input character is not special
symbol."));
getch();
}
(b) Write a program using conditional operators to determine whether a year entered
through the keyboard is a leap year or not.
#include<stdio.h>
#include<conio.h>
main()
{
int year;
clrscr();
printf("Enter any year : ");
scanf("%d",&year);
((year%4==0&&year%100!=0)||(year%400==0)?printf("\n%d is a leap
year.",year):printf("\n%d is not a leap year.",year));
getch();
}
(c) Write a program to find the greatest of the three numbers entered through the keyboard
using conditional operators.
#include<stdio.h>
#include<conio.h>
main()
{
int n1,n2,n3; //n1=1st number,n2=2nd number,n3=3rd number
clrscr();
printf("Enter three numbers:\n");
scanf("%d%d%d",&n1,&n2,&n3);
(n1>n2&&n1>n3?printf("\n%d is greater.",n1):(n2>n3&&n2>n1?printf("\n%d is
greater.",n2):printf("\n%d is greater.",n3)));
getch();
}
Back to Top
30 Comments Let Us C Solutions Login 1
Sort by Best Share
Join the discussion
A.WaHaB 8 months ago
plz solve this program. and send me source file
The policy followed by a company to process customer orders is given by the
following rules:
(a) If a customer order is less than or equal to that in stock and has credit is OK,
supply has requirement.
(b) If has credit is not OK do not supply. Send him intimation.
(c) If has credit is Ok but the item in stock is less than has order, supply what is
in stock. Intimate to him data the balance will be shipped.
Favorite
Reply
Write a C program to implement the company policy.

6
Reply
faizi 4 months ago A.WaHaB
good ques

1
Reply
Hafsa Ameer 6 months ago
The policy followed by a company to process customer orders is given by the
following rules:
(a) If a customer order is less than or equal to that in stock and has credit is OK,
supply has requirement.
(b) If has credit is not OK do not supply. Send him intimation.
(c) If has credit is Ok but the item in stock is less than has order, supply what is
in stock. Intimate to him data the balance will be shipped.
Write a C program to implement the company policy.
plz solve this problem

4
Reply
animesh 3 days ago
C(k)#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float area,ard,r,x,y,z;//ard is area to be determined
printf("coordinate of center of circle is (0,0) and its radius is 8\n");//coordinate of
center of circle and radius is given accrdng 2 the ques. u may assume any othr
also
printf("enter the coordinate (x,y)\n");
scanf("%f%f",&x,&y);
area=3.14*8*8;
z=pow(x,2)+pow(y,2);
r=sqrt(z);
ard=3.14*r*r;
if(ard<area) printf("coordinates="" lies="" inside="" the="" circle");="" else=""
if(ard="=area)" printf("coordinates="" lies="" on="" the="" circle");="" else=""
printf("coordinates="" lies="" outside="" the="" circle");="" getch();="" }="">

1
Reply
Sudip Modak 7 months ago
see more
The answer of G-h:
#include<stdio.h>
int main()
{
int stock,order;
char credit;
printf("Enter the stock of the company : ");
scanf("%d",&stock);
printf("Enter the order of the customer : ");
scanf("%d",&order);
printf("Is the credit has been made (y/n) : ");

1
A 8 months ago
According to the Gregorian calendar, it was Monday on the date 01/01/1900. If
any year is input through the keyboard write a program to find out what is the
day on 1st January of this year.
Answer:
Share
Share
Share
Share
Share
Reply
see more
void main()
{
float days;
int year,diff,leap,type;
long int days1;
printf("\nInput the year");
scanf("%d",&year);
year=year-1;
diff=year-1900;
/* The line year=year-1 was written because we are finding the days before
that particular year not that full year as the required date is 01/01/year.
In days... 365 was added because the year 1900 has to be taken into account
as 1900-1904 is not 1904-1900=4years but is 5 years. 1900 is not a leap year.

1
Reply
Asad ur rehman 9 months ago
thank u

1
Reply
Humza 2 years ago
irtiqa tmhara left click disable ko enable karna aa gaya:-D

1
Reply
shahidul a year ago Humza
you have done great work solving these problems,but most of your
solutions are wrong.

4
Reply
Humza 2 years ago
Irtiqa c ke part i me area ka formula sahi nahi lag raha hai .
it maight be length*breadth/2

1
Reply
chetan raikwar 7 months ago
http://letuscalllessons.blogsp...


Reply
Sayyaf 9 months ago
CALENDAR PROGRAM
#include <stdio.h>
int main ()
{
int a,b,c,d,e,f,day;
printf ("Enter the year after 1990: ");
scanf ("%d", &a);
b=(a-1)-1990;
for (c=1990,f=0; c<a; c++)="" {d="c%4;" if="" (d="=0)" f++;}="" e="(b*365)+f;"
day="e%7;" switch="" (day)="" {="" case="" 6:="" printf="" ("its="" monday");=""
break;="" case="" 5:="" printf="" ("its="" sunday");="" break;="" case="" 4:=""
printf="" ("its="" saturday");="" break;="" case="" 3:="" printf="" ("its=""
friday");="" break;="" case="" 2:="" printf="" ("its="" thursday");="" break;=""
case="" 1:="" printf="" ("its="" wednessday");="" break;="" case="" 0:="" printf=""
("its="" tuesday");="" break;="" }="" getchar="" ();="" getchar="" ();="" return=""
0;="" }="">


Reply
kainat malik 9 months ago Sayyaf
samj nai aa rahi..

1
Reply
vaibhav 9 months ago
thank you


Share
Share
Share
Share
Share
Share
Share
Share
Share
Reply
MAHAM 9 months ago
BAQI KIDR HA SOLVE EXERCISE


Reply
asya 10 months ago
I think names should not used in c pprogram


Reply
nikitha a year ago
g(f) soln is wrong since sides need to be entered not angles,inappropriate
program according to question


Reply
nikitha a year ago
solution for j is wrong since (1,2),(4,6),(12,14) are not collinear but its showing
collinear


Reply
NoorullahKazmi a year ago
C(e) solution is wrong if any one inputs 11111 then the program will also say not
equal to original


Reply
jaikant a year ago
your ans k (solution no c) is not run ..........................................


Reply
logic a year ago
Your C (e) solution is wrong if any one enter 55555 then also it will say not equal


Reply
jhanwi 9 months ago logic
point to be noted


Reply
Parveen Anand a year ago
thanx for solution


Reply
dua khan 2 years ago
thaks to solve all problems :)


Reply
Shaiza 2 years ago
Thanks :)


Reply
Pratap Singh 2 years ago
Bhai Please add other chapter's also....


Reply
Syedammadiqbal 2 years ago
halwa ha ye to :)


Reply
Humza 2 years ago
secret........


Reply
Irtiqapk 2 years ago
how to Disable Right Click?


Reply
Humza 2 years ago
Sorry u r ri8 ab8 C part i



Subscribe Add Disqus to your site
Share
Share
Share
Share
Share
Share
Share
Share
Share
Share
Share
Share
Share
Share
Share
Share
(http://disqus.com)

Das könnte Ihnen auch gefallen