Pages

Monday, December 31, 2018

Preprocessor Directives - Good Bye 2018, Welcome 2019


Example of Preprocessor Directives:

Following program shows example of use of #include and #define in the C program.

#include<stdio.h>
#include<Windows.h>
#define p printf
#define s Sleep

int main()
{
    int i;
    for(i=0; i<5; i++)
    {
p("..... Good Bye 2018 .....");
    s(500);
    system("cls");
    s(500);
    }
    
    for(i=0; i<5; i++)
    {
p("..... WEL COME 2019 .....");
    s(500);
    system("cls");
    s(500);
    }
    return 0;
}

Output of the program:

This program will blink five times 

..... Good Bye 2018 .....

and then blinks five times

..... WEL COME 2019 .....

Visit C Program Practicals Blog for more details.



Preprocessor Directives


Preprocessor Directives - Overview

It is a program that is invoked by the compiler to process code before compilation.

Once preprocessor directives are applied; changes are applied to the original source code; and the new source code file without directives is created.

Preprocessing is one of the preliminary operation on C and C++ program files before they are passed to the compiler. The preprocessed source program file must be a valid C or C++ program. It allows us to perform the following:
  • Replace tokens in the current file with specified replacement
  • Insert files within the current file
  • Based on given condition- compile sections of the current file
  • Apply machine-specific rules to specified sections of code

A token is a series of characters delimited by white space. The allowed white space characters in as a preprocessor directives are space, horizontal tab, vertical tab, form feed, new-line character and comments.

Some of the preprocessor directives are:
  • #include Inserts text from another source file.
  • #define Defines a macro.
  • #undef Removes a preprocessor macro definition.
  • #error Defines text for a compile-time error message.
  • #if Conditionally suppresses portions of source code
Preprocessor directives begin with the # token and # is followed by a preprocessor keyword. The # is not part of the directive name and can be separated from the name with white spaces.


Example of Preprocessor Directives:



Sunday, December 16, 2018

Flowchart to find largest of 3 numbers


Flowchart to find Largest of Three Numbers

Following flowchart is used to find largest number from the given three numbers. This flowchart is prepared using RAPTOR tool.

Flowchart to find largest of given three numbers.
Fig.: Flowchart to find largest of given three numbers.
We may add one more conditional block in the flowchart to display appropriate message when all three or two of three numbers are equal.


You may like to visit following top 10 Flowchart Examples:

Friday, December 7, 2018

Factorial of number - flowchart

Flowchart of Factorial of a Given Number

According to Wikipedia; the Factorial of a non-negative integer N, denoted by N!, is the product of all positive integers less than or equal to N. 

For example: 4! = 4 X 3 X 2 X 1 = 24

The flowchart of finding factorial of a given number using RAPTOR tool is given below:

Factorial of number - flowchart
Fig: Flowchart of Factorial of a given number.

For more such interesting flowchart example visit Flowchart page.