In this tutorial you will learn about the C Program to Demonstrate Printf inside Another Printf Statement and its application with practical example.
C Program to Demonstrate Printf inside Another Printf Statement
In this tutorial, we will learn to create a C program that will Demonstrate Printf inside Another Printf Statement using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
Demonstrate Printf inside Another Printf Statement :-
As we all know every programming language the program cannot be completed without taking input or returning output. In C programming language printf() and scanf() functions are inbuilt library functions in which are available in C library by default. These functions are declared and related macros are defined in “stdio.h” which is a header file in C language.
We only have to include the header file named as “stdio.h” as shown in below C program to make use of these printf() and scanf() library functions in C language.
Printf function is used to write the output or show message on the screen.
In nested printf Inner most printf() function writes the output of the program.
Second printf() function counts the output number’s digits and write them.
And third printf() function will write the number of digits returned by the second printf() function
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 12 13 |
STEP 1: START STEP 2: INITIALIZE variable for program STEP 3: take input number from the user STEP 4: create nested printf() STEP 5: pass the variable value to print STEP 6: Return 0. STEP 7: END. |
Program:-
Demonstrate Printf inside Another Printf Statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<stdio.h> //MAIN FUNCTION CODE int main() { //declaring variable int no; // taking input from user printf("enter the number="); scanf("%d",&no); //Printing the data using the nested printf functions //Firstly Inner printf is executed which results in printing no //This Printf Returns total number of Digits //It prints 4 and Returns the total number of digits //i.e 1 (4 is single digit number ) printf("%d", printf("%d", printf("%d", no))); return(0); } |
Output:-
The above program we have to first initialize the required variable.
- no = it will hold the integer value.
Taking Input from the user an integer value.
Printing using Printf inside Another Printf Statement.