C Program to display the sequence 1, 2, 4, 8, 16, 32, 64,........................

C Program to display the sequence 1, 2, 4, 8, 16, 32, 64,........................

In this example of C tutorial, we will take number of terms input from the user and print the above mentioned series in the console/screen.

Write program to display the sequence 1, 2, 4, 8, 16, 32, 64,...................

Program:


================================






================================

Output:


================================




================================




Explanation of the program:

# : If any line start with #, it is a pre-process only that line. Special symbol (#) to indicate the pre-processor directive.

include : pre-processor directive. I include important file in the C program.

stdio.h : This file contains functions such as printf() and scanf() to print in the screen and taking input from the user.

main() : The C program execution starts from this line. The main() function is called by the operating system (O/S).

int : It is an Integer data type.

scanf() : It is a function defined in the stdio.h header file, to take the date from the user.

%d : It is the format specifier for the Integer data type.

& : Address of any variable in the memory.

printf() : It is a function defined in the stdio.h header file, to print or send output to the screen/consol.

return 0 : This statement is to Exit the program. It tells the operating system (O/S) that the program has run successfully, as 0 means success. In place of 0 we can use any number like 1, 2,… but the general convention is to write 0.