Computer Concept & Programming In C - Unit III - 3

}
else
{
printf (“\ n The amount of purchase exceeds your credit limit”);
printf (“\ n Sorry, the purchase can’t be approved”);
}
printf (“\ n Thank you for using C credit card”);
printf (“\ n We look forward to doing business with you in the future”);
}
If you enter an amount like 100 the output will be:
Enter the amount: 100.
Your charge is accepted.
Your price plus taxes is $ 105.00.
Thank you for using C credit card.
We look forward to doing business with you in the future.  
If you enter an amount that exceeds the credit limit like 2000, you will notice that the last two statements in the program are still executed as they are outside the condition blocks.
The other run of the program:
Enter the amount: 2000
The amount of purchase exceeds your credit limit.
Sorry the purchase cannot approve.
Thank you for using C credit card.
We look forward to doing business with you in the future.
* Nesting if and else: -
The if-else may contain other if or if else constructs, a feature called nesting. You must be careful in this case, as you have to keep track of the different ifs and the corresponding else. Consider this simple example.
if (a > = 4)
  if (b > = 4)
    printf (“result # 1”);
else
    printf (“result #2”);
The rule is that every else belongs to the last if in the same block. In this example, the else belongs to the second if. You can however associate it with the first if by using a block as follows:
if (a > =  4)
{
  if (b > = 4)
printf (“ result # 1”);
}
else
print (“result #2”);
This way, the else belongs to the first if which is now the closest if in the same block.

/* Q.5    Write a program in C to test whether
   given year is a leap year or not.         */
/* An year is a leap year if and only if it is exactly divisible by 4. */   (AKTU. 2008 - 09)
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
  long year;
  clrscr();
  printf("\n Enter the year \n");
  scanf("%ld", &year);
  if((year >= 0)&&((year%4) == 0))
    printf("\n It is a valid leap year");
  else
    printf("\n It is not a valid leap year");
  printf("\nPress any key to exit.");
  getch();
}

/* Q.6 A company insures a its driver in the following cases.
   1.  If the driver is married.
   2.  If the driver is unmarried, male and above
       30 years of age.
   3.  If the driver is unmarried and above 25 years of age.
   In all other case the driver is not insured.
   Write a 'C' program without using logical operators  to determine whether the driver is insured or not.*/                                                             (AKTU. 2008 - 09)
Ans. /* We have not used logical operators like &&(and), ||(or)   */
#include<stdio.h>
#include<conio.h>
void main()
{
  int marital_status;    /* 1 for married    */
/* 0 for unmarried  */
  unsigned int age;      /* for storing age  */
  unsigned int sex;      /* 1 for male       */
/* 0 for female     */
  unsigned int flag = 0;
clrscr();