Showing posts with label If. Show all posts
Showing posts with label If. Show all posts

Saturday, 28 July 2012

Conditional statement018


A certain grade of steel is graded according to the following condition:
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 conditions (1) and (2) are met
§  Grade is 8 if conditions (2) and (3) are met
§  Grade is 7 if conditions (1) and (3) are met
§  Grade is 6 if only one conditions 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.

#include <stdio.h>
#include <conio.h>
void main ( )
{       
        float        hard, c, tens;
        clrscr ( );
                        
        printf ("\n\n\n\t\t Enter the hardness of steel .......:"); scanf ("%f", &hard);
        printf ("\n\t\t Enter the carbon content of steel ...:"); scanf ("%f", &c);
        printf ("\n\t\t Enter the tensile strength of steel ..:"); scanf ("%f", &tens);
        
        if ( hard > 50 && c < 0.7 && tens > 5600)
        {                          
                    printf ("\n\n\n\n\t\t\t GRADE 10");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }           
        if ( hard > 50 && c < 0.7 && tens < 5600)
        {                                        
                    printf ("\n\n\n\n\t\t\t GRADE 9");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }                            
        if ( hard <= 50 && c < 0.7 && tens > 5600)
        {                          
                    printf ("\n\n\n\n\t\t\t GRADE 8");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }                                    
        if ( hard > 50 && c >= 0.7 && tens > 5600)
        {                           
                    printf ("\n\n\n\n\t\t GRADE 7");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }                                 
        if ( hard > 50 || c < 0.7 || tens > 5600)
        {                                
                    printf ("\n\n\n\n\t\t GRADE 6");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }
        printf ("\n\n\n\n\t\t GRADE 5");
        printf ("\n\n\n\n Press any key to exit");
        getch( );
}

Friday, 27 July 2012

Conditional statement017


An Insurance company follows following rules to calculate premium.
1) If a person's health is excellent and the person is between 25 and 35 years of age and lives in a 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 between 25 and 35 years of age and lives in a village and is a male 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.

#include <stdio.h>
#include <conio.h>
void main ( )
{     
        int         age, pr, pol;
        char      hel, resi, sex;
        clrscr ( );
            
        printf ("\n\n\n\n\t\t\t Enter the values of \n\n");
        printf ("\n\n\n\t\t Sex ( M/F ).......................:"); scanf ("%c", &sex);
        fflush(stdin);                        /* To clear input buffer */
        printf ("\n\n\t\t Health excellent/poor ( E/P ).......:"); scanf ("%c", &hel);
        fflush(stdin);
        printf ("\n\n\t\t Resident of city/village ( C/V )....:"); scanf ("%c", &resi);
        fflush(stdin);
        printf ("\n\n\t\t Age.................................:"); scanf ("%d", &age);
                  
        if (( sex == 'M' || sex == 'm' ) && ( hel == 'E' || hel == 'e' )
                 && ( resi == 'C' || resi == 'c' ) && age >= 25 && age <= 35)
              
 /* These conditions will work even if lowercase letters are entered */
        {       
                   printf ("\n\n\n\n\t\t The person is insured");
                   printf ("\n\n\t\t Premium = Rs. 4 per thousand");
                   printf ("\n\n\t\t Maximum insurance amount = Rs. 2 lakhs");
                   printf ("\n\n\n\n\n Press any key to exit");
                   getch ( );
                   exit ( );                   /* Terminates Program execution */
        }                         
        if (( sex == 'F' || sex == 'f' ) && ( hel == 'E' || hel == 'e' )
                 && ( resi == 'C' || resi == 'c' ) && age >= 25 && age <= 35)
                              

 /* These conditions will work even if lowercase letters are entered */
        {                          
                   printf ("\n\n\n\n\t\t The person is insured");
                   printf ("\n\n\t\t Premium = Rs. 3 per thousand");
                   printf ("\n\n\t\t Maximum insurance amount = Rs. 1 lakhs");
                   printf("\n\n\n\n\n Press any key to exit");
                   getch ( );
                   exit ( );                  /* Terminates Program execution */
        }             
        if (( sex == 'M' || sex == 'm' ) && ( hel == 'P' || hel == 'p' )
                  && ( resi == 'V' || resi == 'v' ) && age >= 25 && age <= 35)
                                     

/* These conditions will work even if lowercase letters are entered */
        {                            
                   printf ("\n\n\n\n\t\t The person is insured");
                   printf ("\n\n\t\t Premium = Rs. 6 per thousand");
                   printf ("\n\n\t\t Maximum insurance amount = Rs. 10,000");
                   printf ("\n\n\n\n\n Press any key to exit");
                   getch ( );
                   exit( );                   /* Terminates Program execution */
        }
        printf ("\n\n\n\n\t\t The person is not insured");
        printf("\n\n\n\n\n Press any key to exit");
        getch ( );
}




Thursday, 26 July 2012

Conditional statement016


Any character is entered through the keyboard; write a program to determine whether the character entered is a capital letter, a small letter, a digit or a special symbol.
The following table shows the range of ascii values for various characters.

Characters
Ascii Values
A – Z

a – z

0 – 9

Special symbols
65 – 90

97 – 122

48 – 57

0 – 47, 58 – 64, 91 – 96, 123 – 127


