Pages

Of Computers, troubles and my Experiments with programming as a beginner.

Thursday, May 8, 2008

002:Book 1,Chapter 1,Program 2

Problem Statement:

1.2 Modify program 1.1 to provide border lines to the address

Solution:

This is just an extension of the previous program. It's a gimmick basically. All it teaches is to visualise the printf lines inside the " ".Because barring the \n - carriage return or newline, the content appears as such in the output.
Program:
/*Program 1.1.2 */
#include stdio.h
/*This is a header file.*/
#include conio.h
/*This is another header file that we require for using getch()*/

int main()
{
printf(" -----------------------");
printf("\n XYZ, ");
printf("\n 10, Downing Street, ");
printf("\n London, 123456 ");
printf("\n -----------------------");
getch();
return 0;
}
Output:
----------------------
XYZ,
10, Downing Street,
London, 123456
----------------------
Description:
You can achieve the same using a single printf statement too. But that's just left to the choice of the programmer. I have used multiple printf statements because it aids the presentation and you can visualise how the output will actually look.
To know more about these terms, click on them.
stdio.h
conio.h
getch()
/* */-Comment Lines
/n - Carriage Return

No comments: