To learn programming in C, we must start with a dummy program and then understand various terms being used in that code. So write the below given code in a New File (Open TurboC> File> New>Noname00.c, the default name given to new C File).
#include <stdio.h>
main()
{
clrscr();
printf(“Welcome to My BLOG : Learning C is a FUN”);
getch();
}
After typing, press CTRL + F9 to compile and execute the above code.
Now, let us understand the statements written within main() block.
1. clrscr(); This is a library function, used to clear the Output Window and place the cursor at Top Left corner of the screen. This function can be used, whenever you want to clear the existing contents available on the screen.
2. printf(): This is the default Output Function and is used to output any message on screen. We will be discussing this in a few moments.
3. getch(): This is Input Function which accepts a single character from Console Input i.e. Keyboard but doesn’t echo it on screen. Thus, rather than using it as Input MEthod, we mostly use it as a wait statement in our program, so that as soon as user hits any Key, the program may proceed further.
The printf()
printf() is the standard Output Function used to output any message or value current position on Output Screen. The generalized format for printf is :
printf(“Message”);
Using two printf’s doesn’t make sure that the Message will appear at Next Line on Output Screen. To do this, Place New Line Character just before your message , just like shown below:
printf (“\n Message”);
You can place as many \n as you want , in any printf statement. The number of \n is equal to the number of lines after which the message will appear on screen.
Similarly, to have a TAB distance within message text, you can use “\t” within the message.
Basic TURBOC Editor Commands
1. ALT + F3 : To close any Window
2. Alter + ENTER : Toggle the FULL SCREEN and RESTORE view
3. CTRL +F9 : Compile and RUN
4. ALT +F5 : Toggle between CODE and OUTPUT Window
5. F5: To get the FULL SCREEN VIEW of any WINDOW.
6. F2: Save Program File.
7. ALT + X: Quit TURBOC .
Self Assessment Question
1. Explain the working and usage of : clrscr() and getch() function
2. Define the general format of printf() function.
3. Write a C program Code to output following on screen:
AARTI C BLOGS
AARTI C BLOGS
AARTI C BLOGS
No comments:
Post a Comment