Wednesday, April 15, 2009

Calculate gross salary

/*If his basic salary is less than Rs. 1500, then HRA = 10% of basic
salary and DA = 90% of basic salary. If his salary is either equal to
or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic
salary. If the employee's salary is input through the keyboard write
a program to find his gross salary.*/

Solution Code:-
=========


#include <stdio.h>
int main(void)
{
int bs;
float hra,da,gross;
printf("Enter Basic Salary : ");
scanf("%d",&bs);
if ( bs < 1500 )
{
hra = bs * 10 / 100;
da = bs * 90 /100;

}

else
{
hra = 500 ;
da = bs * 98 /100;
}

gross = hra + da + bs ;
printf("\n Your gross salary is %f",gross);
return 0;
}

Tuesday, April 14, 2009

Print a five digit number by adding one to each of its digits

/*If a five-digit number is input through the keyboard, write a
program to print a new number by adding one to each of its
digits. For example if the number that is input is 12391 then
the output should be displayed as 23402.*/


Solution Code :-
=========

#include <stdio.h>
int main(void)
{
int i,temp = 0;
printf("Enter a +ve 5 digit number :");
scanf("%d",&i);
if (( i <= 99999 ) && ( i > 9999 ))
{
printf(" %d",(i/10000) + 1);
printf(" %d",((( i/100) % 100)/10) + 1);
printf(" %d",(( i/100) % 10 ) + 1);
printf(" %d",((i % 100) / 10) + 1 );
printf(" %d",(i % 10) + 1);
}
else
printf("\n Pl.enter +ve five digit number");
return 0;
}

Monday, April 13, 2009

Calculate price of single item

*If the total selling price of 15 items and the total profit earned
on them is input through the keyboard, write a program to
find the cost price of one item.*/

/*Here the query maker ,I suppose seeks for groce price rate of one item ,as groce profit & groce selling price is sought out
sin => single item groce price ; procin => profit on single item ;con => conjugal price (profit + single item price)
*/

Solution Code :-
==========


#include <stdio.h>
int main(void)
{
int price,profit,sin,prosin,con;
printf("Enter price of 15 items : ");
scanf("%d",&price);
printf("\nEnter profit made on 15 items : ");
scanf("%d",&profit);
sin = price / 15 ;
prosin = (profit / 15) - sin;
con = sin + prosin ;
printf("\nSingle item cost is %d",sin);
printf("\nSingle item profit is %d",prosin);
printf("\nSingle item cost price is %d",con);
return 0;
}

Sunday, April 12, 2009

Find total number of currency notes of each 10,50,100 denominations

/*A cashier has currency notes of denominations 10, 50 and
100. If the amount to be withdrawn is input through the
keyboard in hundreds, find the total number of currency notes
of each denomination the cashier will have to give to the
withdrawer.*/

Solution Code:-
=========

#include <stdio.h>
int main(void)
{
int amt;
printf("Enter the amount to withdraw : ");
scanf("%d",&amt);
printf("\nNotes of 100 required are %d", amt/100);
printf("\nWhile Notes of 50 required are %d", ((amt % 100)/50));
printf("\nAnd notes of 10 required are %d",((amt % 100)% 50)/10);
return 0;
}

Percentage of Literate & Illiterate along with men & women in town

/*In a town, the percentage of men is 52. The percentage of
total literacy is 48. If total percentage of literate men is 35 of
the total population, write a program to find the total number
of illiterate men and women if the population of the town is
80,000*/

Solution Code:-
===========
/*popmen = population of men,popwo = population of women ,literate women = ilwo,ilmen = ill-literate men,limen = literate men,liwo = literate women,li= literate men*/

#include <stdio.h>
int main(void)
{
int popmen,popwo,ilmen,ilwo,li,limen,liwo,total;
popmen = (80000 * 52)/100;
printf("\nTotal population of Men in town is %d out of 80000",popmen);
popwo = (80000 - popmen);
printf("\nTotal population of women in town is %d out of 80000",popwo);
li = ( 80000 * 48)/100;
printf("\nTotal literate population in town is %d",li);
limen = ( popmen * 35 )/100;
printf("\nTotal amount of literate Men are %d",limen);
ilmen = popmen - limen;
printf("\nTotal amount of Ill-literate Men are %d",ilmen);
liwo = li - limen ;
printf("\nTotal amount of Literate women is %d",liwo);
ilwo = popwo - liwo ;
printf("\n Total amount of Ill-literate women is %d",ilwo);

return 0;
}

Saturday, April 11, 2009

Calculate percentage of 5 subjects & display Divison resp.

/*The marks obtained by a student in 5 different subjects are input through keyboard.The student gets a division as per the following rules:

Percentage above or equal to 60 - First division
Per btw 50 and 59 - Second div
per btw 40 and 49-Third div
per less than 40 - Fail */

Solution Code:
=========

#include <stdio.h>
int main(void)
{
int m1,m2,m3,m4,m5,sum,per;
printf("Enter marks for Math : ");
scanf("%d",&m1);
printf("\nEnter marks for Chemistry : ");
scanf("%d",&m2);
printf("\nEnter marks for Biology : ");
scanf("%d",&m3);
printf("\nEnter marks for Physics : ");
scanf("%d",&m4);
printf("\nEnter marks for English : ");
scanf("%d",&m5);
sum = (m1 + m2 + m3 + m4 + m5);
per = (sum * 100 / 500);
printf("\nYou got %d percentage",per);

if ( per >= 60 )
printf("\nFirst Division");

else if (( per <= 59) && ( per >= 50 ))
printf("\nSecond Divison");

else if (( per <= 49 ) && ( per >= 40 ))
printf("\nThird Divison");

else
printf("\nSorry you Failed");
return 0;
}

2nd Solution Code:-
===========

#include
int main(void)
{
int m1,m2,m3,m4,m5,sum,per;
printf("Enter marks for Math : ");
scanf("%d",&m1);
printf("\nEnter marks for Chemistry : ");
scanf("%d",&m2);
printf("\nEnter marks for Biology : ");
scanf("%d",&m3);
printf("\nEnter marks for Physics : ");
scanf("%d",&m4);
printf("\nEnter marks for English : ");
scanf("%d",&m5);
sum = (m1 + m2 + m3 + m4 + m5);
per = (sum * 100 / 500);
printf("\nYou got %d percentage",per);

if ( per >= 60 )
printf("\nFirst Division");
else
{
if ( per >= 50 )
printf("\nSecond Division");

else
{
if ( per >= 40 )
printf("\nThird Division");

else
printf("\nFail");
}
}
return 0;
}


Example of compound statement & nested if

/*Prompts for and accepts input of an integer.Integer is tested to see that it meets the stated criteria.If it doesn't an error message is issued.If all criteria are met,execution terminates silently*/

*Solution Code:-
===========

#include <stdio.h>
int mod(int i);
int main(void)
{
int i;
printf("Enter an Even number less than 20 : ");
scanf("%d",&i);

if ( i < 20)
{
if ( mod(i))
printf("Oops you entered Odd number %d",i);
else if ( i <= 0 )
printf("Oops you entered number less than or equal to 0 %d",i);
}
else
printf("You entered a number greater than 20");



return 0;
}

int mod(int i)
{
return ( i % 2 );
}