#include <stdio.h>
#include <conio.h>
void main ( )
{      
        char       ch;
        clrscr ( );
         
        printf ("\n\n\n\t\t Enter a character from the keyboard .....: "); scanf ("%c",&ch);
              
        if ( ch >= 65 && ch <= 90 )
        {                    
                    printf ("\n\n\n\t\t The character is an uppercase letter.");
        }                     
        if ( ch >= 97 && ch <= 122 )
        {                    
                    printf ("\n\n\n\t\t The character is a lowercase letter.");
        }                         
        if ( ch >= 48 && ch <= 57 )
        {                              
                    printf ("\n\n\n\t\t The character is a digit letter.");
        }                                          
        if (( ch >= 0 && ch < 48 ) || ( ch > 57 && ch < 65 ) || ( ch > 90 && ch < 97 ) || ch > 122)
        {                           
                    printf ("\n\n\n\t\t The character is a special symbol.");
        }
        getch ( );
} 


Monday, 16 July 2012

Conditional statement011

The marks obtained by the student in five different subjects are input through the keyboard. The student gets a division as per the following rules: -
Percentage above or equal to sixty is first division.
Percentage between fifty to fifty nine is second division.
Percentage between forty to forty nine is third division.
Percentage less than forty is fail.

#include <stdio.h>
#include <conio.h>
void main ( )
{     
        int        m1, m2, m3, m4, m5, per;
        clrscr ( );
              
        printf ("\n\n\n\t Enter marks in first subject......:"); scanf ("%d",&m1);
        printf ("\n\n\t Enter marks in second subject.....:"); scanf ("%d",&m2);
        printf ("\n\n\t Enter marks in third subject......:"); scanf ("%d",&m3);
        printf ("\n\n\t Enter marks in fourth subject.....:"); scanf ("%d",&m4);
        printf ("\n\n\t Enter marks in fifth subject......:"); scanf ("%d",&m5);
              
        per = (m1 + m2 + m3 + m4 + m5)/5;
           
        if ( per >= 60)
        {                     
                   printf ("\n\n\n\t\t FIRST DIVISION");
        }                      
        if ( ( per >= 50 ) && ( per < 60 ) )
        {                              
                   printf ("\n\n\n\n\t\t SECOND DIVISION");
        }                           
        if ( ( per >= 40 ) && ( per < 50 ) )
        {         
                   printf ("\n\n\n\n\t\t THIRD DIVISION");
        }                    
        if ( per < 40 )
        {                     
                   printf ("\n\n\n\n\t\t FAIL");
        }
        getch ( );
}
Click here to contact us 

Tuesday, 10 July 2012

Conditional statement005

If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred. 


#include <stdio.h>
#include <conio.h>
void main ( )
{     
        float         cp, sp, p, l;
        clrscr ( );
           
        printf ("\n\n\n\t\t Enter cost price.........:"); scanf ("%f",&cp);
        printf ("\n\n\t\t Enter selling price......:"); scanf ("%f",&sp);
                
        p = sp - cp;
        l = cp - sp;
                      
        if ( p > 0 )
        {              
                 printf ("\n\n\n\t\t The seller has made a profit of a profit of ...: Rs.%.2f", p);
        }      
        if ( l > 0 )
        {              
                 printf ("\n\n\n\t\t The seller is in loss by .......: Rs.%.2f", l);
        }              
        if ( p == 0)
        {                  
                 printf ("\n\n\n\t\t There is no loss and no profit.");
        }
        getch ( );
}
Click here to contact us 

Sunday, 8 July 2012

Conditional statement003

The current year and the year in which the employee joined the organization are entered through the keyboard. If the number of years for which the employee served the organization is greeter than three then a bonus of Rs. 2500/- is given to the employee. If the years of service is not greeter than three, then the program should not do any thing. 


#include <stdio.h>
#include <conio.h>
void main ( )
{    
        int         bonus, cy, yoj, yr_of_ser;
        clrscr ( );
                        
        printf ("\n\n\n\t\t Enter current year........:"); scanf ("%d",&cy);
        printf ("\n\n\t\t Enter year of joining.....:"); scanf ("%d",&yoj);
                  
        yr_of_ser = cy - yoj;
        if ( yr_of_ser > 3 )
        {                           
                  bonus = 2500;
                  printf ("\n\n\n\t\t Bonus.......: Rs.%d",bonus);
        }
        getch ( );
}

Click here to contact us

Saturday, 7 July 2012

Conditional statement002

Input :- Quantity and price per item.
Output : - Calculate the total expenses where as a discount of  ten percent is offered if the quantity purchased is more than thousand. 

#include <stdio.h>
#include <conio.h>
void main ( )
{      
        int        qty, dis = 0;
        float     rate, tot;
        clrscr ( );
                       
        printf ("\n\n\n\t\t Enter quantity.....:"); scanf ("%d",&qty);
        printf ("\n\n\t\t Enter rate.....:"); scanf ("%f",&rate);
                  
        if ( qty > 1000 )
        {                   
                  dis = 10;
        }
        tot = (qty * rate) - (qty * rate * dis / 100);
                            
        printf ("\n\n\n\t\t Total expenses.......: %.2f",tot);
        getch ( );
}

Friday, 6 July 2012

Conditional statement001

Demonstration of if statement


#include <stdio.h>
#include <conio.h>
void main ( )
{      
        int       num;
        clrscr ( );
                 
        printf ("\n\n\n\t\t Enter a number less than Ten.....:"); scanf ("%d",&num);
            
        if ( num <= 10 )
        {                          
                    printf ("\n\n\n\t\t What an obedient student you are.");
        }                       
        getch ( );
}

Click here to contact us
Related Posts Plugin for WordPress, Blogger...