Thursday, October 8, 2009

Determine Grade of steel

/*A certain grade of steel is graded according to the following conditions:
*1)Hardness must be greater than 50
*2)Carbon content must be less than 0.7
*3)Tensile strength must be greater than 5600
*
*The grades are as follows:
*
*Grade is 10 if all three conditions are met
*Grade is 9 if condition 1 & 2 are met
*Grade is 8 if condition 2 & 3 are met
*Grade is 7 if condition 1 & 3 are met
*Grade is 6 if only one condition is met
*Grade is 5 if none of the conditions are met
*
*Write a program which will require the user to give values of hardness,carbon content and tensile

*strength of the steel under consideration and output the grade of the steel*/

# Solution code :

==========

#include <stdio.h>
int main(void)
{
int hard,ts; // hard = hardness ; ts = tensile strength
float cc; //cc -- Carbon content

printf("\nEnter hardness of steel: ");
scanf("%d",&hard);
printf("\nEnter Carbon content of steel : ");
scanf("%f",&cc);
printf("\nEnter Tensile strenght of steel : ");
scanf("%d",&ts);

if ( (hard > 50) && (cc < 0.7) && (ts > 5600))
printf("Steel is of 10th Grade");
else if ( (hard > 50) && (cc < 0.7))
printf("Steel is of 9th Grade");
else if ( (cc < 0.7) && (ts > 5600 ))
printf("Steel is of 8th Grade");
else if (( hard > 50) && (ts > 5600 ))
printf("Steel is of 7th Grade");
else if ( (hard > 50) || (cc < 0.7) || (ts > 5600))
printf("Steel is of 6th Grade");
else
printf("Steel is of 5th Grade");
return 0;
}

Determine if eligible for premium & Policy

/*An Insurance company follows rules to calculate premium

1)If a person's health is excellent and the person is btw. 25 & 35 years of age and lives in city and is a male then the premium is Rs 4 per thousand and his policy amount cannot exceed Rs 2 lakhs.

2)If a person satisfies all the above conditions except that the sex is female then the premium is Rs 3 per thousand and her policy amount cannot exceed Rs 1 lakh.

3)If a person's health is poor and the person is btw. 25-35 and lives in village and is male ,the premium is Rs 6 per thousand and his policy cannot exceed Rs 10,000

4)In all other cases the person is not insured

Write a program to output whether the person should be insured or not ,his/her premium rate and maximum amount for which he/she can be insured.*/

#Solution
=======

#include <stdio.h>
int main(void)
{
int age,pre,policy_amt;
char sex,live,health;
printf("Enter your age : ");
scanf("%d",&age);
if ( age <= 35 && age >= 25)
{
printf("\nPl.enter your health status ( h/p- h(healthy),p(poor health): ");
scanf(" %c",&health);
printf("\nDo you live in city/Village(c=city)(v=village): ");
scanf(" %c",&live);
printf("\nAre you Male/Female(m=male,f=female : ");
scanf(" %c",&sex);

if ( health == 'h')
{
if ( sex == 'm'&& live == 'c')
printf("\nYou are opt for Rs 4/- Preminum over 1000 Rs & Policy not greater than 2 lakh");
else if ( sex == 'f'&& live == 'c')
printf("\nYou are opt for Rs 3/- Preminum over 1000 Rs & Policy not greater than 1 lakh");
}
else if ( live == 'v' && sex == 'm')
printf("\nYou are opt for Rs 6/- Preminum over 1000 Rs & Policy not greater than 10,000 Rs/-");

if ( sex == 'm' && live == 'c' && health == 'p')
printf("\nSorry no premium or Policy for you");
if ( sex == 'm' && live == 'v' && health == 'h')
printf("\nSorry no premium or Policy for you");
if ( sex == 'f' && live == 'v' && ((health == 'h') || (health == 'p' )))
printf("\nSorry no premium or Policy for you");
if ( sex == 'f' && live == 'c' && health == 'p')
printf("\nSorry no premium or Policy for you");
}

else
printf("\nYou are not eligible for Premium or Policy");

return 0;
}






Determine character input if its Capital,small,decimal or special character

/*Any character is entered through the keyboard ,write a program to determine whether the character entered is a capital letter,a small case letter,a digit or a special symbol

Following is Range of Ascii values for various characters:-

Characters                                           Ascii Values

A-Z                                                        65-90

a-z                                                         97-122

0-9                                                         48-57

Special symbols                                   0-47,58-64,91-96,123-127 */


#1 Solution ( With Value of ASCII characters as integer as input) :-

========================================

#include <stdio.h>
int main(void)
{
int i;
printf("Enter a character to determine its type : ");
scanf("%d",&i);


if ( (i <= 90) && (i >= 65))
printf("\nIts %c whose value is %d ,which belongs to A-Z character type",i,i);
else if ( i <= 122 && i >= 97 )
printf("\nIts %c whose value is %d,which belongs to a-z character type",i,i);
else if ( i <= 57 && i >= 48 )
printf("\nIts %c whose value is %d,which belongs to 0-9 character type",i,i);
else if (( i <= 47 && i >= 0) || ( i <= 64 && i >= 58) || ( i >= 91 && i <= 96) || ( i <= 127 && i >= 123))
printf("\nIts %c whose value is %d,which belongs to specific symbols",i,i);
return 0;
}
 

#2 Solution ( With ASCII Characters as input ) :-

==============================

#include <stdio.h>
int main(void)
{
char i;

printf("Enter a character to determine its type :");
scanf("%c",&i);


if (( i <= 'Z') && (i >= 'A'))
printf("\nIts %c whose value is %d ,which belongs to A-Z character type",i,i);
else if (( i >= 'a') && (i <= 'z' ))
printf("\nIts %c whose value is %d,which belongs to a-z character type",i,i);
else if ( (i >= '0') && (i <= '9'))
printf("\nIts %c whose value is %d,which belongs to 0-9 character type",i,i);
else
printf("\nIts %c whose value is %d,which belongs to *special symbols*",i,i);
return 0;
}