Hello World | First C Program

In this tutorial, we are using a Turbo C++ compiler and integrated development environment (IDE), which is originally from Borland. What are the ways to run the C Program.

Example 1: WAP to print a Message "Hello World"

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    printf("Hello World"); /* to print the statement */
    getch();
}
Hello World
Code Explanation:
  • #include<stdio.h> - stands for Standard input output, .h - header file. It includes the standard input output library functions like printf(), scanf().
  • #include<conio.h> - Console input output header file. It includes the console input output library functions like clrscr(), getch().
  • void main() - main() is a function from where the program starts its execution, void specifies that the function does not return any value.
  • {...} - Braces or curly brackets define the scope of the program.
  • clrscr() - to clear the screen. It will clear the output screen so that previous output will be cleared when running a new program.
  • printf() - is a function which is used to print data.
  • /*...*/ - is used to comment.
  • getch() - use to input a single character. It holds the screen until the user presses any key.

How to compile and run the program

There are 2 ways to compile and run the c program, by menu and by shortcut key.

  1. By Menu: Click on compile menu and select compile option to compile the program. Then, click on run menu and select run option to run the program.
  2. By Shortcut key: Press ALT+F9 keys to compile the program and ctrl+f9 to run the program.

Example 2: WAP to Input 2 numbers and find the sum. 1

#include<stdio.h>
#include<conio.h>
void main()
{
    int a, b, c;
    clrscr();
    printf("Enter 1st Number: ");
    scanf("%d",&a);
    printf("Enter 2nd Number: ");
    scanf("%d",&b);
    c=a+b;
    printf("Sum = %d",c);
    getch();
}
Enter 1st Number: 10
Enter 2nd Number: 20
Sum = 30
Code Explanation:
  • scanf() - function is used to receive the values from the user.
  • & - means the address of a variable.