SET A
1. Write a program, which accepts a character from the user and checks if it is an alphabet, digit
or punctuation symbol. If it is an alphabet, check if it is uppercase or lowercase and then change
the case.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("\nEnter charcter:");
scanf("%c",&ch);
if(isalpha(ch))
{
printf("\n%c is alphabet",ch);
if(isupper(ch))
printf("\n %c is uppercase alphabet",ch);
else if(islower(ch))
printf("\n %c is lowercase aplhabet",ch);
}
else if(isdigit(ch))
printf("\n %c is digit",ch);
else if(ispunct(ch))
printf("\n %c is a punctuation ",ch);
getch();
}
/*
Enter charcter:4
4 is digit
Enter charcter:!
! is a punctuation
Enter charcter:D
D is alphabet
D is uppercase alphabet
1. Write a program, which accepts a character from the user and checks if it is an alphabet, digit
or punctuation symbol. If it is an alphabet, check if it is uppercase or lowercase and then change
the case.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("\nEnter charcter:");
scanf("%c",&ch);
if(isalpha(ch))
{
printf("\n%c is alphabet",ch);
if(isupper(ch))
printf("\n %c is uppercase alphabet",ch);
else if(islower(ch))
printf("\n %c is lowercase aplhabet",ch);
}
else if(isdigit(ch))
printf("\n %c is digit",ch);
else if(ispunct(ch))
printf("\n %c is a punctuation ",ch);
getch();
}
/*
Enter charcter:4
4 is digit
Enter charcter:!
! is a punctuation
Enter charcter:D
D is alphabet
D is uppercase alphabet
2. Write a menu driven program to perform the following operations till the user selects Exit.
Accept appropriate data for each option. Use standard library functions from math.h
i. Sine ii. Cosine iii. log iv. ex v. Square Root vi. Exit
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int ch;
double n,x,ans;
clrscr();
printf("\n1.Power\n2.square root\n3.Floor\n4.Ceil\n5.Exit");
while(ch!=5)
{
printf("\nEnter your Choise:");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nEnter number and Power:");
scanf("%lf%lf",&x,&n);
ans=pow(x,n);
printf("\nPower is:%lf",ans);
break;
case 2:printf("\nEnter Number :") ;
scanf("%lf",&n);
ans=sqrt(n);
printf("\n %lf is square root of %lf",ans,n);
break;
case 3:printf("\nEnter Number:");
scanf("%lf",&n);
ans=floor(n);
printf("\n%lf floor is %lf",n,ans);
break;
case 4:printf("\nEnter Number:");
scanf("%lf",&n);
ans=ceil(n);
printf("\n%lf ceiling is %lf",n,ans);
break;
case 5:printf("\nExit");
exit(0);
}
}
getch();
}
OUTPUT:
1.Power2.square root3.Floor4.Ceil5.ExitEnter your Choise:1Enter number and Power:23Power is:8.000000Enter your Choise:2
Enter Number :25
5.000000 is square root of 25.000000Enter your Choise:3
Enter Number:1.5456567
1.545657 floor is 1.000000
Enter your Choise:4
Enter Number:2.348348574
2.348349 ceiling is 3.000000
Enter your Choise:5
Exit
---------------------------------------------------------------------------------------------------------------
3. Accept two complex numbers from the user (real part, imaginary part). Write a menu driven
program to perform the following operations till the user selects Exit.
i. ADD ii. SUBTRACT iii. MULTIPLY iv. EXIT
Code:
#include<conio.h>
#include<stdio.h>
#include<stdio.h>
void main()
{
int n1,d1,n2,d2,ch;
float ans;
clrscr();
printf("\nEnter Numerator and denominator of First number");
scanf("%d%d",&n1,&d1);
printf("\nEnter Numerator and denominator of Secconds number");
scanf("%d%d",&n2,&d2);
printf("\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Exit");
while(ch!=4)
{
printf("\nEnter your choise:");
scanf("%d",&ch);
switch(ch)
{
case 1:ans=(n1*d1+d1*n2)/d1*d2;
printf("\nAddition is %f",ans);
break;
case 2:ans=(n1*d1-d1*n2)/d1*d2;
printf("\nSubtraction is %f",ans);
break;
case 3:ans=(n1*n2)/d1*d2;
printf("\nMultiplication is %f",ans);
break;
}
}
getch();
}
OUTPUT:
Enter Numerator and denominator of First number42Enter Numerator and denominator of Secconds number631.Addition2.Subtraction3.Multiplication4.ExitEnter your choise:1Addition is 30.000000Enter your choise:2Subtraction is -6.000000Enter your choise:3Multiplication is 36.000000Enter your choise:4
---------------------------------------------------------------------------------------------------------------
SET B
1. Accept x and y coordinates of two points and write a menu driven program to perform the
following operations till the user selects Exit.
i. Distance between points.
ii. Slope of line between the points.
iii. Check whether they lie in the same quadrant.
iv. EXIT
(Hint: Use formula m = (y2-y1)/(x2-x1) to calculate slope of line.)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double x1,y1,x2,y2,ans;
int ch;
clrscr();
printf("\nEnter Point A:");
scanf("%lf%lf",&x1,&y1);
printf("\nEnter Point B:");
scanf("%lf%lf",&x2,&y2);
printf("\n1.Distance\n2.Slop\n3.Quadrant\n4.Exit");
while(ch!=4)
{
printf("\nEnter your chosie:");
scanf("%d",&ch);
switch(ch)
{
case 1:ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
ans=sqrt(ans);
printf("\nDistance is %lf:",ans);
break;
case 2:ans=(y2-y1)/(x2-x1);
printf("\nSlop is %lf:",ans);
break;
case 3:if(x1>0 &&x2>0 &&y1>0 &&y2>0)
printf("\nIn same quadrant and in First quadrant:");
break;
}
}
getch();
}
SET B
1. Accept x and y coordinates of two points and write a menu driven program to perform the
following operations till the user selects Exit.
i. Distance between points.
ii. Slope of line between the points.
iii. Check whether they lie in the same quadrant.
iv. EXIT
(Hint: Use formula m = (y2-y1)/(x2-x1) to calculate slope of line.)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double x1,y1,x2,y2,ans;
int ch;
clrscr();
printf("\nEnter Point A:");
scanf("%lf%lf",&x1,&y1);
printf("\nEnter Point B:");
scanf("%lf%lf",&x2,&y2);
printf("\n1.Distance\n2.Slop\n3.Quadrant\n4.Exit");
while(ch!=4)
{
printf("\nEnter your chosie:");
scanf("%d",&ch);
switch(ch)
{
case 1:ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
ans=sqrt(ans);
printf("\nDistance is %lf:",ans);
break;
case 2:ans=(y2-y1)/(x2-x1);
printf("\nSlop is %lf:",ans);
break;
case 3:if(x1>0 &&x2>0 &&y1>0 &&y2>0)
printf("\nIn same quadrant and in First quadrant:");
break;
}
}
getch();
}
Best one!!!!
ReplyDeleteThank you for your valuable feedback.
DeleteIn the Q3 of setA,there should be ans=(n1*d2+d1*n2)/d1*d2 and not the ans=(n1*d1+d1*n2)/d1*d2.
ReplyDelete