PROGRAM - 3(a)
Write a program that prints the given 3 integers in ascending order using if-else.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,max,max2,min;
clrscr();
printf("Enter 3 numbers (a,b,c) : ");
scanf("%d %d %d",&a,&b,&c);
if (a>b && a>c)
{
max=a;
if (b>c)
max2=b,min=c;
else
max2=c,min=b;
}
else if (b>c)
{
max=b;
if (a>c)
max2=a,min=c;
else
max2=c,min=a;
}
else
{
max=c;
if (a>b)
max2=a,min=b;
else
max2=b,min=a;
}
printf("The ascending order is : %d %d %d"
,min,max2,max);
getch();
}
/* OUTPUT:Enter 3 Numbers(a,b,c): 5 4 6
The ascending order is: 4 5 6
*/
PROGRAM - 3(b)
Write a program to calculate commission for the input value of sales amount.
Commission is calculated as per the following rules:
i) Commission is NIL for sales
amount Rs.5000.
amount Rs.5000.
ii) Commission is 2% for sales when sales
amount is > Rs.5000 and <= Rs.10000
amount is > Rs.5000 and <= Rs.10000
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
float amount=0,com=0;
clrscr();
printf("Enter the sales amount : ");
scanf("%f",&amount);
if (amount==5000)
com=amount*0.0;
else if (amount >5000 && amount <=10000)
com=amount*0.02;
else if (amount>10000)
com=amount*0.05;
printf("commission=%f",com);
getch();
}
/* OUTPUT:enter the amount 8332.5
the commision is 166.649994
*/
PROGRAM - 3(c)
A Character is entered through keyboard. Write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters.
Character ASCII Values
A-Z 65-90
a-z 97-122
0-9 48-57
Special symbols 0-47,58-64,
91-96,123-127
91-96,123-127
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
clrscr();
printf("enter the character or digit
or symbol : ");
scanf("%c",&a);
if (a>=65 && a<=90)
printf("\n Capital letter");
else if (a>=97 && a<=122)
printf("\n Small case letter");
else if (a>=48 && a<=57)
printf("\n digit");
else if((a>=0 && a<=47) || (a>=58 && a<=64)
|| (a>=91 && a<=96)|| (a>=123 && a<127))
|| (a>=91 && a<=96)|| (a>=123 && a<127))
printf("\n Special symbol");
getch();
}
/* OUTPUT: enter the character or digit or symbol: &
Special symbols
*/
No comments:
Post a Comment