Академический Документы
Профессиональный Документы
Культура Документы
(/)
(http://rating-widget.com/my-rating-report/star/oxygen/rating-86327220-5/)
Rate this (152 Votes)
determine whether the seller has made profit or incurred loss. Also determine how much
#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
{
http://letuscsolutions.weebly.com/chapter-2.html 1/23
8/25/2017 Chapter 2 - Let Us C Solutions
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
#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
#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.
http://letuscsolutions.weebly.com/chapter-2.html 2/23
8/25/2017 Chapter 2 - Let Us C Solutions
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
main()
{
int ram, shyam, ajay;
clrscr();
printf("Enter ages of Ram, Shayam, Ajay\n");
scanf("%d %d %d", &ram, ­am, &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");
}
http://letuscsolutions.weebly.com/chapter-2.html 3/23
8/25/2017 Chapter 2 - Let Us C Solutions
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
#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( )
{
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 =
http://letuscsolutions.weebly.com/chapter-2.html 4/23
8/25/2017 Chapter 2 - Let Us C Solutions
#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
#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.");
}
http://letuscsolutions.weebly.com/chapter-2.html 5/23
8/25/2017 Chapter 2 - Let Us C Solutions
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.
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,
#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();
}
#include<stdio.h>
#include<conio.h>
main()
{
int year;
clrscr();
printf("Enter any year : ");
scanf("%d",&year);
http://letuscsolutions.weebly.com/chapter-2.html 6/23
8/25/2017 Chapter 2 - Let Us C Solutions
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
#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))
http://letuscsolutions.weebly.com/chapter-2.html 7/23
8/25/2017 Chapter 2 - Let Us C Solutions
{
printf("You entered an SPECIAL SYMBOL.\n");
}
getch();
}
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");
http://letuscsolutions.weebly.com/chapter-2.html 8/23
8/25/2017 Chapter 2 - Let Us C Solutions
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
#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();
}
http://letuscsolutions.weebly.com/chapter-2.html 9/23
8/25/2017 Chapter 2 - Let Us C Solutions
(f) If the three sides of a triangle are entered through the keyboard, write a program to check
#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)
http://letuscsolutions.weebly.com/chapter-2.html 10/23
8/25/2017 Chapter 2 - Let Us C Solutions
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.
(c) If has credit is Ok but the item in stock is less than has order, supply what is in stock.
Coming Soon...
(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 : ");
http://letuscsolutions.weebly.com/chapter-2.html 11/23
8/25/2017 Chapter 2 - Let Us C Solutions
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
#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
#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
Sort by Best
Recommend 15 Share
LOG IN WITH
http://letuscsolutions.weebly.com/chapter-2.html 12/23
8/25/2017 Chapter 2 - Let Us C Solutions
LOG IN WITH
Name
(a) If a customer order is less than or equal to that in stock and has credit is
OK, supply has requirement.
(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.
(a) If a customer order is less than or equal to that in stock and has credit is
OK, supply has requirement.
(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.
http://letuscsolutions.weebly.com/chapter-2.html 13/23
8/25/2017 Chapter 2 - Let Us C Solutions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace practice_makes_a_man_perfect
class Program
Reply Share
A 4 years 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:
void main()
{
float days;
int year,diff,leap,type;
http://letuscsolutions.weebly.com/chapter-2.html 14/23
8/25/2017 Chapter 2 - Let Us C Solutions
/* 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
see more
2 Reply Share
#include<stdio.h>
int main()
int stock,order;
char credit;
scanf("%d",&stock);
scanf("%d",&order);
1 Reply Share
http://letuscsolutions.weebly.com/chapter-2.html 16/23
8/25/2017 Chapter 2 - Let Us C Solutions
1 Reply Share
The numbers in the series should be used to create a Pyramid. The base of
the Pyramid will be the widest and will start converging towards the top where
there will only be one element. Each successive layer will have one number
less than that on the layer below it. The width of the Pyramid is specified by
an input parameter N. In other words there will be N numbers on the bottom
layer of the pyramid.
http://letuscsolutions.weebly.com/chapter-2.html
#include<stdio.h> 17/23
8/25/2017 Chapter 2 - Let Us C Solutions
#include<stdio.h>
#include<math.h>
void main()
int x,y,r=5;
int a,b,d;
printf("enter point");
scanf("%d%d",&a,&b);
scanf("%d%d",&x,&y);
d=sqrt((pow((x-a),2)+pow((y-b),2)));
see more
Reply Share
#include<stdio.h>
#include<conio.h>
int main()
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a==b&&a==c&&b==c)
see more
Reply Share
#include <stdio.h>
#include <math.h>
/*Given the coordinates (x, y)of a center of a circle and its radius,
int main()
float xn, yn, a, b; //xn and yn are the coordinates of an any point in or out of a
circle
see more
Reply Share
Reply Share
#include <stdio.h>
int main ()
int a,b,c,d,e,f,day;
b=(a-1)-1990;
http://letuscsolutions.weebly.com/chapter-2.html 21/23
8/25/2017 Chapter 2 - Let Us C Solutions
thank you
Reply Share
http://letuscsolutions.weebly.com/chapter-2.html 23/23