The greatest mistake you can make in life is to be continually fearing you will make one

Monday, 1 March 2010

C programs based on Preprocessor

  1. Write a macro definition to test whether a character entered is a small case letter or not.
  2. Write a macro definition to test whether a character entered is a upper case letter or not.
  3. Write a macro definition to test whether a character entered is a alphabet or not. use the macro defined in 1 and 2.
  4. Write a macro definition to obtain the bigger of two numbers.
  5. Write macro definitions with arguments for calculation of area and perimeter of a triangle,a square and a circle.
  6. Write a macro definition to find arithmetic mean of two numbers.
  7. Write a macro definition to find absolute value of a number.
  8. Write a macro definition to convert a uppercase alphabet to lowercase
  9. Write macro definitions with arguments for calculation of Simple Interest and amount.
  10. Define a macro swap(t,x,y) that interchanges two arguments of type t.

3 comments:

  1. it's cool but i need the answers
    pls...

    ReplyDelete
  2. for the 10th question i coded this.. Can any1 tell me whether its the right way to to do so?? i am a beginner....

    //macro to swap two vars

    #include < stdio.h >
    #include < conio.h >
    #define SWAP(t,m,n) t=m; m=n; n=t;\
    printf("\nAfter swaping m=%d,n=%d",m,n);

    void main(){
    clrscr();
    int m=3,n=4;
    int a;
    printf("\n before swap m and n are %d %d",m,n);
    SWAP(a,m,n);
    getch();
    }

    ReplyDelete
  3. Hi,
    In the 10th question "t" is the data type and not the temp variable. t may be int,char,float or double.

    ReplyDelete