0% found this document useful (0 votes)
19 views5 pages

PS Solution

The document contains code snippets for 4 different C programs: 1. A program to check if a year entered by the user is a leap year or not. 2. A program to find the weekday of a given date. 3. A program to check if a triangle is equilateral, isosceles, or scalene based on the lengths of its three sides. 4. A program to accept an (x,y) coordinate point and determine which quadrant of a XY coordinate system it lies in.

Uploaded by

soniamtech2014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

PS Solution

The document contains code snippets for 4 different C programs: 1. A program to check if a year entered by the user is a leap year or not. 2. A program to find the weekday of a given date. 3. A program to check if a triangle is equilateral, isosceles, or scalene based on the lengths of its three sides. 4. A program to accept an (x,y) coordinate point and determine which quadrant of a XY coordinate system it lies in.

Uploaded by

soniamtech2014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

check whether the year entered by the user is a


leap year or not.
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);

// leap year if perfectly divisible by 400


if (year % 400 == 0) {
printf("%d is a leap year.", year);
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
printf("%d is not a leap year.", year);
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
printf("%d is a leap year.", year);
}
// all other years are not leap years
else {
printf("%d is not a leap year.", year);
}

return 0;
}

2.Find weekday of given date


# include <stdio.h>
# include <conio.h>
void main()
{
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char week[7][10] ;
int date, mon, year, i, r, s = 0 ;
clrscr();
strcpy(week[0], "Sunday") ;
strcpy(week[1], "Monday") ;
strcpy(week[2], "Tuesday") ;
strcpy(week[3], "Wednesday") ;
strcpy(week[4], "Thursday") ;
strcpy(week[5], "Friday") ;
strcpy(week[6], "Saturday") ;
printf("Enter a valid date (dd/mm/yyyy) : ") ;
scanf("%d / %d / %d", &date, &mon, &year) ;
if( (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)) )
month[1] = 29 ;
for(i = 0 ; i < mon - 1 ; i++)
s = s + month[i] ;
s = s + (date + year + (year / 4) - 2) ;
s = s % 7 ;
printf("\nThe day is : %s", week[s]) ;
getch() ;
}
3. Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene.

 Step 1: Declare three sides of triangle.


 Step 2: Enter three sides at run time.
 Step 3: If side1 == side2 && side2 == side3
 Go to step 6
 Step 4: If side1 == side2 || side2 == side3 || side3 == side1
 Go to Step 7
 Step 5: Else
 Go to step 8
 Step 6: Print the triangle is equilateral.
 Step 7: Print the triangle is isosceles.
 Step 8: Print the triangle is scalene.

#include<stdio.h>
int main(){
int side1, side2, side3;
printf("Enter sides of triangle:");
scanf("%d%d%d",&side1,&side2,&side3);
if(side1 == side2 && side2 == side3)
printf("The Given Triangle is equilateral
");
else if(side1 == side2 || side2 == side3 || side3 == side1)
printf("The given Triangle is isosceles
");
else
printf("The given Triangle is scalene
");
return 0;
}

4. Write a C program to accept a coordinate point in a XY coordinate


system and determine in which quadrant the coordinate point lies.

#include <stdio.h>
int main()
{
int x,y;
printf("Input the coordinate(x,y): \n");
scanf("%d",&x);
scanf("%d",&y);
if (x>0 && y>0)
printf("The coordinate point (%d,%d) lies in First Quadrant ",x,y);
else if (x<0 && y>0)
printf("The coordinate point (%d,%d) lies in secound Quadrant ",x,y);
else if (x<0 && y<0)
printf("The coordinate point (%d,%d) lies in Third Quadrant ",x,y);
else if (x>0 && y<0)
printf("The coordinate point (%d,%d) lies in Forth Quadrant ",x,y);
return 0;
}
Sprial of matrix

You might also like