0% found this document useful (0 votes)
11 views

Let Us C: 2: Attempt The Following

This document provides 3 C programs to solve different problems. The first program determines if a seller made a profit or loss based on cost and selling price input. The second program checks if a number is even or odd. The third program checks if a year is a leap year or not.

Uploaded by

venkateshgavini
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Let Us C: 2: Attempt The Following

This document provides 3 C programs to solve different problems. The first program determines if a seller made a profit or loss based on cost and selling price input. The second program checks if a number is even or odd. The third program checks if a year is a leap year or not.

Uploaded by

venkateshgavini
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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