Escolar Documentos
Profissional Documentos
Cultura Documentos
C Language Introduction
Languages :
A Set Of Statements Is Called A Language.There Are
Four Types Of Languages According To Their Time.
C LAN GUAG E
The language C was designed by Dennis Ritchie at AT
& T Bell Laboratories. The standardised C was released in
1979.
Th e C languag e is use d to d ev e lop
i) Scientific applications,
ii)Business applications,
iii) Graphical applications (Ex: WINDOWS ),
iv) System programs,
v) Operating Systems (Ex: UNIX) , ...
Character Set :
alphabets constants, statements,
digits ==> variables, ==> ==>
Programs
special symbols keywords instructions
2) Numeric Constants :
-5-
2) Assigning Operators : =
(variable) = (constant) / (variable) / (expression) ;
Ex: a = 5
b=a
c = a + b -2
3) Multiple operators : += -= *= /= %=
Ex:
-7-
a = a + 3 ==> a += 3
a = a - 3 ==> a -= 3
a = a * 3 ==> a *= 3
a = a / 3 ==> a /= 3
a = a % 3 ==> a %= 3
4) Unary Operators : ++ --
Ex :
a = a + 1 ==> a += 1 ==> a ++ ==> ++ a
a = a - 1 ==> a -= 1 ==> a -- ==> -- a
7)
, . : ; < > # { [ ( ) ] } ......
Structure of a C program :
preprocessor commands
global declarations
-8-
main()
{
local declarations ;
statements ;
}
function(arguments)
{
local declarations ;
statements ;
}
Preprocessor commands :
The commands which start with a hash(#) symbol are
called Preprocessor commands.
Ex :
-9-
# include <stdio.h>
# include conio.h
# define PI 3.14159
Global declarations :
To use any variable it must be declared with its data type
before the first executable statement. The variables which
declared in a block are available in that block only.
To use the variable in the entire program with same effect it
must be declared as global.
- 10 -
Data Types :
Type Range occupied
bytes format string
signed char -128 to 127 1
%c
unsigned char 0 to 255 1
%c
/*
sdfjkshadjfsdjkafkjsadjkfhkasdj
sdafhasdfhgasdhfgasdgfgasdfhasdfj
sdafjksadfjasdkhfjasdhkfjhksda
*/
Ex Programs :
1) /* My First C Program */
# include <stdio.h>
# include <conio.h>
main()
{
clrscr() ;
printf(Hello );
printf(Bhanodaya ) ;
printf(Welcome ) ;
}
/*
- 14 -
*/
- 15 -
TURBO C editor :
It is a compiler of C program and it can be also used as an
general editor. To enter into editor first change into the
directory which contains the software and enter the
command TC at the command prompt.
C:\> CD TC
C:\TC> tc
Then it opens the editor which contains a menu bar at the
top, a status bar at the bottom and a main window to write
the programming statements and a sub window which
shows the messages.
The menu bar contains some menu pads and they can be
selected by pressing ALT and the highlighted character in
the required menu pad.
Then it shows the submenu which contains some bars and
they can be selected using arrow keys.
The status bar shows online help and the keys
information.
1) To write a new program select New command from
File menu.
2) To save the working program select Save command
from File menu
or press F2 and enter a name.
- 16 -
Escape Sequences :
Ex Programs :
2) /* Using Escape Sequences */
# include <stdio.h>
# include <conio.h>
main()
{
clrscr() ;
printf(Hello \t ) ;
printf(Udaya \n) ;
- 18 -
printf(Welcome ) ;
}
/* Output :
Hello Udaya
Welcome
*/
3)
# include <stdio.h>
# include <conio.h>
main()
{
clrscr() ;
printf(Hello \t Bhanu \n Welcome ) ;
}
/* Output :
Hello Bhanu
Welcome
*/
- 19 -
4) /* Using Variables */
# include <stdio.h>
# include <conio.h>
main()
{
int k = 65 ;
char j = * ;
clrscr() ;
/* Output :
The value of k is 65 65 A 101 42
The value of j is 42 42 * 52 2a
*/
- 20 -
# include <stdio.h>
# include <conio.h>
main()
{
int a, b, c ;
clrscr() ;
a = 6 ; b = 23456; c = 678 ;
printf(\n %05d \t %d, a, a ) ;
printf(\n %05d \t %d, b, b ) ;
printf(\n %5d \t %d, c, c ) ;
}
/* Output :
00006 6
23456 23456
678 678
*/
6) /* Arithmetic Operations */
# include <stdio.h>
# include <conio.h>
- 21 -
main()
{
int a, b, c, d, e, f ;
clrscr() ;
a = 100 ; b = 40 ;
c = a + b ;
d = a - b ;
e = a * b ;
f = a / b ;
printf(The given values are %d,
%d, a, b ) ;
printf(\n The addition is %d, c)
;
printf(\n The subtraction %d, d)
;
printf(\n The product is %d, e)
;
printf(\n The division %d, f) ;
printf(\n The reminder is %d,
a%b) ;
}
/* Output :
- 22 -
*/
Ex Programs :
7) /* Type casting */
# include <stdio.h>
# include <conio.h>
main()
{
int m1, m2, m3, tot;
float avg ;
- 23 -
clrscr() ;
/* Output :
The three subjects marks are 65, 66, 68
The total 199 Average 66.33
*/
# include <stdio.h>
# include <conio.h>
main()
- 24 -
{
float bas, da, hra, pf, net ;
clrscr() ;
bas = 5000;
da = bas * 20 / 100 ;
hra = bas * 30 / 100 ;
pf = bas * 5 / 100 ;
net = bas + da + hra - pf ;
/* Output :
*/
- 25 -
# include <stdio.h>
# include <conio.h>
main()
{
int k = 5 ;
clrscr() ;
Output
5
printf(\n %d, k) ;
k ++ ;
7
printf(\n %d, ++k) ;
7
printf(\n %d, k++);
8
printf(\n %d, k) ;
k -- ;
7
- 26 -
Notes :
scanf() :
This function is used to accept the values for the variables
while executing the program from keyboard. This
functions prototype has defined in the header file
STDIO.H
The function printf() returns an integer value that is the
number of arguments given to the statement.
Syntax:
scanf(formatstring , &(variables) );
- 27 -
Note :
To accept two or more values with a single scanf() they can
be seperated by space or tab or enter key.
Ex :
i) int a;
scanf(%d, &a);
ii)int m1, m2, m3;
scanf(%d%d%d, &m1, &m2, &m3);
iii) char ch;
scanf(%c, &ch);
getch() :
This function is used to accept a single character for the
variable while executing the program. But this function
does not display the entered character. This functions
prototype has defined in the header file CONIO.H
Note : To see the entered character the function getche()
can be Used.
Syntax:
(variable) = getch() ;
Ex :
char c;
c = getch();
- 28 -
- 29 -
Ex Programs :
9) /* Program to demonstrate the difference between the
functions
scanf(), getche(), getch()
*/
# include <stdio.h>
# include <conio.h>
main()
{
char k ;
clrscr();
/* Output :
Enter any character abcdef
You entered the chracter a
# include <stdio.h>
# include <conio.h>
main()
{
int m1, m2, m3, tot;
float avg ;
clrscr() ;
/* Output :
Enter three subjects marks
65 66 68
Notes :
Conditional Statements :
- 32 -
main()
{ output
int k = 5 ;
clrscr() ;
printf(\n %d, k ); 5
printf(\n %d, k<10) ; 1
printf(\n %d, k>10) ; 0
printf(\n %d, k+(k==5) );
6
printf(\n %d, k=10) ;
10
getch() ;
- 33 -
}
- 34 -
Notes :
There are three types of conditional statements in C.
1) if, 2) switch, 3) conditional operators
1) if ... else :
Syntax :
if (condition)
if (condition)
{ {
(statements);
(statements);
} or }
else
{
(statements) ;
}
Ex Program :
13)/* Write a program to check
whether the given number is zero or
not */
# include <stdio.h>
- 35 -
# include <conio.h>
main()
{
int k;
clrscr() ;
getch() ;
}
# include <stdio.h>
# include <conio.h>
main()
{
- 36 -
int k ;
clrscr() ;
# include <stdio.h>
# include <conio.h>
main()
- 37 -
{
int a, b ;
clrscr() ;
getch() ;
}
main()
- 38 -
{
int a, b, c ;
clrscr() ;
getch() ;
}
- 39 -
# include <stdio.h>
# include <conio.h>
main()
{
int a, b, c, d, e, t ;
clrscr() ;
getch( );
}
main()
{
int a, b, c, d, e, x, y ;
clrscr() ;
if(x<c) x = c ;
else if(y>c) y = c ;
if(x<e) x = e ;
else if(y>d) y = d ;
if(x<e) x = e ;
else if(y>e) y = e ;
printf(\n The biggest is %d, x) ;
printf(\n The smallest is %d, y) ;
}
getch( );
}
# include <stdio.h>
# include <conio.h>
main()
{
int m1, m2, m3, tot ;
float avg ;
- 42 -
clrscr() ;
Notes :
2) s witc h.. . cas e :
Syntax:
switch(variable)
- 44 -
{
case (value) : (statements) ;
case (value) : (statements) ;
default : (statements) ;
}
break :
This keyword stops the execution in the given block and
come out. Generally this is used in switch..case
statements and looping
Statements.
Ex Programs :
21)
# include <stdio.h>
# include <conio.h>
main()
{
int k ;
clrscr() ;
- 45 -
switch(k)
{
case 0 : printf(\n Number is zero );
case 1 :
case 2 :
case 3 :
case 4 : printf(\n Number is less than five ) ;
break ;
case 5 : printf(\n Number is five );
break ;
default : printf(\n Number is greater than five ) ;
}
getch() ;
}
22)
# include <stdio.h>
- 46 -
# include <conio.h>
main()
{
char k;
clrscr() ;
break ;
default : printf(\n You are timid ) ;
}
getch() ;
}
23)
# include <stdio.h>
# include <conio.h>
main()
{
int a, b, k ;
clrscr() ;
printf(\n) ;
switch(k)
{
case 1 : printf( The addition %d, a+b) ; break ;
case 2 : printf( The subtraction %d, a-b) ; break ;
case 3 : printf( The multiplication %d, a*b); break
;
case 4 : printf( The division %d, a/b); break ;
default : printf( Invalid choice );
}
getch() ;
}
Notes :
3) Conditional Expressions : ( ? : ; )
Syntax :
(condition) ? (statement1) : (statement2) ;
Ex Programs :
24)/* Write a program to check whether the given
number is zero or not */
- 49 -
# include <stdio.h>
# include <conio.h>
main()
{
int k;
clrscr() ;
main()
{
int a, b, c, t ;
clrscr() ;
Notes :
gotoxy() :
This function locates the cursor position to the given place
on the screen. This functions prototype has defined in the
header file CONIO.H
- 51 -
Syntax:
gotoxy(column, row) ;
Generally in MS-DOS mode the screen contains 80
columns and 25 rows.
Ex Programs :
26)
# include <stdio.h>
# include <conio.h>
main()
{
clrscr() ;
gotoxy(20, 3) ;
printf(Hello );
gotoxy(70, 5);
printf(Bhanodaya ) ;
gotoxy(35,12);
printf(Welcome );
gotoxy(50,20);
printf(To smile );
getch() ;
}
- 52 -
Notes :
goto :
This command changes the execution control to the given
statement.
Syntax:
goto (label) ;
(label) :
(statements) ;
Ex Programs :
27)
# include <stdio.h>
# include <conio.h>
main()
{
clrscr() ;
printf(Hello ) ;
printf(World ) ;
goto abc ;
printf(Go out ) ;
xyz :
printf(To smile ) ;
- 53 -
goto end ;
abc :
printf(Welcome ) ;
goto xyz ;
end :
getch() ;
}
/* Output :
Hello World Welcome To smile */
Note :
Looping Statements :
Repeating a block of statements number of times is called
Looping.
There are three types of looping statements defined in C
language.
1) do..while, 2) while, 3) for.
Note :
The keyword goto cn be also used to repeat a block of
statements number of times.
Ex Programs :
28)
- 54 -
# include <stdio.h>
main()
{
abc :
printf(Welcome ) ;
goto abc ;
}
main()
{
int k ;
clrscr() ;
k=1;
abc :
printf(%d , k) ;
k++ ;
if(k<=10) goto abc ;
- 55 -
getch() ;
}
Notes :
1) do ... while() :
Syntax :
do
{
(statements);
} while(condition) ;
- 56 -
Ex Programs :
30) /* Write a program to display the first 10 natural
numbers */
# include <stdio.h>
# include <conio.h>
main()
{
int k ;
clrscr() ;
k=1;
do
{
printf(%d , k) ;
k++ ;
}while(k<=10) ;
getch() ;
}
- 57 -
# include <stdio.h>
# include <conio.h>
main()
{
int k, n, s ;
clrscr() ;
Notes :
There is a draw-back in do.. while() staement. It executes
the conditional statement after executing the statement.
2) while() :
Syntax:
while(condition)
{
(statements);
}
Ex Programs :
32) /* Write a program to display the first 10 natural
numbers */
# include <stdio.h>
# include <conio.h>
main()
{
int k ;
clrscr() ;
k=1;
- 59 -
while(k<=10)
{
printf(%d , k) ;
k++ ;
}
getch() ;
}
main()
{
int k, n, s ;
clrscr() ;
while (k<=10)
{
printf(%d , k) ;
s += k ;
k += 2 ;
}
/* I method */
# include <stdio.h>
# include <conio.h>
main()
{
- 61 -
int n, k, s;
clrscr() ;
k = 1; s = 0;
while(k<=n)
{
if(n%k==0) s++;
k++ ;
}
if(s==2) printf(\n Number is Prime );
else printf(\n Number is not a Prime )
getch( );
}
/* II method */
# include <stdio.h>
# include <conio.h>
main()
{
int n, k, s;
clrscr() ;
- 62 -
k = 2; s = 0;
while(k<=n/2)
{
if(n%k==0) { s++; break ; }
k++ ;
}
if(s==0) printf(\n Number is Prime );
else printf(\n Number is not a Prime )
getch( );
}
# include <stdio.h>
# include <conio.h>
main()
{
long int a, b ;
- 63 -
int n, s, r ;
clrscr( );
printf(Enter any big number ); scanf(%ld, &a) ;
n = 0; s = 0; b = 0;
while(a>0)
{
n ++ ;
r = a % 10 ;
s += r ;
b = (b*10) + r ;
a /= 10 ;
}
Armstrong Number :
- 64 -
main()
{
int a, b, r, s ;
clrscr() ;
b = a ; s = 0;
while(a>0)
{
r = a % 10 ;
s = pow(r, 3); /* s += r * r * r ; */
a /= 10;
}
- 65 -
Notes :
3) for() :
Syntax:
for ( initialisation ; condition ; iteration )
{
(statements) ;
Ex Programs :
37)
/* Write a program to display the odd
numbers upto the given number */
# include <stdio.h>
- 66 -
# include <conio.h>
main()
{
int n, a ;
clrscr() ;
/* n = 1 ;
for ( ; a>=n ; )
{
printf(%d , n);
n += 2 ;
}
*/
getch() ;
}
- 67 -
38)
/* Write a program to display the even numbers upto
the given number
and find the sum of them */
# include <stdio.h>
# include <conio.h>
main()
{
int a, n, s ;
clrscr() ;
s=0;
for(n=2; n<=a; n+=2)
{
printf(%d , n );
s += n;
}
*/
# include <stdio.h>
# include <conio.h>
main()
- 69 -
{
int a, n, s, odd, even ;
clrscr() ;
n! = n * (n-1) !
*/
- 70 -
# include <stdio.h>
# include <conio.h>
main()
{
long int a, f ;
clrscr() ;
/* f = 1 ;
for( ; a>1 ;)
{
f *= a ;
a -- ;
}
*/
41)
- 71 -
main()
{
int n, k;
clrscr() ;
getch() ;
}
main()
{
int k ;
clrscr() ;
/* k=0;
do
- 73 -
{
printf(\t %d %c, k, k) ;
k ++ ;
if(k%50==0) getch() ;
} while(k<=255 ) ;
*/
/* k = 0 ;
while(k<=255)
{
printf(\t %d %c, k, k) ;
k ++ ;
if(k%50==0) getch() ;
}
*/
for(k=0; k<=255; k++)
{
printf(\t %d %c, k, k) ;
if(k%50==0) getch() ;
}
getch() ;
}
- 74 -
Notes :
Nested Loops :
Looping in a loop is called Nesting of Loops.
Ex Programs :
44)
# include <stdio.h>
# include <conio.h>
main()
{
int n, k, j ;
clrscr() ;
printf(%d , j) ;
}
getch() ;
}
/* output :
45)
# include <stdio.h>
# include <conio.h>
main()
{
int n, k, j ;
clrscr() ;
- 76 -
/* output :
46)
# include <stdio.h>
# include <conio.h>
- 77 -
main()
{
int n, k, j ;
clrscr() ;
/* output :
1 2 3
1 2
1 */
47)
# include <stdio.h>
# include <conio.h>
main()
{
int n,j,k,a;
clrscr();
printf(%c,64+k);
for(k=1;k<=2*(a-n)-1;k++)
printf( );
k=(a==n)?n-1:n;
for (;k>=1;k--)
printf(%c,64+k);
}
getch();
}
/* Output :
Enter any number 5
ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
A A */
48)
/* Write a program to display the multiplication tables
upto
the given number */
# include <stdio.h>
# include <conio.h>
- 80 -
main()
{
int a, n, k ;
clrscr() ;
49)
/* Write a program to display the list of Prime
numbers upto
the given number */
# include <conio.h>
- 81 -
# include <stdio.h>
main()
{
int a, n, k, s ;
clrscr() ;
getch() ;
}
Fibonacci Series : 0, 1, 1, 2, 3,
5, 8, 13, 21, 34, 55, ....
In this series every element is the
sum of its previous two numbers */
/* Output :
Enter box length 10
Enter box width 5
Enter any character *
* * * * * * * * * *
* *
* *
* *
* * * * * * * * * *
*/
Notes :
Arrays :
- 83 -
# include <conio.h>
# include <stdio.h>
main()
{
- 84 -
int k, a[5] ;
clrscr() ;
/* Output: 7 7 7 7 7 */
# include <conio.h>
# include <stdio.h>
main()
{
int k, a[5] ;
- 85 -
clrscr() ;
55)
/* Write a program to accept 5 numbers print all, and
find the sum of them */
# include <conio.h>
# include <stdio.h>
main()
{
int k, s, a[5] ;
clrscr() ;
scanf(%d, &a[k]) ;
printf(\n The array elements are \n) ; for(k=0; k<5;
k++)
printf(%d , a[k]) ;
printf(\n The sum of elements is %d, s) ; getch() ;
}
main()
{
int k, a[10] ;
clrscr() ;
Notes :
2) Multi Dimensional Arrays :
Ex:
int a[5][3], b[4][5][6][7], .....
char na[3][20] = { abcdefgh, ramakrishna,
Bhanodaya };
A multi dimensional array is a collection of another arrays.
That means a double dimensional array is a collection of
single dimensional arrays.
Ex:
The array a[5][3] is a collection of 5 single dimensional
arrays with size 3.
Ex Programs :
57)
- 88 -
main()
{
int k, j, a[5][5] ;
clrscr() ;
output:
7 7 7 7 7
for(k=0; k<=4; k++)
7 7 7 7 7
{
printf(\n);
for(j=0; j<=4; j++)
printf(%d , a[k][j] );
- 89 -
getch() ;
}
58)
main()
{
(same as above)
for(k=0; k<5; k++)
for(j=0; j<5; j++)
a[k][j] = (k==j || k+j==4) ? 7 : 0;
(same as above)
}
/* Output :
70007
07070
00700
07070
70007 */
- 90 -
59)
main()
{
(same as above)
for(k=0; k<5; k++)
for(j=0; j<5; j++)
a[k][j] = (k==0 || k==4 || j==0 || j==4) ? 7 : 0;
(same as above)
}
/* Output :
77777
70007
70007
70007
7 7 7 7 7 */
# include <conio.h>
main()
{
char ch, a[25][80] ;
int k, j, len, w ;
clrscr() ;
printf(%c , a[k][j] );
}
getch() ;
}
/* Output :
* * * * * * * * * *
* *
* *
* *
* * * * * * * * * * */
main()
{
- 93 -
getch();
}
scanf(%d, &b[k][j] );
getch();
}
- 96 -
Notes:
STRINGS :
A string is an array of characters. It ends with a null
character. ( \0 ==> Null character )
Ex :
char na1[6] = { a, b,c, d, e, \0 } ;
char na2[6] = abcde ;
char names[][] = { rama, krishna, abcd } ;
char str1[20], str2[40] ;
Note :
The format string for a string variable is %s .
Ex programs :
63)
# include <stdio.h>
# include <conio.h>
main()
{
char str[80];
clrscr();
scanf(%s, str) ;
printf(\n You entered the string %s, str) ; getch() ;
}
/* Output :
Enter any string udaya bhanu
You entered the string udaya */
Notes :
scanf() function can accept the string values. But it does not
allow spaces in the string. To avoid this problem gets() can
be used.
gets() :
This function is used to accept the value for a string
variable. This functions prototype has defined in the
header file STDIO.H.
Syntax :
gets(varaible) ;
Ex :
gets(str) ;
puts() :
- 98 -
Ex Programs :
64)
# include <stdio.h>
# include <conio.h>
main()
{
char str[80] ;
clrscr() ;
printf(Enter any string ) ;
gets(str) ;
printf( You entered );
puts(str);
getch() ;
- 99 -
/* Output :
Enter any string udaya bhanu
You entered the string udaya bhanu */
65) /* Write a program to find the length of a string */
# include <stdio.h>
# include <conio.h>
main()
{
char str[80]; int k;
clrscr() ;
main()
{
char str[80] ; int k ;
clrscr() ;
}
/* Output :
Enter any string Udaya Bhanu
In upper case UDAYA BHANU */
main()
{
char str[80] ; int k ;
clrscr() ;
str[k] += 32 ;
/* Output :
Enter any string UDAYA BHANU
In upper case Udaya Bhanu */
# include <stdio.h>
# include <conio.h>
main()
{
char s[80], t[80] ;
- 103 -
int k;
clrscr() ;
printf(Enter the source string to copy ) ;
gets(s) ;
k=0;
while(s[k]!=\0)
{
t[k] = s[k] ;
k++ ;
}
t[k] = \0 ;
printf(\n The new string is %s, t) ;
getch() ;
}
main()
{
char a[80], b[80] ;
int k, j ;
- 104 -
clrscr() ;
main()
{
char a[80], b[80] ;
int k, j ;
clrscr() ;
printf(Enter any string ) ;
gets(a) ;
b[j] = \0 ;
printf(\n In reverse order %s, b) ;
getch();
}
/* Output :
Enter any string bhanodaya
In upper case ayadonahb */
# include <stdio.h>
# include <conio.h>
# include <string.h>
main()
{
int k, r, c, DL;
char str[80];
clrscr();
- 106 -
while(!kbhit())
{
for(r=1; r<=23; r++)
{
gotoxy(1,r); printf(%s, str);
delay(DL); clrscr();
}
for(c=1; c<=80-k; c+=3)
{
gotoxy(c,23); printf(%s, str);
delay(DL); clrscr();
}
for(r=23;r>0; r--)
{
gotoxy(80-k,r); printf(%s, str);
delay(DL); clrscr();
}
for(c=80-k;c>0; c-=3)
- 107 -
{
gotoxy(c,1); printf(%s, str);
delay(DL); clrscr();
}
}
}
main()
{
char na[80];
int r, c, k, n, DL;
clrscr();
}
- 109 -
main()
{
char str[20], a[25][20];
int k, j, n ;
clrscr( );
getch() ;
}
/* Output :
Enter Your name Bhanodaya
B h a n o d a y a
h y
a a
n d
o
d n
a a
y h
a y a d o n a h B
*/
- 111 -
Notes :
STRING.H functions :
Syntax :
strcpy(target, source) ;
5) strcat() :
This function adds two strings.
Syntax :
strcat(destination, second) ;
6) strrev() :
This function change the given string into reverse order.
Syntax :
strrev(string) ;
7) strcmp() :
This function compares two strings and returns zero when
both are same.
Syntax :
int strcmp(first, second) ;
Ex Programs :
77) /* Program to demonstrate the library functions of
STRING.H */
# include <stdio.h>
# include <conio.h>
# include <string.h>
- 113 -
main()
{
char a[80], b[80] ;
clrscr() ;
printf(Enter a string ) ;
gets(a) ;
/* Output :
Enter a string Bhanodaya
- 114 -
FUNCTIONS :
The function is a piece of code. These functions are used to
reduce the repetition of coding.
The functions are two types.
1) Derived functions,
2) User-defined functions.
(datatype) (functionname)
(arguments) /* Function definition */
{
(statements) ;
}
78)
# include <stdio.h>
# include <conio.h>
void first(void) ;
- 117 -
void second(void) ;
void third(void)
{
printf(\n This is in third function ) ;
}
void fourth(void)
{
printf(\n This is in fourth function ) ;
}
void main()
{
clrscr() ;
printf(This is in Main ) ;
first() ;
second() ;
third() ;
fourth() ;
printf(\n This is in main again ) ;
getch() ;
}
void first(void)
{
- 118 -
void second(void)
{
printf(\n This is in second function ) ;
}
/* Output :
This is in Main
This is in first function
This is in second function
This is in third function
This is in fourth function
This is in mainagain */
79)
# include <stdio.h>
# include <conio.h>
void replicate(void)
{
int k;
for(k=1; k<=50; k++)
printf(*) ;
- 119 -
void main()
{
clrscr() ;
replicate() ;
printf(\n Hello \n) ;
replicate() ;
printf(\n World \n) ;
replicate() ;
printf(\n Welcome \n) ;
replicate() ;
getch();
}
/* Output :
Hello
World
Welcome
*/
- 120 -
void main()
{
clrscr() ;
replicate(30,*) ;
printf(\n Hello \n) ;
replicate(60,#) ;
printf(\n Bhanodaya \n) ;
replicate(50,%) ;
printf(\n Welcome \n) ;
replicate(40,@) ;
getch();
}
- 121 -
/* Output :
Hello
Bhanodaya
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%
Welcome
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@
*/
81)
# include <stdio.h>
# include <conio.h>
void main()
{
int a, b ;
clrscr() ;
getch() ;
}
void subtr(p, q)
- 123 -
int p, q ;
{
int r ;
r=p-q;
printf(\n The subtraction %d , r) ;
}
- 124 -
int main()
{
int a, b, c ;
clrscr() ;
- 125 -
83) Important :
/* Program to demonstrate all types of functions
*/
# include <stdio.h>
# include <conio.h>
int main()
{
looping() ;
return 0;
}
- 127 -
void looping()
{
char ch = y ;
while(ch==y || ch==Y)
{
clrscr() ;
condition() ;
gotoxy(45, 22) ;
printf( Do you want to cotinue (y/n) ) ;
ch = getche ();
}
}
void condition()
{
int a, b, k;
printf(\n Enter any two numbers \n) ;
scanf(%d%d, &a, &b) ;
gotoxy(30, 5) ;
printf(1. Addition );
gotoxy(30, 6) ;
printf(2. Subtraction ) ;
gotoxy(30, 7) ;
printf(3. Multiplication ) ;
- 128 -
gotoxy(30, 8) ;
printf(4. Division ) ;
gotoxy(30, 10 );
printf(Enter Your choice ) ;
scanf(%d, &k) ;
gotoxy(10, 15);
switch(k)
{
case 1 : add(a, b) ; break ;
case 2 : printf( The subtraction %d, subtr(a,b) );
break ;
case 3 : mult(a,b ); break ;
case 4 : printf( The division %d, div(a,b) ) ;
break;
default : printf( Invalid choice ) ;
}
}
{
int z = x - y;
return z ;
}
Notes :
PREPROCESSOR COMMANDS :
The commands which start with hash (#) are called
Preprocessor
Commands.
- 130 -
Ex :
# define PI 3.14159
# include <stdio.h>
# include conio.h
# define A 1.7
- 131 -
define :
This command is used to define our own constants and
macros.
Ex Programs :
84)
# include <stdio.h>
# include <conio.h>
# define MN main()
# define pf printf
# define cls clrscr()
# define wait getch()
# define sf scanf
# define PI 3.14159
# define msg Enter the radius of circle
# define area(g) PI*g*g
# define per(g) 2*PI*g
MN
{
float r ;
cls ;
pf(msg) ;
- 132 -
sf(%f, &r) ;
pf(\n The area of circle is %f, area) ; pf(\n The
perameter of circle %f, per ) ; wait ;
}
Notes :
include :
This command is used to include the files which contains
the definition
of functions.
There are two types to include the files.
1) # include < name >
This type of command includes the file which is
located in the
specified directory. These specifications are set by
selecting
the Directories command from Options menu.
2) # include name
This type of command includes the file which is
located in the
current directory and/or in the specified directory.
- 133 -
Ex Programs :
85)
/* Save this progam as SUB.C */
# include <stdio.h>
# include <conio.h>
int main()
{
int a, b, c ;
clrscr() ;
printf(Enter any two numbers \n );
scanf(%d%d, &a, &b) ;
c = add(a, b) ; printf(\n The addition is %d, c );
printf(\n The subtraction %d, subtr(a,b) ) ;
c = mult(a,b) ; printf(\n The multiplication %d,
mult(a,b) ); printf(\n The division %d, div(a,b) );
getch() ;
return 0;
}
Notes :
STORAGE CLAUSES :
type is auto.
Ex Programs :
86)
# include <stdio.h>
# include <conio.h>
main()
{
auto int k;
{
int k = 5 ; output :
{
auto int k = 20 ;
clrscr() ;
printf(\n %d, k );
20
}
5
}
printf(\n %d, k ); 456
getch() ;
}
- 137 -
87)
# include <stdio.h>
# include <conio.h>
main()
{
int k ;
clrscr() ;
printf(%d \n, k) ;
for(k=1; k<=5; k++)
display() ;
getch() ;
}
display()
{
auto int k = 20 ;
printf( %d , k);
k += 3 ;
}
/* Output :
- 138 -
4567
20 20 20 20 20 */
Notes :
2) register :
This keyword stores the variable in CPU registers. It
assigns a junk(garbage) value to the variable. In CPU
registers it cant store more and big values like floats,
doubles,..etc. It can store Only chars and integers. These
variables are also local that means the variables which
declared in a block are available in that block only.
Generally these variables are used to generate the looping
statements.
Ex Programs
88)
# include <stdio.h>
# include <conio.h>
main()
{
register int k ;
clrscr() ;
- 139 -
printf(%d \n, k );
for(k=1; k<=100; k++)
printf(%d , k) ;
getch() ;
}
Notes :
3) static :
This keyword stores the variable in memory device. It
initialises the
variable as 0. The scope of variable is local that means
the variables which declared in a block are available in
that block
only. But it does not destroy the variables value when
end that block.
It takes the previous value when the controller entered
into that
block again.
Ex Programs :
89)
- 140 -
# include <stdio.h>
# include <conio.h>
main()
{
static int k ;
clrscr() ;
printf(%d \n, k) ;
for(k=1; k<=5; k++)
display() ;
getch() ;
}
display()
{
static int k = 20 ;
printf( %d , k);
k += 3 ;
}
/* Output :
0
20 23 26 29 32 */
- 141 -
Notes :
4) extern :
This keyword stores the variable in memory device. It
initialises the
variable as 0. The scope of variable is global. This variable
is
declared before the main() . The variables value can be
changed
in the functions.
- 142 -
Ex Programs :
90)
# include <stdio.h>
# include <conio.h>
int k ;
main()
{
clrscr() ;
printf(\n %d, k) ;
k=5;
disp1() ;
disp2() ;
printf(\n %d, k) ;
getch() ;
}
disp1()
{
printf(\n %d, k );
k += 3 ;
}
disp2()
- 143 -
{
int k = 20 ;
printf(\n %d, k );
disp3() ;
}
disp3()
{
printf(\n %d, k );
}
/* Output
0 5 20 8 8 */
- 144 -
Notes :
STRUCTURES :
A structure is a collection of variety of data type elements.
This is created with the keyword struct.
struct (name)
{
(elements declaration);
} ;
2) struct employee
{
int eno;
char ename[80];
- 145 -
float bas;
} emp = { 5, rama, 5600 } ;
3) struct
{
int eno;
char ename[80];
float bas;
} emp = { 5, rama, 5600 } ;
- 146 -
Ex Programs :
91)
# include <stdio.h>
# include <conio.h>
main()
{
struct book
{
int pages;
char title[40] ;
float price ;
} ;
92)
# include <stdio.h>
# include <conio.h>
- 147 -
main()
{
struct book
{
int pages;
char title[40] ;
float price ;
} ;
struct book bk ;
clrscr() ;
93)
/* Array of Structures */
# include <stdio.h>
# include <conio.h>
main()
{
struct book
{
int pages;
char title[40] ;
float price ;
} ;
int k ;
struct book bk[3] = { { 500,
Let us C, 175 },
{ 350, Graphics under C, 235 } ,
{ 800, Datastructures through C and C++ , 350 }
} ;
clrscr() ;
- 149 -
# include <stdio.h>
# include <conio.h>
struct book
{
int pages;
char title[40] ;
float price ;
} ;
main()
{
struct book bk = { 500, Let us C, 175 } ;
clrscr() ;
- 150 -
dispstrct(struct book b)
{
printf(\n The title of book %s, b.title);
printf(\n The number of pages %d, b.pages);
printf(\n The price of book %f, b.price );
}
struct book
- 151 -
main()
{
struct shop sh = { Udaya Book world , Chintal ,
{ 1200, Test your skills in C,
175 } ,
{ 50, Reynolds, 12 }
} ;
clrscr() ;
printf(\n The shop name %s , sh.name ) ; printf(\n
The shop address %s , sh.street);
printf(\n\n The book title %s , sh.bk.name ) ;
printf(\n The number of pages in the book
%d,sh.bk.pages ) ; printf(\n The cost of each book
%.2f , sh.bk.price ) ;
- 152 -
Notes :
POINTERS
This topic is the most important in C.
To use any variable it must be declared with its data type
before the first executable statement. By declaring a
variable the compiler reserves the required space in
memory between 64 kb and 128 kb. Every cell has a
unique address in memory. This address is a number,that is
an integer.
The variables stored in the memory can be accessed with
their addresses using pointers.To access with pointers we
have to use two new operators.
& ==> Address of
* ==> Value at address of
Ex :
int a = 5;
a ==> 5
&a ==> 65500
*(&a) ==> 5
Ex Programs :
97)
# include <stdio.h>
# include <conio.h>
main()
{
int k, *p, **q ;
clrscr() ;
k = 7; p = &k; q = &p;
printf(The value of k is %d, k) ; printf(\n The
address of k is %u, &k); printf(\n The value at
address %u is %d, &k, *(&k) ) ;
printf(\n The value of P is %u, p) ; printf(\n The
value at address %u is %u, &p, *(&p) ) ;
printf(\n The value at address %u is %d, p, *p );
printf(\n The value of q is %u, q) ; printf(\n The
value at address of %u is %u, &q, *(&q) ) ;
printf(\n The value at address %u is %u, q, *q);
printf(\n The integer value is %d, *(*q) ) ;
getch() ;
}
- 155 -
/* Output :
The value of k is 7
The address of k is 65524
The value at address 65524 is 7
The value of P is 65524
The value at address 65522 is 65524
The value at address 65524 is 7
The value of q is 65522
The value at address of 65520 is 65522
The value at address 65522 is 65524
The integer value is 7 */
98)
# include <stdio.h>
# include <conio.h>
main()
{
int a, *ap ;
float b, *bp ;
char c, *cp ;
clrscr() ;
- 156 -
Notes :
Pointers in Functions :
The functions can be send some arguments to the
definition and may
take a return value. If the value of these variables
changed in the
functions that does not effected to the function calling.
To change the value after calling the function the values
can be send by reference. That means the address of the
variable can be send to change the value.
Ex Programs :
98) /* Write a program to interchange the values of two
variables using
- 157 -
functions
A) CALL BY VALUE : */
# include <stdio.h>
# include <conio.h>
main()
{
int a=20, b=30 ;
clrscr() ;
swap(int x, int y)
{
int t ;
t = x; x = y ; y = t ;
printf(\n\n After swapping \n);
printf( x = %d, y = %d, x, y);
}
- 158 -
/* Output :
a = 20 b = 30
x = 30 y = 20
a = 20 b = 30 */
B) CALL BY REFERENCE :
# include <stdio.h>
# include <conio.h>
main()
{
int a=20, b=30 ;
clrscr() ;
{
int t ;
t = *x; *x = *y ; *y = t ;
printf(\n\n After swapping \n);
printf( x = %d, y = %d, *x, *y);
}
/* Output :
a = 20 b = 30
x = 30 b = 30
a = 30 b = 20
*/
Notes :
Arrays with Pointers :
An array is a collection of similar data type elements
mentioning with a single variable. The address of first
element is considered the address of the array. The array
elements can be accessed using the address of array and the
index value.
Ex Programs :
q)
# include <stdio.h>
- 160 -
# include <conio.h>
main()
{
int k, a[5] = { 10, 20, 30, 40, 50 } ;
clrscr() ;
for(k=0; k<5; k++)
{
printf(\n the addres of %d element %u %u, k,
&a[k], a+k ) ;
printf(the value is %d %d %d %d, a[k], *(a+k),
*(k+a), k[a] ) ;
}
getch () ;
}
q)
# include <stdio.h>
# include <conio.h>
main()
{
int *a, n ;
- 161 -
clrscr() ;
getch() ;
}
printf(%d , *(p+k) ) ;
}
q)
# include <stdio.h>
# include <conio.h>
# define M 5
main()
{
int a[M] ;
clrscr() ;
accept(a, M) ;
display(a, M) ;
getch() ;
}
Notes :
malloc() :
This function is used to allocate the required space in the
memory while executing the program. This functions
prototype was defined in the header file ALLOC.H
There is an another function to allocate memory. that is
calloc().
The malloc() assigns junk values the allocated space. But
calloc() assigns 0 to the allocated space.
Syntax:
(pointer) = (pointertype) malloc( size * number) ;
(pointer) = (pointertype) calloc( size , number ) ;
Note :
- 164 -
main()
{
int *p, n, k, s;
clrscr() ;
scanf(%d, p+k );
printf(\n The elements are \n) ;
for(k=0; k<n; k++)
printf(%d , p[k] );
main()
{
int *p, n;
clrscr() ;
if(p==NULL)
{
printf(\n Unable to allocate the required space ) ;
exit(0);
}
accept(p, n) ;
linear(p, n) ; /* bubble(p, n) ; */
display(p, n) ;
getch() ;
}
t = *(a+k) ;
*(a+k) = *(a+j) ;
*(a+j) = t ;
}
}
Notes :
String Pointers to Functions :
Ex Programs :
# include <stdio.h>
# include <conio.h>
# include <string.h>
# include <dos.h>
- 170 -
void main()
{
char *str = Bhanodaya is a
super hero ;
clrscr();
while(!kbhit())
{
substr(str); delay(100);
gotoxy(20, 12); printf(%s,str);
}
getch();
}
/*
substr(char *str)
{
char *dst, c; int i=1, j=0;
c = *str;
while(*(str+i)!=\0)
{
*(dst+j) = *(str+i);
i++; j++;
}
- 171 -
*(dst+j) = c;
*(dst+j+1) = \0;
strcpy(str,dst);
}
*/
substr(char str[])
{
char dst[80], ch ;
int k, j ;
ch = str[0] ;
k=1; j=0;
while(str[k]!=\0)
{
dst[j] = str[k] ;
k++; j++;
}
dst[j++] = ch ;
dst[j] = \0 ;
strcpy(str, dst) ;
}
Notes :
- 172 -
struct book
{ int pages; char title[40]; float price ; } ;
main()
{
struct book bk = { 500, Pointers in C, 175.00 } ;
struct book *b ;
clrscr() ;
b = &bk ;
printf(\n The book title %s , bk.title ) ; printf(\n
The number of pages %d , bk.pages ) ; printf(\n
The cost of book %.2f , bk.price ) ;
- 173 -
struct book
{ int pages; char title[40]; float price ; } ;
main()
{
struct book bk = { 500, Pointers in C, 175.00 } ;
clrscr() ;
dispvar(bk) ;
disppntr(&bk) ;
getch() ;
- 174 -
Notes :
FILE HANDLING IN C
- 175 -
fclose() :
- 176 -
Ex Programs :
main()
{
FILE *fp ;
char ch ;
fp = fopen(DATA, w) ;
if(fp==NULL)
{
printf(\n Unable to open the given file ) ;
exit(0) ;
}
while(1)
{
ch = getchar();
if(ch==EOF) break ;
- 178 -
fputc(ch, fp) ;
}
fclose(fp) ;
}
main()
{
FILE *fp ;
char ch ;
clrscr() ;
fp = fopen(DATA, r) ;
if(fp==NULL)
{
printf(\n File not found ) ;
exit(0) ;
}
- 179 -
while(1)
{
ch = fgetc(fp);
if(ch==EOF) break ;
putchar(ch) ;
}
fclose(fp) ;
getch() ;
}
main()
{
FILE *fp ;
char ch ;
- 180 -
clrscr() ;
fp = fopen(data, r) ;
if(fp==NULL)
{
printf(\n File not found ) ;
exit(0) ;
}
while(1)
{
ch = fgetc(fp);
if(ch==EOF) break ;
if(ch>=97 && ch<=122) ch -= 32 ;
putchar(ch) ;
}
fclose(fp) ;
getch() ;
}
# include <stdlib.h>
main()
{
FILE *fs, *ft ;
char ch, *src, *trg ;
clrscr() ;
printf(Enter the source file to copy ) ;
scanf(%s, src) ;
fs = fopen(src, r) ;
if(fs==NULL)
{
printf(\n Source File not found ) ;
exit(0) ;
}
while(1)
{
ch = fgetc(fs);
if(ch==EOF) break ;
if(ch>=97 && ch<=122) ch -= 32 ;
putchar(ch) ;
fputc(ch, ft) ;
}
fclose(fs) ; fclose(ft) ;
getch() ;
}
Notes :
fprintf() :
This function stores the data in the file.
Syntax :
fprintf(filepointer, format string, variables);
Ex :
fprintf(fp, %d %s %f, eno, ena, bas);
- 183 -
fscanf() :
This function reads the data from the file.
Syntax :
fscanf(filepointer, format string, variables);
Ex :
fscanf(fp, %d%s%f, &eno, ena, &bas);
Ex Programs :
q)/* Write a program to create a data file EMP.DAT,
accept employee number,
name, basic salary and store all in the data file */
# include <conio.h>
# include <stdio.h>
# include <stdlib.h>
main()
{
FILE *fp ;
int eno; char ena[40]; float bas ;
char ans=y ;
clrscr() ;
fp = fopen(EMP.DAT, w) ;
if(fp==NULL)
- 184 -
{
printf(\n Unable to open in the required mode ) ;
exit(0) ;
}
while(ans==y || ans==Y)
{
printf(\n Enter Employee Number ) ;
scanf(%d, &eno) ;
printf( Enter Employee Name ) ;
scanf(%s, ena) ;
printf( Enter Basic Salary ) ;
scanf(%f, &bas) ;
fprintf(fp, \n %d %s %f, eno, ena, bas) ;
printf(Do you want to
continue ) ;
ans = getche() ;
}
getch();
}
main()
{
FILE *fp ;
int eno; char ena[40];
float bas, da, hra, pf, net ;
clrscr() ;
fp = fopen(EMP.DAT, r) ;
if(fp==NULL)
{
printf(\n File not found ) ;
exit(0) ;
}
Notes :
fwrite() :
This function is used to store the structures in the file in
binary
mode.
Syntax:
fwrite ( (pointer to variable), (size of variable),
(numberofvariables),(filepointer) );
Ex:
fwrite( &emp, sizeof(emp), 1, fp);
- 187 -
fread() :
This function is used to read the structures from the file in
binary level.
Syntax: fread ( (pointer to
variable), (size of variable),
(numberofvariables),(filepointer) );
q)
# include <stdio.h>
# include <conio.h>
struct employee
{ int eno; char ena[20]; float bas ; } ;
main()
{
struct employee emp ;
FILE *fp ;
char ans ;
- 188 -
clrscr() ;
fp = fopen(empbn.dat, wb) ;
if(fp==NULL)
{
printf(Unable to open the data file ) ;
exit(0) ;
}
do
{
printf(\n\n Enter employee Number ) ;
scanf(%d, &emp.eno) ;
printf(Enter Employee Name ) ;
scanf(%s, emp.ena) ;
printf(Enter Basic Salary ) ;
scanf(%f, &emp.bas) ;
fwrite(&emp, 1, sizeof(emp), fp) ; printf(Do you
want to add more ) ;
ans = getche() ;
} while(ans==y || ans==Y) ;
}
- 189 -
q)
# include <stdio.h>
# include <conio.h>
struct employee
{ int eno; char ena[20]; float bas ; } ;
main()
{
struct employee emp ;
FILE *fp ;
clrscr() ;
fp = fopen(empbn.dat, rb) ;
if(fp==NULL)
{
printf(Unable to open the data file ) ;
exit(0) ;
}
q)
# include <stdio.h>
# include <conio.h>
struct employee
{ int eno; char ena[20]; float bas ; } ;
main()
{
struct employee emp ;
FILE *fs, *ft ;
clrscr() ;
fs = fopen(empbn.dat, rb) ;
if(fs==NULL)
{
printf(Unable to open the data file ) ;
exit(0) ;
- 191 -
ft = fopen(emp.dat, w) ;
if(ft==NULL)
{
printf(\n Unable to open the target file ) ;
exit(1);
}
Notes :
COMMAND LINE ARGUMENTS :
- 192 -
Syntax:
main(int argv, char *args[])
Ex Programs :
q) /* This program demonstrates about the arguments
passed to
the function main() */
# include <stdio.h>
void main(int argv, char *args[])
{
int k ;
printf(\n The number of arguments given %d,
argv) ;
printf(\n The arguments are \n) ;
for(k=0; k<argv; k++)
printf(\n %s, args[k] ) ;
- 193 -
# include <stdio.h>
# include <stdlib.h>
{
printf(\n Invalid number of arguments ) ;
exit(0) ;
}
fp = fopen(args[1], w) ;
if(fp==NULL)
{
printf(\n Unable to create the given file ) ;
exit(1) ;
}
while(1)
{
ch = getchar() ;
if(ch==EOF) break ;
fputc(ch, fp) ;
}
/*
- 195 -
# include <stdio.h>
# include <stdlib.h>
exit(0) ;
}
fp = fopen(args[1], r) ;
if(fp==NULL)
{
printf(\n File not found - %s, args[1] ) ;
exit(1) ;
}
while(1)
{
ch = fgetc(fp) ;
if(ch==EOF) break ;
putchar(ch) ;
}
# include <stdio.h>
# include <stdlib.h>
void main(int argv, char *args[])
{
FILE *fs, *ft ;
char ch ;
if(argv!=3)
{
printf(Invalid number of arguments );
exit(0) ;
}
fs = fopen(args[1], r) ;
if(fs==NULL)
{
printf(\n Unable to open the source file ) ;
- 198 -
exit(1) ;
}
ft = fopen(args[2],w) ;
if(ft==NULL)
{
printf(\n This target file %s not found , args[2] ) ;
exit(2) ;
}
Notes :
random() :
This function returns the value which is between 0 and 1
less than the given number. This functions prototype has
defined in the header file STDLIB.H
Syntax :
random(n);
This function returns any number from 0 to n-1 .
textattr() & textbackground() :
This function changes the text color to the given color.
- 200 -
GRAPHICS
Generally the screen is in textmode. It can be changed by
the display adopters. There are a number of adopters like
VGA, CGA,EGA, ...
The normal text mode has 25 rows and 80 columns. It can
be changed using the MODE command in MS-DOS.Using
C programs we can design some graphics by changing the
screen from text mode to graphics mode.
initgraph() :
This function changes the screen from text mode to
graphics mode. But here we have to mention the display
driver and mode. To use this command the file
EGAVGA.BGI must be in the current directory. This
functions prototype has defined in the header file
GRAPHICS.H
Syntax:
initgraph( (address of driver), (address of mode), (path to
file) );
Ex :
int gdr = DETECT, gmd;
initgraph(&gdr, &gmd, C:\TC );
- 201 -
detectgraph() :
This function detects the using graphic driver and modes. It
assign the values to the variables.
Syntax :
detectgraph( (address of graphic driver), (address of
graphic mode) );
Ex :
int gdr, gmd;
detectgraph(&gdr, &gmd);
closegraph() :
This function closes the graphics mode and changes to text
mode.
Syntax:
closegraph();
setcolor() :
This function changes the displaying color of screen. In
VGAHI we can use 16 colors. The color can be mentioned
as integer.
Syntax:
setcolor(integer) ;
- 202 -
Ex :
setcolor(RED) ;
setcolor(4) ;
setbkcolor() :
This function changes the background color of screen .
Syntax :
setbkcolor(integer) ;
Ex:
setbkcolor(YELLOW) ;
setbkcolor(15);
putpixel() :
This function highlights the pixel(picture element) at the
given co-ordinates to the given color .
Syntax :
putpixel(x-coordinate, y-coordinate, color) ;
Ex :
putpixel(320, 240, 5) ;
line() :
This function displays a line between the given coordinates.
Syntax :
- 203 -
circle() :
This function displays a circle with the given center
coordinates and the radius.
Syntax :
circle(x, y, radius) ;
Ex :
circle(320, 240, 100) ;
ellipse() :
Syntax :
- 204 -