Document

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Let Us C Solutions

[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.

Submitted by Rahul Raina

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 = 5 and breadth = 4 is
greater than its perimeter

#include<stdio.h>

#include<conio.h>

main()

You might also like