You are on page 1of 3

LET US C:

2ND CHAPTER:
[C] Attempt the following:

1.)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>
int main(void) {
int cp,sp;
printf("Enter cp and sp:");
scanf("%d%d",&cp,&sp);
int l=cp-sp;
if(l>0)
printf("U had a profit");
else if(l<0)
printf("U had loss");
else
printf("NO loss and no profit");
return 0;
}

#include <stdio.h>

2.)Any integer is input through the keyboard. Write a program


to find out whether it is an odd number or even number.
int main(void) {
int c;
printf("Enter c:");
scanf("%d",&c);
if(c%2==0)
printf("IT IS EVEN");
else
printf("IT IS ODD");
return 0;
}
3.)Any year is input through the keyboard. Write a
program to determine whether the year is a leap year
or not.
#include <stdio.h>

int main(void) {
int y;
printf("Enter the year u want:");
scanf("%d",&y);
if(y%400==0)
printf("Yes it is leap year");
else if(y%4==0 && y%100!=0)
printf("Leap year");

else
printf("not a leap year");

return 0;
}

You might also like