Chap. 1 : Unit 6 : Sample C Program : Part 2

This video explains you file inclusion at the beginning of program and also how to start writing simple C code to print message, how to take input and how to print the result of summation of two integers. 

Earlier we have tried to study many statements individually… but now we will try to write a program using these statements…

Usually a few library files like stdio.h, conio.h, stdlib.h needs to be included at the beginning of C program. Its use and purpose will be discussed later in the syllabus. So write a statement #include stdio.h and #include conio.h.

So write on the first line # include stdio.h…. and on the next line #include conio.h

Now start program by writing function by writing int or void followed by main followed by pair of round brackets…as pair indication of function as said earlier. As main is one of the important function in C, brackets need to be written in front of this

So whatever we are going to write in C program will be from here onwards…

Here we are going to try to get addition of 2 numbers using C program….So Here we will declare 3 variables namely x, y, and sum all having integer data type, by writing int x, y, sum…

Now we will call one library function called clrscr to clear the screen. Under DOS environment you may require to call but for other environments you will have to check compiler manuals… the earlier contents available in the buffer of monitor may get displayed during next execution so clear screen function will clear it from the screen…this is a function available in the conio.h library so this file is included

If we want to print Welcome to C Programming on the screen then you can write printf 

This function is called from the library and is part of stdio.h file so this file is usually included before main. as printf function is available in this library file…

To take the input from the keyboard one more library function is available in the library which is called as scanf…it stands for scan function and On the next line we can write printf 

You can terminate here the main function by writing getch function followed by closing curly brace on the next line…

Access this framework with lot more stuff like C language MCQ, viva and interview preparation, Glossary, Solved Programs of C language etc. please register free (log in) on Register / Login

cenglishcppengcmarathi

Leave a Reply