Get Email Subscription

Enter your email address:

Delivered by FeedBurner

Monday, January 4, 2010

Write a program in 'C' to calculate house rent allowance (hra), Dearness allowance (da) and the gross & Net salary. (Using if.........else statement.)

Q.1) In a company the employee are paid as follows:-
If basic pay (bp) is less than Rs. 2000/- then the house rent allowance (hra) is 10% of basic pay and dearness allowance (da) is 90% of basic pay.
If basic pay is equal or more than Rs. 2000/- then the house rent allowance is Rs. 500/- and dearness allowance is 98% of basic pay.
Gross salary (gs) = bp + hra + da

Write a program in 'C' to enter the basic pay and to find and print the hra, da and the gross salary.




#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float bp, hra, da, gs;
printf(" \n Enter the basic pay \n");
scanf("%f", &bp);
if (bp < 2000)
{
hra = bp * 10/100;
da = bp * 90/100;
}
else
{
hra = 500.0;
da = bp * 98/100;
}
gs = bp + hra + da;
printf("The hra is Rs. %f \n", hra);
printf("The da is Rs. %f \n", da);
printf("The gross salary is %f \n", gs);
return(0);
}

For eg :-

Output :-
Enter the basic pay
1000
The hra is Rs. 100.000000
The da is Rs. 900.000000
The gross salary is Rs. 2000.000000
read more "Write a program in 'C' to calculate house rent allowance (hra), Dearness allowance (da) and the gross & Net salary. (Using if.........else statement.)"

Write a program in 'C' to test whether the given integer is even or odd and to print message accordingly.(Using if...........else statement.)

 Toshiba Satellite L505-GS5037 TruBrite 15.6-Inch Laptop (Black)
HP 2009M 20-Inch HD LCD Monitor
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int n;
printf("Enter any integer\n");
scanf("%d", &n);
if(n % 2 = = 0)
printf("The integer %d is even \n", n);
else
printf("The integer %d is odd \n", n);
return(0);
}


Samsung 2233SW 21.5-Inch Full HD Widescreen LCD Monitor
For eg :-

Output :-
Enter any integer
25
The integer 25 is odd

Output :-
Enter any integer
10
The integer 10 is even

ViewSonic VA2223wm 22-Inch 16:9 1080p LCD Monitor
read more "Write a program in 'C' to test whether the given integer is even or odd and to print message accordingly.(Using if...........else statement.)"

Write a program in 'C' to input an integer and to print whether it is positive, negative or zero.(Using if.............else statement)



#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int a;
clrscr( );
printf("Enter any integer\n");
scanf("%d", &a);
if (a > 0)
printf("The integer is positive\n");
else
if (a < 0) printf("The integer is negative\n");
else
printf("The integer is Zero\n");
return(0);
}

For eg :-

Output :-
Enter any integer
25
The integer is positive


Output :-
Enter any integer
-32
The integer is negative

Output :-
Enter any integer
0
The integer is Zero
read more "Write a program in 'C' to input an integer and to print whether it is positive, negative or zero.(Using if.............else statement)"

Sunday, January 3, 2010

Write a program in 'C' to enter any two numbers and find and print their minimum.(Using if.....else statement)



#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float a, b, min;
printf("Enter any two numbers\n");
scanf("%f %f", &a, &b);
if(a < min =" a;" min =" b;">

For eg :-

Output :-
Enter any two numbers
20.5 32.3
The minimum number is 20.500000
read more "Write a program in 'C' to enter any two numbers and find and print their minimum.(Using if.....else statement)"

Write a program in 'C' to enter any two numbers and find and print their maximum.(Using if.....else statement)



#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float a, b, max;
printf("Enter any two numbers\n");
scanf("%f %f", &a, &b);
if(a > b)
max = a;
else
max = b;
printf("The maximum number is %f\n", max);
return(0);
}

For eg :-

Output :-
Enter any two numbers
20.5 32.3
The maximum number is 32.300000
read more "Write a program in 'C' to enter any two numbers and find and print their maximum.(Using if.....else statement)"

if ........................ else statement

The syntax is

if (expression)
statement set 1;
else
statement set 2;

The bracket contains a condition, the condition is tested, if the condition is true then statement set 1 gets executed and statement set 2 ignored.
If the condition is false then statement set 2 gets executed and statement set 1 is ignored.

Note that :-
1) Statement set 1 is called as the "if block" and statement set 2 is called as "else block"
2) else should be written below if.
3) Both the statement sets 1 and 2 should be written little towards the right side. This is the formatting convention.
4) Both the statement set should be enclosed in a pair of braces { } but braces are not required in case of single statement.
5) Both the statement sets must end with semicolon ;
read more "if ........................ else statement"

Control Statement in 'C'

A computer program in usually executed in the same order in which the statement appear in the program but in some programs it is necessary to conduct a logical test and then the order of execution should be decided. This is called as conditional execution and it is done with the helps of control statement.

We have the following control statement.
1) if...........................else,
2) switch.........................case,
3) while,
4) do...................while,
5) for,
read more "Control Statement in 'C'"

About This Blog

Lorem Ipsum

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP