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.
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