Learn C Programming in 7 days -Day 1

Howdy viewers, HowIPro welcomes you to the page of “Learn C Programming in 7 days -Day 1”. In this tutorial you are going to learn about the very beginning of the C programming. You will learn how you can easily print something to the output screen. In the previous tutorial you have learnt about the setting up the C onto your windows machine. In the 7th day C tutorial I am going to use windows as my Operating System. However, the coding procedure is same but to start the C default editor is different.

Things you should know:

  1.  Every C programming starts with #include<stdio.h> where # is the preprocessor, include is the function to include the file and stdio.h within the tags is the file (header file) that has to be included. stdio.h is the standard input output header file written by the C developers where the printing and other procedures are written. The main purpose of the header files is to shortend the code and reduces the multiple uses during the C software development. However, in some cases the said header file has not to be declared as it is declared by default.
  2. Every C language has the main() function which defines to be the starting of the program and it is mandatory. If you start with main() function then you must declare a return type at the end of the program. But, if you start with void main() then you don’t have to declare any return value.
  3. Curly braces are important because it defines that a program has started. The start of a program is indicated by the opening curly brace {. Since a program has started, you must end the program and that is done by closing curly brace }.
  4. If you are printing something like sum of two numbers or such then you need to declare the type of the output known as data types. The data types in C language are int (integer), float (floating number), double, char and void.
  5. If you are outputing the result then use %d for int, %f for float, %l for double and %c for char.



Let’s start learning:

I assume that you have understand the basic theoretical concept of C programming language. Let’s dive into the programming.

P1. Write a C program to print your name with no return type?

#include<stdio.h>
void main()
{
printf(“HOWIPRO welcomes you to the C tutorial”);
}

P2. Write a C program to print your name with return type?

#include<stdio.h>
main()
{
printf(“HOWIPRO welcomes you to the C tutorial”);
return 0;
}

P3. Write a C program to add two numbers?

#include<stdio.h>
void main()
{
int a=5,b=6,c; // declaring the values as integer type.
c=a+b; //sum of a and b.
printf(“The sum of two numbers is %d”,c); //%d is used to output the integer value
}

If you want to multiply, divide, substract or find the modulo (remainder) of two numbers, follow the P3 instead change the ‘+’ sign to ‘*’, ‘/’, ‘-‘ and ‘%’ respectively.

Overview of C                                                                                                                      Day 2 of C tutorial