Before writing our first program, let us understand the rules for writing the C program. Every language specification defines its own syntax and rules.
Rules for writing a C Program:
To write 'Hello World' which is our first C Program, we need a IDE (Integrated Development Environment), in this example we are using Turbo C++ IDE, which is originally from Borland.
Example 1.1: Write a program to print a Message "Hello World" 1
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello World"); /* to print the statement */
getch();
}
There are 2 ways to compile and run the c program, by menu and by shortcut key.
How to write 'Hello World' in Microsoft Visual Studio Code Editor.
Example 1.2: Write a program to print a Message "Hello World" 1
#include<stdio.h>
void main()
{
printf("Hello World"); /* to print the statement */
}
There are 2 ways to compile and run the c program, by menu and by shortcut key.
Example 2: WAP to Input 2 numbers and find the sum. 1
#include<stdio.h>
void main()
{
int a, b, c;
printf("Enter 1st Number: ");
scanf("%d",&a);
printf("Enter 2nd Number: ");
scanf("%d",&b);
c=a+b;
printf("Sum = %d",c);
}