Tuesday, April 7, 2020

C Programming slip 10




BCA PRACTICAL SLIPS SOLUTION


Slip 10
Q1. Write a C program to accept the x and y coordinate of a point and find the quadrant in
which the point lies. [15 Marks]
#include <stdio.h>
void main()
{
 int x, y;
 printf("Enter the values for X and Y\n");
 scanf("%d %d", &x, &y);
 if (x > 0 && y > 0)
 printf("point (%d, %d) lies in the First quandrant\n");
 else if (x < 0 && y > 0)
 printf("point (%d, %d) lies in the Second quandrant\n");
 else if (x < 0 && y < 0)
 printf("point (%d, %d) lies in the Third quandrant\n");
 else if (x > 0 && y < 0)
 printf("point (%d, %d) lies in the Fourth quandrant\n");
 else if (x == 0 && y == 0)
 printf("point (%d, %d) lies at the origin\n");
}

-----------------------------------------------------------------

Q2. Write a program, which accepts a number n and displays each digit in words.
Example: 6702 Output = Six-Seven-Zero-Two [25 Marks]
#include<stdio.h>
int main()
{
int a,n=1,x,m=0,p;
printf("enter no :");
scanf("%d",&a);
p=a;
while(p!=0)
{
 p=p/10;
 n=n*10;
}
while(a!=0)
{
 n=n/10;
 x=a%10;
 a=a/10;
 m=m+(x*n);
}
 while(m!=0)
{
x=m%10;
 m=m/10;
 switch(x)
{
case 0:
printf("Zero");
break;
case 1:
printf("one - ");
break;
case 2:
printf("Two - ");
break;
case 3:
printf("Three - ");
break;
case 4:
printf("Four - ");
break;
case 5:
printf("Five - ");
break;
case 6:
printf("Six - ");
break;
case 7:
printf("Seven - ");
break;
case 8:
printf("Eight - ");
break;
case 9:
printf("Nine -");
break;
}
}
}

No comments:

Post a Comment