counter

Free Hit Counter
Showing posts with label Decision control structure. Show all posts
Showing posts with label Decision control structure. Show all posts

C program to check if input year is leap year

Q:C program to check if input year is leap year or not when the year is input from the user

#include
#include
void main()
{
int year;
clrscr();
printf("enter any year: ");
scanf("%d",year);
if(year%400==0 || year%100!=0 && year%4==0)
{
printf("this year is leap year");
}
else
{
printf("this year is not leap year");
}
getch();
}

c program to check position of point in a circle


Q:Write a c program to check whether a given point is outside, inside or on the circle when radius and coordinates of points are input



#include
#include
void main()
{
int x,y,r,d;
clrscr();
printf("enter x co ordinate");
scanf("%d",&x);
printf("enter y co ordinate");
scanf("%d",&y);
printf("enter radius");
scanf("%d",&r);

d=(x*x)+(y*y);
r=r*r;
if(d==r)
{
printf("point is on the circle");
}
else if(d>r)
{
printf("point is outside the circle");
}
else if(d
{
printf("point is inside the circle");
}
getch();
}

C program to compare area and perimeter


Q:Given the length and breadth of rectangular,write a program to find whether the area of the rectangle is greater than its perimeter.

#include
#include
void main()
{
int l,b,a,p;
clrscr();
printf("enter the length: ");
scanf("%d",&l);
printf("enter the bragth: ");
scanf("%d",&b);
a=l*b;
p=2*l+2*b;
if(a>p)
{
printf("area is big");
}
else
{
printf("perameter is big");
}
getch();
}

C program to check validity of triangle


Q:Write a c program to check whether a triangle is valid or not ..when the three angles of the triangle are entered through keyboard.A triangle is valid if sum of all angles is 180

#include
#include
void main()
{
int A1,A2,A3;
clrscr();
printf("enter three angles: ");
scanr("%d",&A1);
scanf("\n%d",&A2);
scanf("\n%d",&A3);
if(A1+A2+A3==180)
{
printf("valid tringle");
}
else
{
printf("invalid tringle");
}
getch();
}

C program to display day on !st january of any year



Q:According to Gregorian calendar,it was monday on 01/01/1900.If any year is input through the keyboard.write a program to find out what was the date on 1st January of that year


#include
#include
void main()
{
long int nd,ld,td,fd,year;
clrscr();
printf("enter the year");
scanf("%ld",&year);
nd=(year-1)*365;
ld=(year-1)/4-(year-1)/100+(year-1)/400;
td=nd+ld;
fd=td%7;

if(fd==0)
printf("\n monday");
if(fd==1)
printf("\n tuesday");
if(fd==2)
printf("\n wednesday");
if(fd==3)
printf("\n thursday");
if(fd==4)
printf("\n friday");
if(fd==5)
printf("\n saturday");
if(fd==6)
printf("\n sunday");
getch();
}