SEBA Class 10 Computer Science Chapter 6 Arrays In C

Join Roy Library Telegram Groups

Hello Viewers Today’s We are going to Share With You, The Complete Syllabus of SEBA Class 10 Computer Science Chapter 6 Arrays In C Solutions in English in This Page. Are you a Student of (Secondary Education Board of Assam). SEBA Class 10 Computer Science Chapter 6 Arrays In C Notes. Which you Can Download PDF SEBA Class 10 Computer Science Chapter 6 Arrays In C Question Answer for free using direct Download Link Given Below in This Post.

SEBA Class 10 Computer Science Chapter 6 Arrays In C

We have Shared in This Post, SEBA Class 10 Computer Science Chapter 6 Arrays In C Textbook PDF Download for Free with you. SEBA Class 10 Computer Science Chapter 6 Arrays In C Solutions PDF. I Hope, you Liked The information About The SEBA Class 10 Computer Science Chapter 6 Arrays In C Book PDF. If you liked Class 10 Computer Science Notes Then Please Do Share this Post With your Friends as Well.

Arrays In C

TEXTUAL QUESTIONS AND ANSWERS

EXERCISE

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

Ans. Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.

For example, if you want to store 10 integers, you can create an array for it. int data[10];

Arrays are used to store multiple values of the same data type.

For example,

int a;

In the above, variable a can store only one value of only integer type.

But in an array, if we declare variable a as integer, then we can store n number of integer type of value where n is the index of array.

int a[10];

In the above, we can store 10 integer values in the variable a.

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

Ans. If we declare array as an integer the we can store the values of integer type only not of character or float type. So, we cannot store both integer and float types in a single array. For example, if we want to declare array of integer and float type, then we have to declare two variables with different data type as follows:

int a[10];

float b[10];

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’};

Ans. Indices of the first element of the array is 0

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 7th element of the array.

Solution:

Code:

#include <stdio.h>int main(){int a[7], i;printf(“Enter the values of array: “);for(i=0; i<7;i++){scanf(“%d”, &a[i]);}printf(“The 7th element is %d”, a[6]);return 0;}

Output:

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.

Solution:

Code:

#include <stdio.h>int main(){int a[7], i;printf(“Enter the values of array: “);for(i=0; i<7;i++){scanf(“%d”, &a[i]);}for(i=0; i<7;i++){printf(“\n The address of element %d is %p”, (i+1), a[i]):}return 0;}
NOTE: To print the memory address, we use %p’ format specifier in C

Output:

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.

Solution:

Code:

#include <stdio.h>int main(){int a[7], b[7], i, j;printf(“Enter the values of first array: “);for(i=0; i<7; i++){scanf(“%d”, &a[i]);}for(i=0; i<7; i++){b[i] = a[i]:}printf (“\n Displaying the elements of second array \n”);for(i=0; i<7; i++){printf(“%d\t”, b[i]);}return 0;}

Output:

7. Write a strategy to find the summation of all the even numbers stored in an array. Write a C program for the same.

Solution:

Strategy:

  • Create a new array that will store numbers in the array.
  • Use the for loop to iterate over the array and on each iteration check that the element in the array has a remainder when divided by 2.
  • If the remainder is 0, add the value of the element with a declared variable, which is initialized to 0.

Code:

#include <stdio.h>int main(){int a[7], i, sum = 0;printf(“Enter the values of array: “);for(i=0; i<7; i++){scanf(“%d”, &a[i]);}for(i=0; i<7; i++){if (a[i]%2 ==0){sum = sum + a[i];}}printf (“\n The sum of the even numbers stored in the array is %d”, sum);return 0;}

Output:

8. Write a strategy to the summation of all the even positioned numbers stored in an array. Write a C program for the same.

Solution:

Strategy:

  • Create a new array that will store numbers in an array.
  • Use the for loop to iterate over the array and on each iteration check that the counter in the array has a remainder when divided by 2.
  • If the remainder is 0, add the value of the element with a declared variable, which is initialized to 0.

Code:

#include <stdio.h>int main(){int a[7], i, sum = 0;printf(“Enter the values of array: “);for(i=0; i<7; i++){scanf(“%d”, &a[i]);}for(i=0; i<7; i++){if (i%2 ==0){sum = sum + a[i];}}printf (“\n The sum of the even positioned numbers stored in the array is %d “, sum);return 0;}

Output:

S.L No.CONTENTS
Chapter 1Introduction To Computer Network
Chapter 2Html5 And Css3
Chapter 3Database Part – II Mysql
Chapter 4Introduction To Loops
Chapter 5Nested Loops In C
Chapter 6Arrays In C
Chapter 7Functions In C
Chapter 8Pointers In C
Chapter 9Structure In C
Chapter 10An Introduction To Object Oriented Programming
Chapter 11Case Studies

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 the complete C program incorporating the logic.

Solution:

Logic:

  • Create a new array that will store numbers in a array.
  • Use the for loop to iterate over the array.
  • Enter the number to be searched and replaced.
  • Use the for loop to search for the number, if it encountered the number, replace the number with 0 and break the loop.
  • Display the changed array.

Code:

#include <stdio.h>int main(){int a[7], i, s;printf(“Enter the values of array: “);for(i=0; i<7; i++){scanf(“%d”, &a[i]);}printf(“\n Enter the number to be replaced: “);scanf(“%d”, &s);for(i=0; i<7; i++){if (a[i] == s){a[i] = 0;break;}}printf(“\n The new array after replacing the first element are: \n”);for(i=0; i<7; i++){printf(“%d”, a[i]):}return 0;}

Output:

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 the complete C program incorporating the logic.

Solution:

Logic:

  • Create a new array that will store numbers in a array.
  • Use the for loop to iterate over the array.
  • Enter the number to be searched and replaced.
  • Use the for loop to search for the number, if it encountered the number, store the index of the number to a variable.
  • So, the variable will store the last index number of searched array.
  • Replace the last index number in the variable with 0.
  • Display the changed array.

Code:

#include <stdio.h>int main(){int a[7], i, s, flag=0;printf(“Enter the values of array: “);for(i=0; i<7; i++){scanf(“%d”, &a[i]);}printf(“\n Enter the number to be replaced : “);scanf(“%d”, &s);for(i=0; i<7; i++){if (a[i] == s){flag = i;}}a[flag] =0;printf(“\n The new array after replacing the first element are : \n”);for(i=0; i<7; i++){printf(“%d”, a[i]);}return 0;}

Output:

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}

Solution:

Code:

#include <stdio.h>int main(){int a[7], i, sum=0;printf(“Enter the values of array: “);for(i=0; i<7; i++){scanf(“%d”, &a[i]);}for(i=0; i<7; i++){if (i % 2 == 0){sum = sum + a[i];}}printf(“\n The summation of even positioned elements in the array is %d “,sum);return 0;}

Output:

12. Write the 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 the C program for the same.

Solution:

Strategy:

  • Create a new array that will store numbers in an array.
  • Use the for loop to iterate over the array and on each iteration check that the element in the array has a remainder when divided by 2.
  • If the remainder is not 0, replace the element with 0.
  • Display the changed array.

Code:

#include <stdio.h>int main(){int a[7], i, sum=0;printf(“Enter the values of array: “);for(i=0; i<7; i++){scanf(“%d”, &a[i]);}for(i=0; i<7; i++){if (i % 2 != 0){sum = sum + a[i];}}printf(“\n The summation of even positioned elements in the array is %d “,sum);return 0;}

Output:

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

Solution:

Code:

