Arrays in C | Chapter 6 | Class 10 Computer Science 571(NCERT) Question and Answer | Class 10 Computer Science 571(NCERT) Question and Answer Solutions English Medium |


Arrays in C

Chapter 6


Exercise


1. Define array. Why do we use arrays in computer programs?

(āĻā§°ে āύিā§°্āϧাā§°āĻŖ āϕ⧰āĻ•। āφāĻŽি āĻ•āĻŽ্āĻĒিāωāϟাā§° āĻĒ্ā§°'āĻ—্ā§°াāĻŽāϤ āĻā§°ে āĻ•িāϝ় āĻŦ্āĻ¯ā§ąāĻšাā§° āϕ⧰োঁ?)

Ans: We use arrays in computer programs because-In coding and programming, arrays are a collection of items, or data, stored in adjacent memory locations, also known as database systems. The purpose of an array is to store multiple pieces of data of the same type together.


2. Can we store both integer and float types of data in a single array? Demonstrate this by writing a simple C program.

(āφāĻŽি āχāĻŖ্āϟেāĻ—াā§° āφ⧰ু āĻĢ্āϞোāϟ āĻĒ্ā§°āĻ•াā§° āĻĻুāϝ়োāϧ⧰āĻŖā§° āĻĄাāϟা āĻāϟা āĻā§°েāϤ āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦ āĻĒাā§°োঁāύে? āĻāϟা āϏ⧰āϞ āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–ি āχāϝ়াāĻ• āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰āĻ•।)

Ans: We cannot store data in both integers and float types. 

In the above program, when array elements are taken as integers, the program prints the correct output. But if we take the input as a float value (e.g. 3.14,2.54,5.7,........) an error will occur.


3. Write the indices of the first and last element of the following array declaration. char city [7]=('S', T, 'L', 'C', 'H', 'A', 'R', };

(āύিāĻŽ্āύāϞিāĻ–িāϤ āĻā§°ে āϘোāώāĻŖাā§° āĻĒ্ā§°āĻĨāĻŽ āφ⧰ু āĻ…āύ্āϤিāĻŽ āωāĻĒাāĻĻাāύ⧰ āϏূāϚāĻ•āĻŦোā§° āϞিāĻ–āĻ•। āϚাā§° āϚিāϟি [7]=('āĻāĻ›', āϟি,'āĻāϞ', 'āϚি', 'āϚি', 'āĻāχāϚ', 'āĻ', 'āφ⧰', };)

Ans: Indices of the first element of the array is 0. and Indices of the last element of the array is 6.

( āĻā§°ে āϘোāώāĻŖাā§° āĻĒ্ā§°āĻĨāĻŽ  āωāĻĒাāĻĻাāύ⧰ āϏূāϚāĻ•āĻŦোā§° āĻš'āϞ ā§Ļ। āφ⧰ু āĻā§°ে āϘোāώāĻŖাā§° āĻ…āύ্āϤিāĻŽ āωāĻĒাāĻĻাāύ⧰ āϏূāϚāĻ•āĻŦোā§° āĻš'āϞ ā§Ŧ।)

4. Write a C program and declare an integer type array with capacity 7. Take input to the array from the keyboard. Display the 8th element of the array. Hint: display num[7] if num is the name of the array. Analyze the output.

(āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ• āφ⧰ু āĻ•্āώāĻŽāϤা 7-ā§° āϏৈāϤে āĻāϟা āχāĻŖ্āϟেāĻ—াā§° āĻĒ্ā§°āĻ•াā§°ā§° āĻā§°ে āϘোāώāĻŖা āϕ⧰āĻ•। āĻ•ীāĻŦোā§°্āĻĄā§° āĻĒā§°া āĻā§°েāϞৈ āχāύāĻĒুāϟ āϞāĻ“āĻ•। āĻā§°েā§° 8āĻŽ āωāĻĒাāĻĻাāύ āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰āĻ•। āχāĻ™্āĻ—িāϤ: āϏংāĻ–্āϝা āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰āĻ•[7] āϝāĻĻি āϏংāĻ–্āϝাāϟো āĻā§°েā§° āύাāĻŽ āĻšāϝ়। āφāωāϟāĻĒুāϟ āĻŦিāĻļ্āϞেāώāĻŖ āϕ⧰āĻ•।)

Ans: 


5. Write a C program and declare an integer type array with 7 elements in it. Display the address of the individual elements in the array.

(āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ• āφ⧰ু āχāϝ়াāϤ 7 āϟা āωāĻĒাāĻĻাāύ āĻĨāĻ•া āĻāϟা āχāĻŖ্āϟেāĻ—াā§° āĻĒ্ā§°āĻ•াā§°ā§° āĻā§°ে āϘোāώāĻŖা āϕ⧰āĻ•। āĻā§°েāϤ āĻĨāĻ•া āĻ—াāχāĻ—ুāϟীāϝ়া āωāĻĒাāĻĻাāύāĻŦোā§°ā§° āĻ িāĻ•āύা āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰āĻ•।)

Ans: To create an array, define the type of data (for example int) and specify the name of the array after the class brackets []. To include values here, use a less-varying list within curly braces: in my number[] = {25, 50, 75, 100};

(āĻā§°ে āĻāϟা āϏৃāώ্āϟি āϕ⧰িāĻŦāϞৈ, āĻĄাāϟাā§° āĻĒ্ā§°āĻ•াā§° āύিā§°্āϧাā§°āĻŖ āϕ⧰āĻ• (āωāĻĻাāĻšā§°āĻŖ āϏ্āĻŦā§°ূāĻĒে āχāĻŖ্āϟ) āφ⧰ু āĻļ্ā§°েāĻŖী āĻŦāύ্āϧāύীā§° āĻĒিāĻ›āϤ āĻā§°েā§° āύাāĻŽ āύিā§°্āĻĻিāώ্āϟ āϕ⧰āĻ• []। āχāϝ়াāϤ āĻŽাāύāĻ…āύ্āϤ⧰্āĻ­ুāĻ•্āϤ āϕ⧰িāĻŦāϞৈ, āĻ•োঁāĻ•āĻĄ়া āĻŦ্ā§°েāϛ⧰ āĻ­িāϤ⧰āϤ āĻāĻ• āĻ•āĻŽ-āĻĒā§°িā§ąā§°্āϤāύāĻļীāϞ āϤাāϞিāĻ•া āĻŦ্āĻ¯ā§ąāĻšাā§° āϕ⧰āĻ•: āχāĻŖ্āϟ āĻŽাāχāύāĻŽ্āĻŦā§°[] = {25, 50, 75, 100};)


6. Write a C program and declare two integer type arrays, each with capacity 7. Take input only to the first array. Write a loop to copy the elements of the first array to the second one. Display the elements of the second array.

(āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ• āφ⧰ু āĻĻুāϟা āχāĻŖ্āϟিāĻ—াā§° āĻĒ্ā§°āĻ•াā§°ā§° āĻā§°ে āϘোāώāĻŖা āϕ⧰āĻ•, āĻĒ্ā§°āϤিāϟো āĻ•্āώāĻŽāϤা 7 ā§° āϏৈāϤে। āχāύāĻĒুāϟ āĻ•েā§ąāϞ āĻĒ্ā§°āĻĨāĻŽ āĻā§°েāϞৈ āϞৈ āϝাāĻ“āĻ•। āĻĒ্ā§°āĻĨāĻŽ āĻā§°েā§° āωāĻĒাāĻĻাāύāĻŦোā§° āĻĻ্āĻŦিāϤীāϝ়āϟোāϞৈ āĻĒ্ā§°āϤিāϞিāĻĒি āϕ⧰িāĻŦāϞৈ āĻāϟা āϞুāĻĒ āϞিāĻ–āĻ•। āĻĻ্āĻŦিāϤীāϝ় āĻā§°েā§° āωāĻĒাāĻĻাāύāĻŦোā§° āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰āĻ•।)

Ans: 


7. Write a strategy to find the summation of all the even numbers stored in an array. Write a C program for the same. If the array elements are (1, 2, 4, 3, 5, 6, 7, 7, 8), the output of the program will be 20.

āĻā§°েāĻāϟাāϤ āϏāĻž্āϚিāϤ āϏāĻ•āϞো āϏāĻŽাāύ āϏংāĻ–্āϝাā§° āϏাā§°াংāĻļ āĻŦিāϚাā§°িāĻŦāϞৈ āĻ•ৌāĻļāϞ āĻāϟা āϞিāĻ–āĻ•। āχāϝ়াā§° āĻŦাāĻŦে āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•। āϝāĻĻি āĻā§°ে āωāĻĒাāĻĻাāύāĻŦোā§° (1, 2, 4, 3, 5, 6, 7, 7, 8) āĻšāϝ়, āĻĒ্ā§°'āĻ—্ā§°াāĻŽāϟোā§° āφāωāϟāĻĒুāϟ āĻš'āĻŦ 20।

Ans:


8. Write a strategy to find the summation of all the even positioned numbers stored in an array. Write a C program for the same. If the array elements are {1, 2, 4, 3, 5, 6, 7, 7, 8), the output of the program will be 18.

āĻā§°েāĻāϟাāϤ āϏāĻž্āϚিāϤ āϏāĻ•āϞো āϏāĻŽাāύ āĻ…ā§ąāϏ্āĻĨাāύāϝুāĻ•্āϤ āϏংāĻ–্āϝাā§° āϏাā§°াংāĻļ āĻŦিāϚাā§°িāĻŦāϞৈ āĻ•ৌāĻļāϞ āĻāϟা āϞিāĻ–āĻ•। āχāϝ়াā§° āĻŦাāĻŦে āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•। āϝāĻĻি āĻā§°ে āωāĻĒাāĻĻাāύāĻŦোā§° {1, 2, 4, 3, 5, 6, 7, 7, 8 āĻšāϝ়, āĻĒ্ā§°'āĻ—্ā§°াāĻŽāϟোā§° āφāωāϟāĻĒুāϟ āĻš'āĻŦ 18।

Ans:


9. Write the logic to replace only the first occurrence of an element in an array. For example, if the array elements are {1, 2, 3, 4, 5, 1, 2, 3] and we want to replace element 3 by 0, the array content becomes {1, 2, 0, 4, 5, 1, 2, 3). Write a complete C program incorporating the logic.

āĻā§°ে āĻāϟাāϤ āĻ•েā§ąāϞ āĻāϟা āωāĻĒাāĻĻাāύ⧰ āĻĒ্ā§°āĻĨāĻŽ āϘāϟāύাāϏāϞāύি āϕ⧰িāĻŦāϞৈ āϝুāĻ•্āϤি āϞিāĻ–āĻ•। āωāĻĻাāĻšā§°āĻŖ āϏ্āĻŦā§°ূāĻĒে, āϝāĻĻি āĻā§°ে āωāĻĒাāĻĻাāύāĻŦোā§° {1, 2, 3, 4, 5, 1, 2, 3] āĻšāϝ় āφ⧰ু āφāĻŽি āωāĻĒাāĻĻাāύ 3 āĻŦাāχ 0 āϏāϞāύি āϕ⧰িāĻŦ āĻŦিāϚাā§°ো, āĻā§°ে āϏāĻŽāϞ {1, 2, 0, 4, 5, 1, 2, 3) āĻšāϝ়। āϝুāĻ•্āϤি āĻ…āύ্āϤ⧰্āĻ­ুāĻ•্āϤ āϕ⧰ি āĻāϟা āϏāĻŽ্āĻĒূā§°্āĻŖ āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•।

Ans:


10. Write the logic to replace only the last occurrence of an element in an array. For example, if the array elements are (1, 2, 3, 4, 5, 1, 2, 3) and we want to replace element 3 by 0, the array content becomes (1, 2, 3, 4, 5, 1, 2, 0). Write a complete C program incorporating the logic.

āĻā§°ে āĻāϟাāϤ āĻ•েā§ąāϞ āĻāϟা āωāĻĒাāĻĻাāύ⧰ āĻ…āύ্āϤিāĻŽ āϘāϟāύাāϟো āϏāϞāύি āϕ⧰িāĻŦāϞৈ āϝুāĻ•্āϤিāϞিāĻ–āĻ•। āωāĻĻাāĻšā§°āĻŖ āϏ্āĻŦā§°ূāĻĒে, āϝāĻĻি āĻā§°ে āωāĻĒাāĻĻাāύāĻŦোā§° (1, 2, 3, 4, 5, 1, 2, 3) āĻšāϝ় āφ⧰ু āφāĻŽি āωāĻĒাāĻĻাāύ 3 āĻŦাāχ 0 āϏāϞāύি āϕ⧰িāĻŦ āĻŦিāϚাā§°ো, āĻā§°ে āϏāĻŽāϞ (1, 2, 3, 4, 5, 1, 2, 0) āĻšৈ āĻĒā§°ে। āϝুāĻ•্āϤি āĻ…āύ্āϤ⧰্āĻ­ুāĻ•্āϤ āϕ⧰ি āĻāϟা āϏāĻŽ্āĻĒূā§°্āĻŖ āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•।

Ans:


11. Write a C program to replace all the even positioned elements in an integer array by 0. For example, if the array elements are {1, 2, 3, 9, 5, 5, 7, 1, 9), it becomes (1, 0, 3, 0, 5, 0, 7, 0, 9).

 āχāĻŖ্āϟেāĻ—াā§° āĻā§°েāϤ āϏāĻ•āϞো āϏāĻŽাāύ āĻ…ā§ąāϏ্āĻĨাāύāϝুāĻ•্āϤ āωāĻĒাāĻĻাāύ0 ā§° āĻĻ্āĻŦাā§°া āϏāϞāύি āϕ⧰িāĻŦāϞৈ āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•। āωāĻĻাāĻšā§°āĻŖ āϏ্āĻŦā§°ূāĻĒে, āϝāĻĻি āĻā§°ে āωāĻĒাāĻĻাāύāĻŦোā§° {1, 2, 3, 9, 5, 5, 7, 1, 9) āĻšāϝ়, āχ (1, 0, 3, 0, 5, 0, 7, 0, 9) āĻšৈ āĻĒā§°ে।

Ans:


12. Write a strategy to replace all the odd numbers in an integer array by 0. For example, if the array elements are (1, 2, 3, 9, 5, 5, 7, 1, 9), it becomes (0, 2, 0, 0, 0, 0, 0, 0, 0). Write a C program for the same.

 āχāĻŖ্āϟেāĻ—াā§° āĻā§°েāϤ āϏāĻ•āϞো āĻŦিāϜোāĻĄ় āϏংāĻ–্āϝা 0 ā§°ে āϏāϞāύি āϕ⧰িāĻŦāϞৈ āĻ•ৌāĻļāϞ āĻāϟা āϞিāĻ–āĻ•। āωāĻĻাāĻšā§°āĻŖ āϏ্āĻŦā§°ূāĻĒে, āϝāĻĻি āĻā§°ে āωāĻĒাāĻĻাāύāĻŦোā§° (1, 2, 3, 9, 5, 5, 7, 1, 9) āĻšāϝ়, āχ (0, 2, 0, 0, 0, 0, 0, 0, 0, 0) āĻšāϝ়। āχāϝ়াā§° āĻŦাāĻŦে āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•।

Ans:


13. Write a C program to store your name and your mother's name in two different strings. Display them one after another.

āφāĻĒোāύাā§° āύাāĻŽ āφ⧰ু āφāĻĒোāύাā§° āĻŽাāϤৃā§° āύাāĻŽ āĻĻুāϟা āĻĒৃāĻĨāĻ• āϏ্āϟ্ā§°িংāϤ āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•। āϏিāĻšঁāϤāĻ• āĻāϟাā§° āĻĒিāĻ›āϤ āĻāϟা āĻ•ৈ āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰āĻ•।

Ans:


14. Write a C program to declare 3 integer type arrays to store the marks of 10 students scored in 3 different subjects. Take another integer to store the average marks of the students. The average mark of a student is the average of the marks scored by the student in 3 subjects. This should be calculated and inserted by the program. Then you should display the average marks of the students. The program should also display "PASS" or "FAIL" along with the average as per the rule: PASS if average >= 45, FAIL otherwise.

3 āϟা āĻĒৃāĻĨāĻ• āĻŦিāώāϝ়āϤ āύāĻŽ্āĻŦā§° āĻĒোā§ąা 10 āϜāύ āĻļিāĻ•্āώাā§°্āĻĨীā§° āύāĻŽ্āĻŦā§° āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ 3 āϟা āχāĻŖ্āϟেāĻ—াā§° āĻĒ্ā§°āĻ•াā§°ā§° āĻā§°ে āϘোāώāĻŖা āϕ⧰িāĻŦāϞৈ āĻāϟা āϚি āĻĒ্ā§°'āĻ—্ā§°াāĻŽ āϞিāĻ–āĻ•। āĻļিāĻ•্āώাā§°্āĻĨীāϏāĻ•āϞ⧰ āĻ—āĻĄ় āύāĻŽ্āĻŦā§° āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦāϞৈ āφāύ āĻāϟা āχāĻŖ্āϟেāĻ—াā§° āϞāĻ“ঁāĻ•। āĻāϜāύ āĻļিāĻ•্āώাā§°্āĻĨীā§° āĻ—āĻĄ় āϚিāĻš্āύ āĻšৈāĻ›ে 3 āϟা āĻŦিāώāϝ়āϤ āĻļিāĻ•্āώাā§°্āĻĨীāϝ়ে āĻĒ্ā§°াāĻĒ্āϤ āϕ⧰া āύāĻŽ্āĻŦā§°ā§° āĻ—āĻĄ়। āĻāχāϟো āĻĒ্ā§°'āĻ—্ā§°াāĻŽā§° āĻĻ্āĻŦাā§°া āĻ—āĻŖāύা āφ⧰ু āĻ…āύ্āϤ⧰্āĻ­ুāĻ•্āϤ āϕ⧰িāĻŦ āϞাāĻ—ে। āϤেāϤিāϝ়া āφāĻĒুāύি āĻļিāĻ•্āώাā§°্āĻĨীāϏāĻ•āϞ⧰ āĻ—āĻĄ় āύāĻŽ্āĻŦā§° āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰া āωāϚিāϤ। āĻĒ্ā§°'āĻ—্ā§°াāĻŽāϟোā§ąে āύিāϝ়āĻŽ āĻ…āύুāϏ⧰ি āĻ—āĻĄ়ā§° āϏৈāϤে "āĻĒাāĻ›" āĻŦা "āĻĢেāχāϞ" āĻĒ্ā§°āĻĻā§°্āĻļāύ āϕ⧰িāĻŦ āϞাāĻ—ে: āϝāĻĻি āĻ—āĻĄ় >= 45, āĻ…āύ্āϝāĻĨা āĻŦিāĻĢāϞ āĻšāϝ় āϤেāύ্āϤে āĻĒাāĻ› āϕ⧰āĻ•।

Ans:


15. Write any two limitations of arrays. Can you store your name and roll number in the same aray?

āĻā§°েā§° āϝিāĻ•োāύো āĻĻুāϟা āϏীāĻŽাāĻŦāĻĻ্āϧāϤা āϞিāĻ–āĻ•। āφāĻĒুāύি āφāĻĒোāύাā§° āύাāĻŽ āφ⧰ু ā§°োāϞ āύāĻŽ্āĻŦā§° āĻāĻ•েāϟা āφ⧰েāϤ āϏংā§°āĻ•্āώāĻŖ āϕ⧰িāĻŦ āĻĒাā§°িāĻŦāύে?

Ans:



Type & Assamese Translate : Himashree Bora.



Post ID: DABP002256