C Programming

Solved Example

Practice Questions

Exercise Question

Check the axis of a point

Objective:

Input a point(x,y), write a program to find out if it lies on the x-axis, y-axis, or at the origin (0,0).

Problem / Solution:

#include<stdio.h>
int main() {
	int x,y;
	printf("Enter a point (x,y): ");
	scanf("%d%d",&x,&y);
	
	if(x == 0 && y == 0) {
		printf("Point(%d,%d) is on origin",x,y);
	}else if(x == 0 && y != 0) {
		printf("Point(%d,%d) is on x-axis",x,y);	
	}else if(x != 0 && y == 0) {
		printf("Point(%d,%d) is on y-axis",x,y);
	}else {
		printf("Point doesn't lie on any axis, nor origin");
	}
	
	return 0;
}

Sample Output:

Enter a point (x,y): 0 0
Point(0,0) is on origin

Enter a point (x,y): 5 0
Point(5,0) is on y-axis

Enter a point (x,y): 0 6
Point(0,6) is on x-axis

Enter a point (x,y): 5 5
Point doesn't lie on any axis, nor origin

More Progarms of Decision Making in C

Calculate profit or loss

Check a number is even or odd

Check a number is positive or negative

Check a year is leap year or not

Find the first day of year

Find the youngest person

Absolute value of a number

Find area of rectangle is greater than perimeter

Check the points are co-linear or not

Check a point is inside,outside or on the circle

Identify a character is alphabet, digit and more

Check the insurance eligibility and calculate premium

Calculate the library penalty charges

Calculate grade of a student