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