212 Programming and Data Structures
char msgl] = "C is Easy";
inti = 0;
Q U m K i
C is Easy
Explanation A character array and integer variable are initialized. Array always begins with element
number 0. In case % i ' is not initialized with 0 result provides garbage value. Standard stdo u t ()
function prints the string on console. Here the string is "C i s Easy".
7.6 PREDEFINED STREAMS
Following are the streams
2. stdout ()
When C program is executed few "files" are automatically opened by the system for use by the
program. Constant FILE pointers recognize these files. Streams s td in , s tdou t and s t der r are
defined in the standard I/O include files. These are macros. Their details are illustrated in the chapter
12] PREPROCESSOR DIRECTIVES.
a) stdin The file pointer s tdin identifies the standard input text and it is associated with our terminal.
All standard I/O functions perform input and do not take a FILE pointer as an argument and get their
input from s tdin.
b) stdout Similarly, it is used for outputting the text. It is a standard output stream.
c) a tderr It is an output stream in the text mode. It is a standard error stream.
7.18 Write a program to read the text through keyboard and display it by using stdin and
char ch[ll] ;
printf("The Text inputted was");
Q U n ilL
Input a Text Hello World
The Text Entered was
Explanation In the above program two f o r loops are used. The first f o r loop reads input characters
from the keyboard and stores in an array ch [ 11 ] by using s td in standard function. The second for
loop displays the string using stdo ut standard function.
7.19 Write a program to sort the given strings alphabetically.
# include <8tdio.h>
# include <ctype.h>
# include <canio.h>
int i, j;
printf (“Enter Text Below
printf (“Sorted Text Below An");
if( textlj]=-toupper(i) I I text[j]==toloweiii))
Tips The tolower and toupper are the 'C' functions for conversion from lower to upper or vice versa
or convert numerical to its ASCII equivalent .For initializing these functions header file ctype.h is to
Enter Text Below:
Sorted Text Below:
Explanation ASCII equivalents of alphabets are used to sort out the given string. The standard
functions toupper () and tolower () in i f statement are used to ignore the case i.e. capital or small
214 Programming and Data Structures
letters are treated the same. If the character value given by f o r loop ' i ' andstring text  value '
denoted by f o r loop % j ' are same that value gets printed. Because the value of a character supplied
by the outer f o r loop are taken alphabetically. Hence, characters when matched gets printed.
7.20 Write a program to arrange the numbers in increasing and decreasing order (ascending
& descending order) using loops.
int i, j,suma>0,a;
printf ("Enter ten numbers z");
printf ("Numbers In Ascending Order:");
printf ("\nNumbers In Descending Order:");
Enter ten numbers :5214791012 93
Numbers In Ascending Order :123457991012
Numbers In Descending Order: 1210 99754321
Explanation In the above program ten numbers are entered through the keyboard in an array a [ 10 ].
In the same loop their sum is performed. The outer loop executes from 1 to variable 'sum'. Here,