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

Thursday, 2 August 2012

Conditional statement022

Input the ASCII value and print its character value.


#include <stdio.h>
#include <conio.h>
void main ( )
{
        int       d;
        clrscr ( );
        
        printf ("\n Enter an ASCII value (0-255):"); scanf ("%d",&d);
        
        if ( d < 0 || d > 255 )
        {                    
                       printf("\n Invalid input.");
        }                              
        else                            
        {                                          
                       printf("\n Character value of %d is '%c'.",d,d);
        }
        getch ( );
}


Click here to contact us

Tuesday, 31 July 2012

Conditional statement020


write a program to compute the roots of a quadratic equation A*X^2 + B*X + C = 0. Allow the possibility that (B^2 - 4*A*C) <= 0.



#include <stdio.h>
#include <conio.h>
#include <math.h>
void main( )
{
        int          A,B,C;
        float       r1,r2,d;
        clrscr( );
        
        printf ("\n Enter the value of the coefficient A:"); scanf ("%d",&A);
        printf ("\n Enter the value of the coefficient B:");  scanf ("%d",&B);
        printf ("\n Enter the value of the coefficient C:"); scanf ("%d",&C);
        printf ("\n The equation is %dX^2+%dX+%d=0",A,B,C);
          
        d=B*B-4*A*C;

        if(d<0)
        {                          
                     printf ("\n Roots of the equation are imaginary.");
        }                             
        else                    
        {                              
                     r1 = ( -B + sqrt (d) ) / ( 2 * A );
                     r2 = ( -B - sqrt (d) ) / ( 2 * A );
                     printf ("\n Roots of the equation are %f and %f",r1,r2);
        }                      
        getch( );
}


Thursday, 26 July 2012

Conditional statement015

A five digit number is entered through the keyboard. Write a program to obtain the reversed number and to determine whether the original and reversed numbers are equal or not. 



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

void main( )
{
        int    n, a, b, num;
        long    revnum = 0;            /* Initialised otherwise it will contain garbage value. */
                                                /* Declared as long since after reversing, it may not be in the int range */
                                           
        clrscr ( );
        printf ("\n Enter a five digit number (less than 32767) ............:"); scanf ("%d",&n);
                                                       
        num = n;                              /* Entered number stored for comparison later */
        a = n % 10;                         /* Last digit */
        n = n / 10;                           /* Remaining digits */
        revnum = revnum + a * 10000L;   /* revnum updeted with value of extracted digit */
                                                                   
        a = n % 10;                        /* Fourth digit */
        n = n / 10;                           /* Remaining digits */
        revnum = revnum + a * 1000;
                                           
        a = n % 10;                        /* Third digit */
        n = n / 10;                          /* Remaining digits */
        revnum = revnum + a * 100;
                                                                     
        a = n % 10;                        /* Second digit */
        n = n / 10;                          /* Remaining digits */
        revnum = revnum + a * 10;
                                                                         
        a = n % 10;                      /* First digit */
                 
        revnum = revnum + a;
                 
        if (revnum == num)
                          printf ("\n Given number and its reversed number are equal.");
        else                  
                          printf ("\n Given number and its reversed number are not equal.");
        getch ( );
}

To contact us

Wednesday, 18 July 2012

Conditional statement013

Any year is entered through the keyboard, write a program to determine whether the year is leap year or not.   Use the logical operators && and ||. 

#include <stdio.h>

#include <conio.h>

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

        if ( y % 400 == 0 || y % 100 != 0 && y % 4 == 0 )
                      printf ("\n LEAP YEAR");
        else      
                      printf ("\n NOT LEAP YEAR");
        getch ( );
}

To contact us

Tuesday, 17 July 2012

Conditional statement012

A company insure its drivers in the following cases: -
If the driver is married.
If the driver is unmarried, male and above thirty years of age.
If the driver is unmarried, female and above twenty five years of age.
In all other cases the driver is not insured. If the marital status, sex, and age of driver are inputs through the keyboard, write a program to determine whether the driver is to be insured or not. 



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

void main( )
{
        char       sex, ms;
        int       age;
        clrscr ( );

        printf ("\n Enter age of driver.......................:"); scanf ("%d",&age);
        fflush (stdin); /* For cliearing input buffer */
        printf ("\n Enter sex of driver.......................:"); scanf ("%c",&sex);
        fflush (stdin); /* For cliearing input buffer */
        printf ("\n Enter marital status of driver.........:"); scanf ("%c",&ms);
     
        if((ms == 'M')||(ms == 'U' && sex == 'M' && age > 30)||(ms == 'U' && sex == 'F' && age > 25 ))
                             printf("\n DRIVER IS INSURED");
        else            
                             printf("\n DRIVER IS NOT INSURED");
        getch ( );
}

To contact us

Saturday, 14 July 2012

Conditional stetment009

Input three numbers, write a program to prove that this three numbers are Pythagorean triples.
N.B. a2 = b2 +c2




#include <stdio.h>
#include <conio.h>
void main ( )
{
        int            a,b,c;
        clrscr ( );
           
        printf ("\n Enter three numbers..:");  scanf ("%d%d%d",&a,&b,&c);
                   
        if ( a * a == b * b + c * c )
        {                             
                        printf ("\n Three numbers are pythagorean tripples.");
        }                              
        else if ( b * b == a * a + c *c )
        {                                        
                        printf ("\n Three numbers are pythagorean tripples.");
        }                                      
        else if ( c * c == b * b + a * a )
        {                                               
                        printf ("\n Three numbers are pythagorean tripples.");
        }                                    
        else                                 
        {                                
                        printf ("\n Three numbers are not pythagorean tripples.");
        }
        getch();
}

Wednesday, 11 July 2012

Conditional statement006

Any integer is input through the keyboard. Write a program to find out whether it is an odd number or even number. 



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

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

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

if ( n % 2 == 0 )
printf ("\n The number is even");
else
printf ("\n The number is odd");
getch ( );
}


To contact us

Monday, 9 July 2012

Conditional statement004

If the basic salary less than Rupees One thousand five hundred then house rent allowances is ten percent of basic salary and dearness allowances is ninety percent of basic salary.  
If the basic salary is either equal to or above Rupees One thousand five hundred then house rent allowances is five hundred rupees and dearness allowances is ninety eight percent of basic salary.
If the employee's salary is input through the keyboard write a program to find his gross salary. 



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

void main( )
{
float  bs, gs, da, hra;
  clrscr ( );

  printf ("\n Enter basic salary.....:"); scanf ("%f",&bs);

  if ( bs < 1500)
{                  
  hra = bs * 10/100;
  da = bs * 90/100;
  }                  
  else                
  {                        
  hra = 500;
  da = bs * 98/100;
  }
  gs = bs + hra + da;
                                   
  printf ("\n Gross salary.......: Rs.%f", gs);
  getch ( );
}

www.crystalcomputercentre.org
Related Posts Plugin for WordPress, Blogger...