TurboC Chp3
TurboC Chp3
Control String
\a bell \v vertical tab
\b backspace \\ backslash
\f formfeed \' single quote
\n newline \" double quote
\r carriage return \? question mark
\t horizonal tab \0 null
Type casting
(data type)variable - convert data type to another data type
Example
int a,b;
float c;
c=(float)a/b;
Example 3.1
/* example 3.1*/
//display statement on the screen
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"\a\a\a\t\t\tHello student\n";
cout<<"\a\a\a\t\t\tGood Morning!\n";
getch();
}
Example 3.2
Example
window(1,1,80,25);
window(10,10,80,30);
textbackground(BLUE);
textcolor(LIGHTCYAN);
textcolor(7);
textbackground(2);
Value Constant foregroun backgrou
d nd
0 BLACK YES YES
1 BLUE YES YES
2 GREEN YES YES
3 CYAN YES YES
4 RED YES YES
5 MAGENTA YES YES
6 BROWN YES YES
7 LIGHTGRAY YES YES
8 DARKGRAY YES NO
9 LIGHTBLUE YES NO
10 LIGHTGREEN YES NO
11 LIGHTCYAN YES NO
12 LIGHTRED YES NO
13 LIGHTMAGENTA YES NO
14 YELLOW YES NO
15 WHITE YES NO
To make the characters blink in a call to textcolor, you add 128 to the
foreground color. The predefined constant BLINK exists for this purpose; for
example,
textcolor(CYAN + BLINK);
Example 3.9
/* div & ldiv example */
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
div_t x; //declaration
ldiv_t lx; //declaration
int main(void)
{
clrscr();
x = div(10,3);
printf("10 div 3 = %d remainder %d\n",
x.quot, x.rem);
lx = ldiv(100000L, 30000L);
printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem);
return 0;
}
Exercises
1. Write a program to display the following statement on the screen.
[tab]Hello, my name's Sanda.
[tab] [tab] [tab]What's your name?, please.
2. Write a program to find the sum, product and average of three integer numbers and display the
results on the screen.
3. Write a program to find the area of triangle and display the result on the screen.
(area=0.5*base*height)