Showing posts with label MACRO. Show all posts
Showing posts with label MACRO. Show all posts

define a macro that does not make use of a bitwise XOR operator to swap the contents of two variables.


#include<stdio.h>
#define swap(a,b) {a=a+b;b=a-b;a=a-b;printf("x=%d y=%d",a,b);}
void main()
{
    int x,y;
    printf("enter the two numbers\n");
    scanf("%d%d",&x,&y);
    printf("the numbers before swapping are\n x=%d y=%d\n",x,y);
    printf("the numbers after swapping are\n");
    swap(x,y);
}

NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.

output image


define a macro to find the factors of a number.

#include<stdio.h>
#define factor(num) {do{if(num%a==0){num=(num/a);printf("\n%d",a);}else a++;}while(num!=1);}
void main()
{
    int a=2,num;
    printf("enter the number\n");
    scanf("%d",&num);
    printf("%d",1);
    factor(num);
}


NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.


output image  (click to enlarge).


Implemet Stack in python

  class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...