Wednesday 9 March 2016

INTERCEPTS


Emily is a very popular Maths Teacher in School. She retires from her service today. Her 7th class students like her very much and they wanted to give her a grand farewell at school. The school HeadMistress is a very strict person and she didn't give permission for them to conduct the farewell in the school premises. The students decided to conduct the farewell at Emily Mam's house itself.

They know the street in which Emily mam lives. The student leader asked Emily Mam to tell her house number. Emily Mam's last class was on Equation for a straight line. She said that a straight line can be represented by the equation y=mx+c and you know how to find the x-intercept and y-intercept of the line and my house number is the sum of the x-intercept and y-intercept of the line.

The students were puzzled. Can you help the students find the house number of Emily Mam? 

 Given the values of m and c of the line equation y=mx+c, write a C program to find the sum of x-intercept and y-intercept.

Input Format: 
Input consists of 2 integers. The first integer corresponds to m and the second integer corresponds to c. 
Output Format:
Refer Sample Input and Output for exact formatting specifications. 
[Assume that the inputs are such that the intercept values are always integers] 

Sample Input and Output: 
[All text in bold corresponds to input and the rest corresponds to output]
Enter the value of m
5
Enter the value of c
10
The line equation is y=5x+10
The x intercept is -2
The y intercept is 10
The house number is 8

Code:
  #include<stdio.h>
int main(){
  int m,x,y,c;
  printf("Enter the value of m\n");
  scanf("%d",&m);
  printf("Enter the value of c\n");
  scanf("%d",&c);
  x=(0-c)/m;
  y=(m*0)+c;
  printf("The line equation is y=%dx+%d\n",m,c);
  printf("The x intercept is %d\n",x);
  printf("The y intercept is %d\n",y);
  printf("The house number is %d",x+y);
  
  return 0;
}

No comments:

Post a Comment