PLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
ssuser609e37
328 views
16 slides
Oct 14, 2024
Slide 1 of 16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
About This Presentation
Using the printf function:
This is the most versatile and frequently used method.
Takes a format string as its first argument and then any number of additional arguments that correspond to placeholders in the format string.
Example:
C
#include
int main() {
printf("Hello, world!\n");...
Using the printf function:
This is the most versatile and frequently used method.
Takes a format string as its first argument and then any number of additional arguments that correspond to placeholders in the format string.
Example:
C
#include
int main() {
printf("Hello, world!\n");
return 0;
}
Use code with caution.
In this example, printf is used to print the message "Hello, world!" to the console. The \n character in the format string represents a newline, which moves the cursor to the beginning of the next line.
You can also use placeholders in the format string to insert variables into the output:
C
#include
int main() {
int age = 25;
char name[] = "Alice";
printf("My name is %s and I am %d years old.\n", name, age);
return 0;
}
Use code with caution.
Here, %s is used to insert the value of name, and %d is used to insert the value of age.
Other methods:
puts: Prints a single string to the console.
fprintf: Prints output to a file instead of the console.
putchar: Prints a single character to the console.
Additional notes:
You can use escape sequences like \n, \t, and \r in the format string to control the output formatting.
For more complex output formatting, consider using the sprintf function to format output into a string first. Using the printf function:
This is the most versatile and frequently used method.
Takes a format string as its first argument and then any number of additional arguments that correspond to placeholders in the format string.
Example:
C
#include
int main() {
printf("Hello, world!\n");
return 0;
}
Use code with caution.
In this example, printf is used to print the message "Hello, world!" to the console. The \n character in the format string represents a newline, which moves the cursor to the beginning of the next line.
You can also use placeholders in the format string to insert variables into the output:
C
#include
int main() {
int age = 25;
char name[] = "Alice";
printf("My name is %s and I am %d years old.\n", name, age);
return 0;
}
Use code with caution.
Here, %s is used to insert the value of name, and %d is used to insert the value of age.
Other methods:
puts: Prints a single string to the console.
fprintf: Prints output to a file instead of the console.
putchar: Prints a single character to the console.
Additional notes:
You can use escape sequences like \n, \t, and \r in the format string to control the output formatting.
For more complex output formatting, consider using the sprintf function to format output into a string first.Using the printf function:
This is the most versatile and frequently used method.
Takes a format string as its first argument and then any number of additional arguments that correspond to placeholders in the format string.
Example:
C
#include
int main() {
printf("Hello, world!\n");
return 0;
}
Use code with caution.
In this example, printf is used to prin
Size: 1.17 MB
Language: en
Added: Oct 14, 2024
Slides: 16 pages
Slide Content
Lesson 5 – Program Logic and Design
Professional Lecturer
#include <stdio.h>
int main ()
{
printf ("Hello World!");
printf (“I love C!");
printf (“I love PUP!");
}
printf ("Hello World!");
printf (“I love C Language!");
printf (“I love PUPBC!");
printf ("Hello World!");
printf (“I love C Language!");
printf (“I love PUPBC!");
printf ("Hello World! \n");
printf (“I love C Language! \n");
printf (“I love PUPBC! \n");
printf ("Hello World! \n");
printf (“I love C Language! \n");
printf (“I love PUPBC! \n");
#include <stdio.h>
int main ()
{
printf ("Bye, Bye, Bye by NSYNC \n");
printf ("Change the World by Westlife \n");
printf ("And I by Boyzone \n");
printf ("True to Your Heart by 98 Degrees \n");
printf ("All Rise by Blue");
}
#include <stdio.h>
int main ()
{
// This is a comment
printf ("Hello
World!");
printf (“I love C!");
printf (“I love PUP!");
}
// This is a single-line comment
printf (“I love C Language!");
printf (“I love PUPBC!");
/* The code below will print the words Hello
World! to the screen, and it is amazing //
printf (“Hello World!");