Pages

Sunday, February 09, 2014

For-Statement

Write a program to print digit from 1 to 10 


Input:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include <stdio.h>
#include <conio.h>
void main(void)
{
   clrscr();
   int count;
   for (count = 1; count <= 10; count++)
 printf("%d \n", count);
   getch();

}

Result:

1
2
3
4
5
6
7
8
9
10

XY-coordinate

Write a program that input x- and y-coordinate of a point in the coordinate plane. Based on these values, it then determines where it lies, on x-axis or y-axis or in any of the four quadrant


Input:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <conio.h>
void main (void)
 {
  clrscr();
    int x, y;
  printf("Enter the value of x- and y-coordinate: ");
   scanf("%d %d", x, y);
   if(x == 0)
    {
     if(y == 0)
 printf("The point lie on origin.");
     else
 printf("The point lie on y-axis");
    }
   else if(x > 0)
     {
      if(y == 0)
 printf("The point lie on x-axis");
      else if(y > 0)
 printf("The point lies in 1st quadrant");
      else
 printf("The point lies in 4th quadrant");
     }
   else
   {
     if(y == 0)
 printf("The point lies on x-axis");
     else if(y > 0)
 printf("The points lies in 2nd quadrant");
     else
 printf("The points lies in 3rd quardant");
   }
     getch();
 }// main