Showing posts with label nested if-else. Show all posts
Showing posts with label nested if-else. Show all posts

Thursday, 2 August 2012

Conditional statement023


A library charges a fine for every book returned late.
           For first 5 days the fine is 50 paisa,
           For 6-10 days, fine is one rupee
           and above 10 days, fine is 5 rupees.
If you return the book after 30 days your membership will be cancelled.
Write a program to accept the number of days the member is late to return the book and display the fine or the appropriate message.


#include <stdio.h>
#include <conio.h>
void main ( )
{
        int          day;
        clrscr ( );
        
        printf ("\n Enter the number of days the member is late to return the book..:"); scanf ("%d",&day);
        
        if( day < 0 )
        {                     
                   printf ("\n Invalid input.");
        }              
        else if ( day == 0 )
        {                        
                    printf ("\n No fine required.");
        }                                        
        else if ( day >= 1 && day <= 5 )
        {                                              
                    printf ("\n You have to pay fine of 50 paise.");
        }                              
        else if ( day <= 10 )
        {                                   
                    printf("\n You have to pay fine of one rupee.");
        }                                
        else                            
        {                                 
                    printf("\n You have to pay fine of 5 rupees.");
        }                                   
        if ( day >= 30 )
        {                                         
                    printf ("\n YOUR MEMBERSHIP IS CANCELLED.");
        }                                             
        getch ( );
}


Wednesday, 1 August 2012

Conditional statement021


Write a C program to calculate and display the monthly income of a salesperson corresponding to the value of monthly sales input in the scanf ( ) function, let us consider the following commission schedule: (Note: use if-else statement)
Monthly Sales Income: -
         Greater than or equal to Rs.50,000 375 plus 16% of sales 
         Less than Rs. 50,000 but Greater than or equal to Rs. 40,000 350 plus 14% of sales
         Less than Rs. 40,000 but Greater than or equal to Rs. 30,000 325 plus 12% of sales
         Less than Rs. 30,000 but Greater than or equal to Rs. 20,000 300 plus 9% of sales
         Less than Rs. 20,000 but Greater than or equal to Rs. 10,000 250 plus 5% of sales
         Less than Rs. 10,000 200 plus 3% of sales



#include <stdio.h>
#include <conio.h>
void main ( )
{
        float         sales, commission;
        clrscr ( );
                     
        printf ("\n Enter the monthly sales..:"); scanf ("%f",&sales);
               
        if ( sales >= 50000 )

        {                               
                     commission = 375 + ( sales * 16 / 100 );
        }                                   
        else if ( sales >= 40000 )
        {                                 
                     commission = 350 + ( sales * 14 / 100 );
        }                                  
        else if ( sales >= 30000 )
        {                            
                     commission = 325 + ( sales * 12 / 100 );
        }                                   
        else if ( sales >= 20000 )
        {                                         
                     commission = 300 + ( sales * 9 / 100 );
        }                           
        else if ( sales >= 10000 )
        {                            
                     commission + 250 + ( sales * 5 / 100 );
        }                                 
        else                        
        {                                   
                     commission=200+(sales*3/100);
        }                         
        printf ("\n Monthly income of the salesperson is Rs.%.2f",commission);
        getch ( );
}


Click here to contact us


Monday, 30 July 2012

Conditional statement019


Write a ‘C’ program to calculate the electricity bill using if..elseif, as per the following details


Given the number of units consumed, unit charges are as follows:
i)    For first 50 units Rs. 0.50/unit
ii)   For next 100 units Rs. 0.75/unit
iii)  For next 100 units Rs. 1.20/unit
iv)  For unit above 250 Rs. 1.50/unit


Add fuel surcharge 20% and Govt. Tax 10% on bill to calculate the total bill.



