Tuesday, 31 July 2012

Basic C Programming013

Input two numbers and swapping these two numbers without using third variable.


#include <stdio.h>
#include <conio.h>
void main( )
{
       int        m,n;
       clrscr ( );
                          
       printf ("\n\n\t\t Enter first number...:"); scanf ("%d",&m);
       printf ("\n\n\t\t Enter second number..:"); scanf ("%d",&n);
                 
       m = m + n;
       n = m - n;
       m = m - n;
                           
       printf ("\n\n\n\t\t\t After Swapping \n\t\t_____________________________ \n");
       printf ("\n\t\t The first number is...: %d \n\n\t\t The second number is..: %d",m,n);
               
       getch ( );
}
Click here to contact us

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


Basic C Programming012


Write a program that calculates the net salary using entered basic salary.
Here, D.A. = 27%, H.R.A. = 10%, P.F. = 12% of basic salary; and M.A. = Rs.100, T.A.= Rs.1600 are fixed and I.T. = Rs.1000. Net salary = basic salary + (DA + HRA + MA + TA) - (PF + IT)
A program should print the output in the following format only:

ENTER BASIC SALARY (in Rs.) =40000
                  ALLOWANCES:
                  D.A. =10800.00
                  H.R.A. = 4000.00
                  M.A. = 100.00
                  T.A. = 1600.00
                  DEDUCTION:
                  P.F. = 4800.00
                  I.T. = 1000.00
-------------------------------------------
        NET SALARY = 50700.00


#include <stdio.h>
#include <conio.h>
void main ( )
{
        float      basic, da, hra, ma, ta, pf , it, net;
        clrscr( );
               
        printf ("\n\n\n\t\t ENTER BASIC SALARY (in Rs.)="); scanf("%f",&basic);
             
        da = ( basic * 27 ) / 100;
        hra = ( basic * 10 ) / 100;
        pf = ( basic * 12 ) / 100;
        ma = 100;
        ta = 1600;
        it = 1000;
        net = ( basic + da + hra + ma + ta) - ( pf + it );
                        
        printf ("\n\t\t\t ALLOWANCES: \n\t\t\t______________ \n");
        printf ("\n\t\t\t D.A.=%.2f",da);
        printf ("\n\t\t\t H.R.A.=%.2f",hra);
        printf ("\n\t\t\t M.A.=%.2f",ma);
        printf ("\n\t\t\t T.A.=%.2f",ta);
        printf ("\n\n\t\t\t DEDUCTION:\n");
       printf ("\n\t\t\t P.F.=%.2f",pf);
       printf ("\n\t\t\t I.T.=%.2f",it);
       printf ("\n\t\t\t___________________\n");
       printf("\n\t\t\t NET SALARY=%.2f",net);
          
       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.

Sunday, 29 July 2012

Basic C Programming011

Write a function that takes time in seconds as input and prints it in terms of hours, minutes and seconds.


#include<stdio.h>
#include<conio.h>
void main( )
{
        int         sec, hr = 0, min = 0;
     
        clrscr( );
        printf("\n Enter the time in seconds..:"); scanf("%d",&sec);
     
        min = sec / 60;
        sec = sec % 60;
        hr = min / 60;
        min = min % 60;
     
        printf("\n The time is %d hr: %d min: %d sec",hr,min,sec);
        getch();
}
Click here to contact us 

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


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

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

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

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 

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

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

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

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

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 

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

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...