Learn how to use the printf() function to display output in C programming.
To write a C program that demonstrates the use of the printf() function to display output on the screen.
In C programming, printf() is a built-in function used to display output on the screen. It stands for "print formatted". The printf() function is part of the stdio.h (Standard Input/Output) library. You need to include this library at the beginning of your program using #include <stdio.h>.
The printf() function can display:
%d (integer), %f (float), %c (character), and %s (string) are used with printf() to print different types of data.
Expected Output:
| Format Specifier | Data Type | Example | Output |
|---|---|---|---|
%d |
Integer | printf("%d", 10); |
10 |
%f |
Float | printf("%f", 3.14); |
3.140000 |
%.2f |
Float (2 decimals) | printf("%.2f", 3.14); |
3.14 |
%c |
Character | printf("%c", 'A'); |
A |
%s |
String | printf("%s", "Hello"); |
Hello |
\n |
Newline | printf("Hello\nWorld"); |
Hello World |
printf() function is used to display output on the screen.%d, %f, %c, %s are used to print different data types.\n is used to move to a new line.%.2f limits float values to 2 decimal places.printf() statement using multiple format specifiers.
You have successfully written a C program that demonstrates the use of the printf() function. You can now display different types of data on the screen using format specifiers.
#include <stdio.h> at the top of your program to use printf() and other I/O functions.
printf() with different format specifiers to become comfortable with displaying output in C programs.
ایک C پروگرام لکھنا جو اسکرین پر آؤٹ پٹ ظاہر کرنے کے لیے printf() فنکشن کا استعمال دکھاتا ہے۔
C پروگرامنگ میں، printf() ایک بلٹ ان فنکشن ہے جو اسکرین پر آؤٹ پٹ ظاہر کرنے کے لیے استعمال ہوتا ہے۔ یہ "print formatted" کا مخفف ہے۔ printf() فنکشن stdio.h (Standard Input/Output) لائبریری کا حصہ ہے۔ آپ کو اس لائبریری کو اپنے پروگرام کے شروع میں #include <stdio.h> استعمال کرکے شامل کرنا ہوگا۔
printf() فنکشن درج ذیل ظاہر کر سکتا ہے:
%d (انٹیجر)، %f (فلوٹ)، %c (کریکٹر)، اور %s (سٹرنگ) مختلف اقسام کے ڈیٹا کو پرنٹ کرنے کے لیے printf() کے ساتھ استعمال ہوتے ہیں۔
متوقع آؤٹ پٹ:
| فارمیٹ اسپیسیفائر | ڈیٹا کی قسم | مثال | آؤٹ پٹ |
|---|---|---|---|
%d |
انٹیجر | printf("%d", 10); |
10 |
%f |
فلوٹ | printf("%f", 3.14); |
3.140000 |
%.2f |
فلوٹ (2 اعشاریہ) | printf("%.2f", 3.14); |
3.14 |
%c |
کریکٹر | printf("%c", 'A'); |
A |
%s |
سٹرنگ | printf("%s", "Hello"); |
Hello |
\n |
نئی لائن | printf("Hello\nWorld"); |
Hello World |
printf() فنکشن اسکرین پر آؤٹ پٹ ظاہر کرنے کے لیے استعمال ہوتا ہے۔%d، %f، %c، %s مختلف ڈیٹا ٹائپس کو پرنٹ کرنے کے لیے استعمال ہوتے ہیں۔\n نئی لائن پر جانے کے لیے استعمال ہوتا ہے۔%.2f فلوٹ ویلیوز کو 2 اعشاریہ جگہوں تک محدود کرتا ہے۔printf() بیان میں متعدد فارمیٹ اسپیسیفائر استعمال کرتے ہوئے متعدد متغیرات کو پرنٹ کیا جا سکتا ہے۔
آپ نے کامیابی سے ایک C پروگرام لکھا ہے جو printf() فنکشن کا استعمال دکھاتا ہے۔ اب آپ فارمیٹ اسپیسیفائر کا استعمال کرتے ہوئے مختلف اقسام کا ڈیٹا اسکرین پر ظاہر کر سکتے ہیں۔
printf() اور دیگر I/O فنکشنز استعمال کرنے کے لیے ہمیشہ اپنے پروگرام کے شروع میں #include <stdio.h> شامل کریں۔
printf() استعمال کرنے کی مشق کریں۔