Generate a square table : Macro Function « Macro Preprocessor « C / ANSI-C






Generate a square table

Generate a square table
#include <stdio.h>
#define SQR(x) ((x) * (x))

int main()
{
    int counter = 0;

    while (counter < 5)
        printf("x %d square %d\n", counter, SQR(++counter));

    return (0);
}
  

           
       








Related examples in the same category

1.Defining a macro to compare two valuesDefining a macro to compare two values
2.Defining a macro to output the value of an expressionDefining a macro to output the value of an expression
3.Define small function in macro
4.Make string
5.Use marco for small function
6.Use macro to find the minor variable
7.Define Macro as simple function
8.Use Macro to check the int range
9.Use Macro to get the bigger int value