[C]ATTEMPT THE FOLLOWING
(a) 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.
click here for Answer!!!
Answer:
void main()
{
float cp,sp,p;
printf("\nInput the cost price and selling price of an item");
scanf("%f%f",&cp,&sp);
p=sp-cp;
if(p>0)
printf("\nSeller has made a profit of %f",p);
else if(p<0) printf("\nSeller has made a loss of %f",p=0-p); else printf("\nSeller has neither profit nor suffer a loss"); }
(b) Any integer is input through the keyboard. Write a program to find out whether it is an odd number or even number.
click here for Answer!!!
Answer:
void main()
{
float b;
int a;
printf("\nInput an Integer");
scanf("%d",&a);
b=a%2;
if(b==0)
printf("\nInteger is an even number");
else
printf("\nInteger is an odd number");
}
(c)Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not.
(Hint: Use the % (modulus) operator)
click here for Answer!!!
Answer:
void main()
{
int year;
printf("\nInput the year");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||year%400==0)
printf("\nThe Year is a leap year");
else
printf("\nThe Year is not a leap year");
}
(d)According to the Gregorian calendar, it was Monday on the date 01/01/1900. If any year is input through the keyboard write a program to find out what is the day on 1st January of this year.
click here for Answer!!!
Answer:
void main()
{
float days;
int year,diff,leap,type;
long int days1;
printf("\nInput the year");
scanf("%d",&year);
year=year-1;
diff=year-1900;
/* The line year=year-1 was written because we are finding the days before
that particular year not that full year as the required date is 01/01/year.
In days... 365 was added because the year 1900 has to be taken into account
as 1900-1904 is not 1904-1900=4years but is 5 years. 1900 is not a leap year.
In days... addition of one was added because the first day of the year
(1st of Jan) has to be accounted for*/
if(diff<100) { leap =diff/4; days=(366.0*leap)+((diff-leap)*365+365+1); days1=days; type=days1%7; } if(diff>=100)
{
leap = (diff/4)-(diff/100)+1+((year-2000)/400);
days=(366.0*leap)+((diff-leap)*365+365+1);
days1=days;
type=days1%7;
}
if(type==0)
printf("Sunday");
if(type==1)
printf("Monday");
if(type==2)
printf("Tuesday");
if(type==3)
printf("Wednesday");
if(type==4)
printf("Thursday");
if(type==5)
printf("Friday");
if(type==6)
printf("Saturday");
printf("\nThe leap is %d\nThe days is %f\nThe type is %d",leap,days,type);
}
(e)A five-digit number is entered through the keyboard. Write a program to obtain the reversed number and to determine whether the original and reversed numbers are equal or not.
click here for Answer!!!
Answer:
void main()
{
float number,a,b,c,d,e,a2,b2,c2,d2,e2,t;
int a1,b1,c1,d1,e1;
printf("\nInput a 5 digit number");
scanf("%f",&number);
a=number/10000;
a1=a;
b=(number-(10000.0*a1))/1000;
b1=b;
c=(number-(10000.0*a1)-(1000*b1))/100;
c1=c;
d=(number-(10000.0*a1)-(1000*b1)-(100*c1))/10;
d1=d;
e=(number-(10000.0*a1)-(1000*b1)-(100*c1)-(10*d1));
e1=e;
a2=e1*10000.0;
b2=d1*1000.0;
c2=c1*100.0;
d2=b1*10.0;
e2=a1*1.0;
t=a2+b2+c2+d2+e2;
printf("\nThe reversed number is %f",t);
if(t!=number)
printf("\nThe original number and reversed number are not equal");
}
(f)If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the youngest of the three.
click here for Answer!!!
Answer:
void main()
{
int r,s,a,small;
printf("\nInput the ages of Ram,Shyam and Ajay");
scanf("%d%d%d",&r,&s,&a);
small=(r>s?(s>a?a:s):(r>a?a:r));
if(small==r)
printf("\nThe youngest is Ram with age %d",r);
if(small==s)
printf("\nThe youngest is Shyam with age %d",s);
if(small==a)
printf("\nThe youngest is Ajay with age %d",a);
}
(g)Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degrees.
click here for Answer!!!
Answer:
void main()
{
while (1)
{
float a,b,c;
int s;
printf("\nInput the number of sides the figure has");
scanf("%d",&s);
if(s==3)
printf("\nThe figure is 3 sided");
else
{
printf("\nThe figure is not 3 sided");
break;
}
printf("\nInput the three angles of the triangle");
scanf("%f%f%f",&a,&b,&c);
if(a+b+c==180)
printf("\nThe figure is a triangle");
else
printf("\nThe figure is not a triangle");
break;
}
}
(h) Find the absolute value of a number entered through the
keyboard.
click here for Answer!!!
Answer:
int main()
{
int number;
printf("Enter any no to find absolute value:");
scanf("%d",&number);
if(number<0) number=(-1)*number; printf("Absolute value is: %d",number); getch(); return 0; }
(i)Given the length and breadth of a rectangle, write a program to find whether the area of the rectangle is greater than its perimeter. For example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter.
click here for Answer!!!
Answer:
void main()
{
float l,b,a,p;
printf("Input length and breadth of rectangle");
scanf("%f%f",&l,&b);
a=l*b;
p=2.0*l+2.0*b;
(a>p?printf("\nArea is larger than perimeter"):printf("\nArea is smaller than perimeter"));
}
(j)Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on one straight line.
click here for Answer!!!
Answer:
void main()
{
float x1,x2,x3,y1,y2,y3;
printf("\nEnter the three coordinates (x1,y1),(x2,y2),(x3,y3)");
scanf("%f%f%f%f%f%f",&x1,&y1,&x2,&y2,&x3,&y3);
if ((y2-y1)/(x2-x1)==(y3-y2)/(x3-x2))
printf("\nThe three points fall on the same line");
else
printf("\nThe three points are not collinear");
}
(k) Given the coordinates (x, y) of a center of a circle and it’s radius, write a program which will determine whether a point lies inside the circle, on the circle or outside the circle. (Hint: Use sqrt( ) and pow( ) functions)
click here for Answer!!!
Answer:
int main()
{
int x,y;
printf("Enter co-ordinate(x1,y1)to check position: ");
scanf("%d%d",&x,&y);
if(x==0&&y==0)
printf("\nPoint lies on the origin ");
else if(x==0&&y!=0)
printf("\nPoint lies on the y-axis ");
else
printf("\nPoint lies on the x-axis ");
getch();
return 0;
}
(l) Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or at the origin, viz. (0, 0).
click here for Answer!!!
Answer:
void main()
{
float x,y;
printf("\nInput the(x,y) values");
scanf("%f%f",&x,&y);
if(x==0&&y==0)
printf("\nThe point lies on the origin");
else if(x==0&&y!=0)
printf("\nThe point lies on the y-axis");
else if(x!=0&&y==0)
printf("\nThe point lies on the x-axis");
else
printf("\nThe point does not lie on any axis or origin");
}
Excellent work . . . .. :)
ReplyDeletehey...can you post the program code of this question
ReplyDelete1.Given a circle x2 +y2 =r2 .WAP to determine whether a point(x1,y1) lies inside, outside or on the circle.
no we cnt post
DeleteChapter 2 [C] K part solution is not correct as there is center point not mentioned here to compare value and find out the result according to quadrant geometry, please share correct answer
ReplyDeleteTry this for question K
ReplyDelete#include
#include
#include
main()
{
float x,y,r,d;
printf("\nEnter the value of x and y:");
scanf("%f %f",&x,&y);
printf("Enter the radius:");
scanf("%f",&r);
d=sqrt(x*x+y*y);
if(d>r)
printf("\nPoint is outside");
else if(d==r)
printf("\nPoint is on the circle");
else if(d<r)
printf("\nPoint lies inside the circle");
getch();
return 0;
}