#include<stdio.h>
#include<conio.h>
void main ( )
{
        int         unit;
        float      cost, fuel, tax;
     
        clrscr ( );
        printf ("\n Enter the number of unit consumed..:"); scanf ("%d",&unit);
     
        if (unit <= 50)
        {                  
                 cost = unit *.50;
        }              
        else if (unit <= 150)
        {                          
                 unit = unit - 50;
                 cost = 50 *.50 + unit * .75;
        }                          
        else if (unit <= 250)
        {                                  
                 unit = unit - 150;
                 cost = 50 * .50 + 100 *.75 + unit * 1.20;
        }                                  
        else            
        {                      
                 unit = unit - 250;
                 cost = 50 * .50 + 100 * .75 + 100 * 1.20 + unit * 1.50;
        }

        fuel = cost * 20 / 100;
        tax = cost * 10 / 100;
         
        printf ("\n Gross amount = %.2f",cost);
        printf ("\n Fuel charges = %.2f",fuel);
        printf ("\n Tax = %.2f",tax);
        printf ("\n_________________________\n");
        printf ("\n Gross amount = %.2f",cost + fuel + tax);
getch( );
}

Click here to contact us.

Thursday, 19 July 2012

Conditional statement014

As per Gregorian calender, 01/01/1900 was Monday. If any year is input through keyboard write a program  to find out what is the day on First January of this year. 



#include <stdio.h>
#include <conio.h>

void main( )
{
        int           a, b, c, d, e;
        clrscr ( );
        
        printf ("\n Enter year............:"); scanf ("%d",&a);

        b = ( a - 1900);
        c = b/4;
        d = ( b + c ) % 7;
     
        if ( a % 100 == 0 )
        {      
                   if ( a % 400 == 0 )
                              e = d -1;
                   else  
                              e = d;
        }                                    
        else                          
        {                              
                   if ( a % 4 == 0 )
                              e = d -1;
                   else                                          
                              e = d;
        }                                          
        if ( e == 0 )
                    printf ("\n MONDAY");
        if ( e == 1 )
                    printf ("\n TUESDAY");
        if ( e == 2 )
                    printf ("\n WEDNESDAY");
        if ( e == 3 )
                    printf ("\n THURSDAY");
        if ( e == 4 )
                    printf ("\n FRIDAY");
        if ( e == 5 )
                    printf ("\n SATURDAY");
        if ( e == 6 )
                    printf ("\n SUNDAY");
        if ( e == -1 )
                    printf ("\n MONDAY");
        getch ( );
}

To contact us

Sunday, 15 July 2012

Conditional statement010

Determine the high value and same value of three input numbers.


#include <stdio.h>

#include <conio.h>

void main( )
{
int p = 0, q = 0, r = 0; 
clrscr ( );
printf ("\n Enter first number.....:"); scanf ("%d",&p);
printf ("\n Enter second number.....:"); scanf ("%d",&q);
printf ("\n Enter second number.....:"); scanf ("%d",&r);
if ( p == q && q == r)
printf ("\n Three numbers are same");
else               
{                
if ( P > q)
{         
if ( p > r)
printf ("\n First number is high value ");
else             
printf ("\n Third number is high value");
}
else
{        
if ( q > r )
printf ("\n Second number is high value");
else    
printf ("\n Third number is high value");
}
}
getch ( );

Friday, 13 July 2012

Conditional statement008

Determine the high value and same value of two input numbers.



#include <stdio.h>
#include <conio.h>

void main( )
{
int m = 0, n = 0;
clrscr ( );

printf ("\n Enter first number..........:"); scanf ("%d",&m);
printf ("\n Enter second number.....:"); scanf ("%d",&n);

if ( m > n )
printf ("\n The first number is high value....: %d", m);
else
if ( n > m)
printf ("\n The second number is high value.....: %d",n);
else
printf ("\n Both the number are same");
getch ( );
}

 To contact us

Thursday, 12 July 2012

Conditional statement007

Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not. 




#include <stdio.h>
#include <conio.h>

void main( )
{
int           yr;
clrscr ( );

printf ("\n Enter a year.....:"); scanf ("%d",&yr);

if ( yr % 100 == 0 )
{
if ( yr % 400 == 0)
printf ("\n LEAP YEAR");
else
printf ("\n NOT LEAP YEAR");
}
else
{
if ( yr % 4 == 0 )
printf ("\n LEAP YEAR");
else
printf ("\n NOT LEAP YEAR");
}
getch ( );
}

To contact us
Related Posts Plugin for WordPress, Blogger...