Sunday, August 13, 2017

C programming; Lesson 4:Print on screen


We use the printf function to print on the screen.

If we only want to print a text message the form of the function is:

                                                                    printf ("string of characters to be printed on the screen");

If we want to print a value stored in a particular variable, the form of the function is:

                                                                                           printf ("list_format", variable_lists);

In the format list, we list the variable format we want to print. The format of the variable consists of the character% and type of format:
                                        format                                         meaning                                                                                                    %c                                      Load one character                                                                                          %d                                      Load integer                                                                                                    %f                                       Load real number                                                                                            %s                                       Load string                                                                                                      %u                                      Print decimal number unsigned


Example of printing only a value of a variable :
                                       
                                         int a = 5;
                                         printf ("%d", a);


Example of text output and variable value:

                            int nm_stud = 7;
                            float average = 4.15;
                            printf ("The number of students is%d, and their average is%f", nm_stud, average);







1 comment: