- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to print characters and strings in different formats.
An algorithm is given below to explain the process which is included in the C programming language to print the characters and strings in different formats.
Step 1: Read a character to print.
Step 2: Read a name at compile time.
Step 3: Output of characters in different formats by using format specifiers.
- printf("%c
%3c
%5c
", x,x,x); - printf("%3c
%c
", x,x); - printf("
");
Step 4: Output of strings in different formats by using format specifiers.
- printf("%s
", name); - printf("%20s
", name); - printf("%20.10s
", name); - printf("%.5s
", name); - printf("%-20.10s
", name); - printf("%5s
", name);
Example
Following is the C program to print the characters and strings in different formats −
#include<stdio.h> main(){ char x = 'T'; static char name[20] = "Tutorials Point"; printf("OUTPUT OF CHARACTERS
"); printf("%c
%3c
%5c
", x,x,x); printf("%3c
%c
", x,x); printf("
"); printf("OUTPUT OF STRINGS
"); printf("%s
", name); printf("%20s
", name); printf("%20.10s
", name); printf("%.5s
", name); printf("%-20.10s
", name); printf("%5s
", name); }
Output
When the above program is executed, it produces the following output −
OUTPUT OF CHARACTERS T T T T T OUTPUT OF STRINGS Tutorials Point Tutorials Point Tutorials Tutor Tutorials Tutorials Point
Example
Consider another program to check different format −
#include<stdio.h> main() { char x = 'T'; static char name[20] = "Tutorials Point"; printf("OUTPUT OF CHARACTERS
"); printf("%c
", x); printf("%c
%3c
%5c
", x,x,x); printf("%3c
%c
", x,x); printf("%c
%3c
%5c
", x,x,x); printf("%3c
%c
", x,x); printf("
"); printf("OUTPUT OF STRINGS
"); printf("%.5s
", name); printf("%-10.10s
", name); printf("%.20s
", name); printf("%20.10s
", name); printf("%20s
", name); printf("%10s
", name); }
Output
When the above program is executed, it produces the following output −
OUTPUT OF CHARACTERS T T T T T T T T T T T OUTPUT OF STRINGS Tutor Tutorials Tutorials Point Tutorials Tutorials Point Tutorials Point
- Related Articles
- How to print the numbers in different formats using C program?
- Java Program to set date formats for different countries
- Print common characters of two Strings in alphabetical order in C++
- C++ program to find uncommon characters in two given strings
- Display years in different formats with C# DateTime
- C++ program to get length of strings, perform concatenation and swap characters
- C program to print array of pointers to strings and their address
- C program to print characters without using format specifiers
- Python code to print common characters of two Strings in alphabetical order
- Java code to print common characters of two Strings in alphabetical order
- Find uncommon characters of the two strings in C++ Program
- Print the arranged positions of characters to make palindrome in C Program.
- Ways to print escape characters in C#
- How to get specific data in different formats with MongoDB?
- Convert list of strings and characters to list of characters in Python

Advertisements