CHAPTER 2
START PROGRAMMING
How to open C compiler:
1.Copy the C compiler file to the C drive.
2.Click START menu and select run option.
3.In run box type cmd command and click OK button.
4.Command prompt window will be open.
5.Type the following commands:
C:\Documents and settings\xp>cd\
C:\>cd turboc2
C:\turboc2>tc
FIRST PROGRAM :
Example 1
/*My first program*/
main()
{
clrscr(); /* This function clear screen */
printf("Good Afternoon"); /* This function prints message */
getch();
}
Output:-
Good Afternoon
printf(): Function is use to display a message on the screen.
getch(): This function is use to input a character from keyboard .
clrscr(): This function is use to clear the screen.
Example 2
/*My 2 program*/
main()
{
clrscr();
printf("Good");
printf("Afternoon");
getch();
}
Output:-
Good Afternoon
\n: It is use to change a line.
Example 3
/*My 3 program*/
main()
{
clrscr();
printf("Good");
printf("\nAfternoon");
getch();
}
Output:-
Good
Afternoon
Program 4
/*Program to print sum of two numbers*/
main()
{
int num1,num2,sum; /* Declaring numbers */
clrscr();
num1=10; /* Assigning values */
num2=20;
sum=num1+num2; /* Addition */
printf("Total is %d",sum);
getch();
}
Output:-
Total is 30
Program 5
/*Program to print sum of two numbers*/
main()
{
int num1,num2,sum;
clrscr();
num1=10;
num2=20;
sum=num1+num2;
printf("num1=%d\nnum2=%d\nTotal is %d",num1,num2,sum);
getch();
}
Output:-
num1=10
num2=20
Total is 30
Program 6
/*Program to print sum of two numbers*/
main()
{
int num1,num2,sum;
clrscr();
printf("Enter first no ");
scanf("%d",&num1); /* This function takes input from user */
printf("Enter second no ");
scanf("%d",&num2);
sum=num1+num2;
printf("num1=%d\nnum2=%d\nTotal is %d",num1,num2,sum);
getch();
}
Output:-
num1=_
num2=_
Total is _
Write a program to input two numbers and calculate their total,multiplication,subtraction and division ?