Computer Concept & Programming In C - Unit V - 7

Q.18 Define a macro to check whether a given year is a leap year or not. Illustrate the use of the macro in a program.                                                         (AKTU. 2013-14)
Ans. # define is leap (Y) (Y % 4) = = 0) ? return 1 : return 0

Q.19 Write macro definition with arguments for calculation of simple interest and amount. Store these macro definitions in a file called ‘Interst.h”. Include this file in your program, and use the macro definitions for calculating simple interest and amount.  (AKTU. 2008 - 09)
Ans. /* The C program that calculates simple intrest using macro defined in the <Intrest.h> header file */ 
#include<stdio.h>
#include<conio.h>
#include<Interest.h>
void main()
{
 float p, r, t, interest;
 clrscr();
 printf("\nEnter the rate r = ");
 scanf("%f",&r);
 printf("\nEnter the principle p = ");
 scanf("%f",&p);
 printf("\nEnter the time in years t = ");
 scanf("%f",&t);
 interest = SI(p, r, t);
/*  This is the header file of Q- 12 Interest.h*/
/* This is the header file  save it with the extension
   .h in include folder of C:\TC\include
#define SI(p, r, t) (p* r* t/ 100)
 printf("\nthe total interest is  = %f", interest);
 printf("\nPress any key to exit");
 getch();
 }

Q.20 What do you mean by standard C library.
Related Questions -
Q. Discuss basic file handling functions.                                            (AKTU. 2011 - 12)
Q. Explain the functions used for reading and writing operation on file.
Ans. The standard C Library: -
The string handling functions are already explained before under heading string.
The input/output functions are explained under standard I/O in C.
Now the functions fopen & fread etc are.
1. fopen ( ): - Function is used to open a file and associate a stream to the opened file.
2. fclose ( ): - Function is responsible for closing an opened file and disassociating a stream with the file.
3. The fget ( ) and fput c: - Function read or write one character at a time.
4. The fgets ( ) and fputs ( ): - Functions read or write one line at a time.
5. The fread ( ) and fwrite ( ): - Function read or write one block of data at a time.
6. The feof ( ): - Function can determine when the end of a file has been reached.
7. In a binary file, the feof ( ) function should be used to detect EOF.

Q.21 Write even number in a file (even.dat) and odd numbers in a file (odd.dat).                                                                                                                         (AKTU. 2011 - 12)
Ans. Program -
# include<stdio.h>
# include<conio.h>
void main ( )
{
    int i,
   FILE * ev, *od;
  ev = fopen (“even.dat” W);
  od = fopen (“odd.dat”, W);
  if ((ev! = NULL) && (od! = NULL))
    {
        for (i=1; i<=100; i++)
{
   if((i%2)==0)
       fprintf(ev, “%d”, i);
  else
     fprintf(od, “%d”,i);
}
   printf(“\n Press any key to exit”);
     }
 else
   printf(“\n Error Operating File”);
 getch ( );
}

Q.22 Write short notes on math functions.
Related Questions-
Q. Give any two built in mathematical functions in C language with proper syntax.                                                                           (AKTU. 2012 - 13)
Ans. Math functions: -
Math functions are found in math.h header file. The function paw ( ) returns the exponent of number e.g. pow (2, 3) returns 23 = 8 its proto type i, double pow (double, double). The function sin ( ) returns the sine ratio of the angle specified in radius. 
Prototype double sine (double) and . The function log ( ) has prototype double log (double) it returns the natural logarithm of a number and gives an error if the argument to the function log is a value 0. i.e. less than or equal to zero.
Important to view all types of C functions.
Go to Turbo C++ IDE Help Header Files Select header File Press Enter.
All built in functions will be listed. To study about the function in detail just select the function and press enter key. The function details are explained along with its prototypes, limitations, compatibility and examples about implementing it.
The C functions are very large in number and can be used to practically solve any problem.