238 Programming and Data Structures
Explanation In the above program a string is initialized with array name [ ]. The string is not
complete and contains blanks. The i f statement within the whi 1 e () loop checks every character of
the string. If blank space is found, i f block is executed and the user needs to enter a character.
Otherwise the next successive characters are displayed.
SUMM ARY
You have now learnt how to initialize an array by different ways .The Characteristics of array has
been discussed in depth. How to specify the elements of one-dimensional, two-dimensional and three
or multi dimensional arrays is explained in detail together with ample examples. The functions such
as the sscanf () and sprin t f () functions are demonstrated through examples. Perhaps this may be
the chapter in which the reader may find practical examples. The programmer should make an attempt
to execute all the programs so as to get expertise in arrays. Unless the unsolved problems are taken up
for solving the depth of the chapter would not be followed.
EXE R C ISES
A) A nswer the following questions.
1) Explain multi-dimensional array.
2) Array name contains base address of the array. Can we change the base address of the array?
3) What is the relation between an array name and an element number? How elements are referred
using base address?
4) Can we store values and addresses in the same array. Explain.
5) Mention the difference between character array and integer array.
B) A nsw er the following by selecting the appropriate option.
1) An array is a collection of
a) different data types. b) same data types,
c) both AandB.
2) Array elemets are stored in
a) scattered memory locations. b) sequential memory locations,
c) both (a) and (b).
3) A character array always ends with
a) null ('NO') character. b) question Mark (?).
c) full Stop (.).
4) If you declare array without stating the elements it will be set to
a) anull value. b) zero,
c) garbage Value.
5) Arrays can not be initalized if they are
a) automatic b) external
c) static d) none of the above
Arrays 239
6) All the elements in the array must be
a) initialized,
c) both (a) and (b)
b) defined
d) none of the abo
7) What will be the output of the following program?
# include <stdio.h>
# include <conio.h>
void main ()
{
int al [5] ={l};
int b=0,k=0;
clrscrO;
for (b=0;b<=4;b++)
{
printf ("% 3 d ",+ + a l[0 ]);
C) A ttem pt the following program s.
1) Write a program to read 10 integers in an array. Find the largest and smallest number.
2) Write a program to read a number containing five digits. Perform square of each digit. For
Example. Number is 45252. Output should be square of-each digit i.e. 16254254.
3) Write a program to read a number of any lengths. Perform the addition and subtraction on
largest and smallest digits of it.
4) Write a program to read three digits positive integer number 'n ' and generate possible
permutation of numbers using their digits. For example n=123 then the permutations are 123,
132, 213, 231,312,321.
5) Write a program to read the text. Find out number of lines in it.
6) Write a program to read any three characters. Find out all the possible combinations.
7) Write a program to enter string in lower as well as upper case. Convert lower to uppercase and
vice versa and display the string.
8) Read the marks of five subjects obtained by five students in an examination. Display the top
two student codes and their marks.
9) Write a program to enter five numbers using array and rearrange the array in the reverse order.
For Example numbers entered are 58324 and after arranging array elements must be 4 2 3 8 5.
10) Accept a text up to 50 words and perform following actions.
a) Count total vowels, consonants, spaces, sentences, and words with spaces.
b) Program should erase more than one space between two successive words.
HINT: Total number of sentences can be computed based on total number of
Full stops.
11) Evaluate the following series. Calculate every term and store its result in an array. Using array
calculate final result.
a) x= l 1+22+33+44..n
b ) x = l! + 2 ! + 3 ! + ... n
c) x = l!-2 !+3 !-....n
}
I
a) 2345 6
c) 1 11111
b) 12 3 4 5
d) 12 2 2 2 2
240 Programming and Data Structures
12) Refer the table given below. Write a program to calculate the bill amount of the stationary
articles. Use array for initializing items and their prices.
a)
Item Price (Rs.)
10th Book Set 850/-
12th Book Set
1150/-
Note books
Rate (Rs.)
100 Pages/Dozen
75/-
200 pages/Dozen
125/-
PEN SET
50/-
b) 15% discount if sets are more than 10 otherwise 10%.
c) 10% discount if notebooks are more than 10 dozen.
13) Consider the following table and write a program to find the total cost of the computer systems
using arrays. 10% discount is to be offered in case the total systems sold are more than 5 in
quantity. Display the code, parts of the system and price. User should enter the configuration
and quantity
Code no. Particulars
Price (Rs.)
1 Mother Board With Processor P3 600 MHz
3000/-
2
Mother Board With Processor P41000 MHz
8000/-
3
Hd (20 GB)
4000/-
4 Hd (90 GB)
8000/-
5
Ram (64 MB)
1000/-
6
Ram (128 MB)
2000/-
7 Cache (64 KB)
1000/-
8 Cache (128 KB)
1500/-
9 Fdd (1.44 MB)
1500/-
10
CD Rom Drive
3000/-
11 Caninet
400/-
12
Key Board
750/-
13 Mouse
200/-
14
Multimedia Kit
3000/-
15 Modem
1500/-
14) Enter the following information through the keyboard using multi-dimension arrays. Calculate
the salary of individuals and total salary of all the employees.
Arrays 241
Code no
Designation
Basic
DA Other perks
1
Manager
40000/-
50%
15%
2 Executive
20000/- 25% 20%
3
Senior Asst. 15000/- 25%
20%
4
Junior Asst. 10000/- 20%- 15%
5 Steno
8000/- 20% 10%
6
Clerk 5000/- 20% 10%
7
Peon 4000/- 20% 10%
15) Refer the table given below. Find the total bill amount using arrays. The user should have option
to enter the quantity of bulbs.
CODE NO.
Wattage of the bulb
Price/bulb (Rs.)
1
15 W
5/-
2
40 W
8/-
3
60 W
12/-
4
100 W
20/-
5
200 W
35/-
16) Write a program to display the different parameters of 10 men in a table. The different parameters
to be entered are height, weight, age, and chest in cms. Find the number of men who satisfy the
following condition.
a) Age should be greater than 18 and less than 25.
b) Height should be between 5.2 to 5.6 inches.
c) Weight should be in between 45 to 60 kg.
d) Chest should be greater than 45 cms.
17) Write a program to display the items that have been exported between 1995 to 2000. The table
should be displayed as follows. Input the amount of various items described as under.
a) Find the total and average export valueof all the items.
b) Find the year in which minimum and maximum export was made.
Items/Year 1995-96 1996-97 1997-98 1998-99 1999-2000
Coffee
Tea
Sugar
Milk powder
Zinger
18) Write a program to replace the zero with successive number in the following arrays.
a) int x[8] = {l , 0, 3, 0, 5, 0, 7, 0}
b) int y[8] = {-1, 0, -3, 0, -5, 0, -7, 0}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.156.93