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 );
}

Plays a one-time guessing game with user.User enters a number which is compared with target

/*Plays a one-time guessing game with the user.The user enters a number,which is compared with TARGET.The computer issues a diagnostic message & then the correct result*/

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


#include <stdio.h>
#define TARGET 17
int test(int i,int target);
int main(void)

{
int i;
printf("Enter target number : ");
scanf("%d",&i);
test( i,TARGET);
return 0;
}

void test(int i,int target)
{
if ( i > target)
printf("\nTarget number is smaller than %d,try again",i);
else if ( i < target)
printf("\nTarget number is greater than %d,try again",i);
else if ( i == target )
printf("\nFinally you could make it");

}

Detect if number is odd or even by function call

/*With an if-else statement detect if input number is odd or even with a function call*/

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

#include <stdio.h>
int odd(int i);
int main(void)
{
int i;
printf("Enter a decimal integer : ");
scanf("%d",&i);

if (odd(i))
printf("\n%d is Odd number",i);
else
printf("\n%d is Even number",i);
return 0;
}

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

A decimal integer is input and added to constant while displaying the sum message is issued

/*A decimal integer is input,added to CONSTANT and the sum is displayed .If the sum is less than 20, a message is issued*/

Solution code:-
========

#include <stdio.h>
#define CONSTANT 7
int sum(int num,int constant);
int main(void)
{
int i,add;
printf("Enter a decimal integer : ");
scanf("%d",&i);

add = sum(i,CONSTANT);
if ( add < 20 )
printf("\nAmount %d is less than 20",add);


return 0;
}

int sum(int num,int constant)
{
return (num + constant);
}