Computer Concept & Programming In C - Unit V - 11

Q.26 What is the use of header file? Discuss.                   (AKTU. 2009-10)
Ans. Consept of Header File : Since “C” is general purpose programming language. It is use to solve more than one type of task just like in the real word we make tool boxes for different type of task similarly we make header files for specific task.
For Example : 1. All functions for performing mathmatical task are inclose then the header file <math.h>
2. All functions for string handling are present in the file <string.h>
3. Functions for performing input and output operation as well as file handling are present in <stdio.h> similarly there are many header file in “C” language and header file contains defination of function to perform a specific task.
Header file extantion is .h
mathmatics <math.h>
string handling <string.h>
graphics <graphics.h>

Input & Output operations <stdio.h> <io stream.h> <f stream> <conio.h>
dos commands <dos.h>

Q.27. Write a program in C that takes a year from twentieth century as an input and then tells whether it is a leap year or not ?                                        (AKTU. 2010 - 11)
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
  int year;
  clrscr();
  printf("\n Enter any year of twentieth century.\n");
  scanf("%d", &year);
  if((year >= 2000)&&(year < 2100))
  {
   if((year % 4) == 0)
     printf("\nIt is a leap year");
   else
     printf("\nIt is not a leap year");
  }
  else
     printf("\nNot an year of twentieth century.");
  getch();
}

/* Q.28 Area of a triangleis given by formula
                  ##################
     A = ## # s(s-a)(s-b)(s-c)
  #
     where a,b,c are sides of the triangle
     and  s = (a+b+c)/2;
write a program in C to compute the area of the
triangle given the values of a, b, c.          */                            (AKTU. 2008 - 09)
Ans.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  float a, b, c, s, A;
  clrscr();

  /* Taking input of sides */
  printf("\n Enter the three sides a, b, c of a triangle\n");
  printf("\n a = ");
  scanf("%f",&a);
  printf("\n b = ");
  scanf("%f",&b);
  printf("\n c = ");
  scanf("%f",&c);

  /* checking whether the sides are positive and
     sum of any two sides of a triangle is always
     greater than the third.                       */

  if( (a < 0)||( b < 0)||(c < 0) ||
      ((a+b) < c)||((b+c) < a)||((a+c) < b))

      printf("\n Invalid sides of a trianle.");
  else
       {
 s = (a+b+c)/2.0;
 A = sqrt(s*(s-a)*(s-b)*(s-c));
 printf("\nThe area of a triangle = %f ", A);
}
  printf("\n\nPress any key to exit.");
  getch( );
}