#include <stdio.h>int main(){char n[6], m[6];int i;printf(“Enter your name : \n”);for(i=0;i<5;i++){scanf(“%c”,&n[i]);}printf(“Enter your mother’s name : \n”);for(i=0;i<5;i++){scanf(“%c”,&m[i]);}printf(“\n Your name :”);for(i=0;i<5;i++){printf(“%c”,n[i]);}printf(“\n Your mother’s name : “);for(i=0;i<5;i++){printf(“%c”,m[i]);}return 0;}

Output:

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.

Solution:

Code:

#include <stdio.h>int main(){int a[10], b[10], c[10], avg[3], i;printf(“Enter details of 10 students :\n”);printf(“Enter the marks of 10 students in English :\n”);for(i=0;i<10; i++){scanf(“%d”, &a[i]);}printf(“\nEnter the marks of 10 students in Mathematics :\n”);for(i=0;i<10; i++){scanf(“%d”, &b[i]);}printf(“\nEnter the marks of 10 students in Science :\n”);for(i=0;i<10; i++){scanf(“%d”, &c[i]);}//Calculating average of 10 students in each subjectsfor(i=0;i<10; i++){avg[i]=(a[i] + b[i] + c[i])/3;if (avg[i]>45){printf(“\n Student %d is PASS”, (i+1));}else{printf(“\n Student %d is FAIL”, (i+1));}}return 0;}

Output:

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

Ans. The limitations of array are –

  • When we declare array as an integer the we can store the values of integer type only not of character or float type.
  • We cannot store the values more than array limit. for example if we declare a[10] then we can’t store values more than 10

No, we cannot store name and roll number in the same array as both are of different data type. So, when we declare an array of character type, we cannot store element of integer type.

ADDITIONAL QUESTIONS AND ANSWERS

1. What are the advantages and disadvantages of array?

Ans. Advantages:

  • we can store multiple values of same datatype.
  • we can perform searching, sorting, insert, delete operations on array.

Disadvantages:

When we declare array as an integer the we can store the values of integer type only not of character or float type.

We cannot store the values more than array limit. for example if we declare a[10] then we can’t store values more than 10.

2. How do we create an array?

Ans. To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows –

type arrayName [arraySize];

Example:

int arr[10];

3. Can we declare without assigning the size of an array?

Ans. No. It is not possible to declare an array without specifying the size.

4. How to find the largest number in an array?

Ans. To find the largest element from the array, a simple way is to arrange the elements in ascending order. After sorting, the first element will represent the smallest element, the next element will be the second smallest, and going on, the last element will be the largest element of the array.

5. Does the array have a fixed length?

Ans. The length of an array is established when the array is created. After creation, its length is fixed.

6. What is the maximum array size in C?

Ans. There is no fixed limit to the size of an array in C.

7. What is the difference between the number of elements in an array and its highest index number?

Ans. The highest element index is one less than the total number of elements in the array.

8. What is the lowest index of an array?

Ans. The lowest index would always be 0.

9. What is the role of indexing in array?

Ans. Indexing is an operation that pulls out a select set of values from an array. The index of a value in an array is that value’s location within the array.

10. How to declare by assigning values to the elements?

Ans. To declare by assigning values to the elements, we may use the following declaration:

int num[5] = {23, 45, 65, 85, 12}; (Type–integer)

char state [5] = {‘A’, ;S’, ‘S’, ‘A’, ‘M’); (Type – character)

11. Write a C program to sort the given data in ascending order.

Solution:

Code:

#include<stdio.h>int main(){int a[10], i, j, temp;printf(“Enter the values of arrays: “);for(i=0; i<10; i++){scanf(“%d”, &a[i]);}//loop to sort the elementsfor(i=0; i<10; i++){for(j=i+1;j<10; j++){if(a[i]>a[i]){temp=a[i];a[i]=a[j];a[j]=temp;}}}//displaying the sorted arrayprintf(“The sorted array is \n”);for(i=0; i<10; i++){printf(“%d\t”, a[i]);}return 0;}

Output:

Leave a Reply

error: Content is protected !!
Scroll to Top