Let's Start Coding

 Let's Start Coding: Your Journey Begins Here!


Welcome to the exciting world of coding, where creativity meets logic and innovation knows no bounds. Whether you're a seasoned programmer diving into a new project or a curious beginner embarking on your coding journey, the journey ahead is filled with endless possibilities and discoveries.

Let's kickstart your coding adventure !!!


Introducing the printf() Function

The printf routine is a function in the C library that simply prints or displays its argument (or

arguments, as you will see shortly) on your screen.



syntax :

int printf(const char *format, ...);

Examples for printf() :

int num = 10;
printf("The value of num is %d\n", num);

float pi = 3.14159;
printf("The value of pi is %.2f\n", pi); // here its rounds to 2 decimal places

char letter = 'A';
printf("The character is %c\n", letter);



What are Escape Sequences?

Escape sequences are special combinations of characters that begin with a backslash () followed by one or more characters. These sequences enable programmers to insert special characters, control characters, and formatting instructions into strings, etc.

some escape sequences are listed 👇





Lets try some exercises based on printf() 


Print the following 👇 text at the terminal. Try your self

  • In C, lowercase letters are significant.
  • main is where program execution begins.
  • Opening and closing braces enclose program statements in a routine.
  • All program statements must be terminated by a semicolon.


The solution for the above exercise is 


#include <stdio.h>

int main() {
    printf("In C, lowercase letters are significant.\n");  \* used \n for next line command *\
    printf("main is where program execution begins.\n");
    printf("Opening and closing braces enclose program statements in a routine.\n");
    printf("All program statements must be terminated by a semicolon.\n");

    return 0;
}


Try printing the following  shapes





Solution for the 1st shape is 


#include <stdio.h>

int main() {
    printf("* \n");
    printf("* * \n");
    printf("* * * \n");
    printf("* * * * \n");
    printf("* * * * * \n");
    printf("* * * * * * \n");

    return 0;
}


Try yourself other  shapes in same manner


What output would you expect from the following program?


#include <stdio.h> 

int main (void)

{

    printf ("Testing..."); 
    printf ("....1");
    printf ("...2"); 
    printf ("..3"); 
    printf ("\n");

return 0; 

}



Output :






"May your code be bug-free and your creativity boundless. Happy coding!"

Designed by : M.I AFTHAL AHAMAD (ICT/2022/105)





Post a Comment

0 Comments