Class 10 Computer Science Chapter 6 SEBA : Arrays in C – Exercise Answers

Class 10 Computer Science Chapter 6 SEBA : Arrays in C – Exercise Answers

SEBA Class 10 Computer Science Chapter 6 – Arrays in C: In this chapter, students learn about arrays in C programming and how arrays can be used to store and manage multiple values of the same data type. This page provides the exercise questions, answers, solutions and explanations for Chapter 6 according to the SEBA Class 10 Computer Science syllabus.

These Class 10 Computer Science Arrays in C exercise answers are explained in a simple and student-friendly manner to help students understand the concepts and prepare effectively for their examinations.

SEBA Class 10 Computer Science Chapter 6 – Arrays in C : Exercise Questions and Answers :

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

Answer:- Array is a collection of similar data items where elements are stored in contiguous memory locations in our computer.

Why we use arrays in computer programs:

  • Stores many values in a single variable name.
  • Handles lots of data quickly using simple loops.
  • Finds any item directly using its index number.
  • Makes programs shorter, simpler, and easier to read.

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

Answer:- No, we can not store both integer and float types of data in a single array.

A program is given below to justify :
#include<stdio.h>
int main( )
{
     int a[3]={1, 2, 3};
     float b[3]={1.5, 2.5, 3.5};
     printf(“\n Displaying data of integer array:”);
     for(int i=0; i<3; i++)
        printf(” %d “, a[i] ) ;
     printf(“\n Displaying data of float array:”);
     for(int i=0; i<3; i++)
        printf(” %f “, b[i] ) ;
return 0;             
}

3. Write the indices of the first and last elements of the following array declaration. char city[7]={‘S’, ‘I’, ‘L’, ‘C’, ‘H’, ‘A’, ‘R’} ;

Answer:- The first element is ‘S’ with index 0, and the last element is ‘R’ with index 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.

Answer:-
#include<stdio.h>
int main( )
{
            int num[7]={1,2,3,4,5,6,7} ;
            printf(“%d”, num[7]) ;
            return 0 ;          
}

The array has 7 elements, with valid indices from 0 to 6. Therefore, num[7] is outside the valid range of the array.

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.

Answer:-
#include<stdio.h>
int main( )
{
      int num[7]={1,2,3,4,5,6,7};
     //Displaying the address of elements
      for(int i=0; i<7; i++)
         printf(“\n Address of %d is %d”, num[i], i) ;
   return 0;             
}

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.

Answer:-
#include<stdio.h>
int main( )
{
  int a[7], b[7] ;
  printf(“Taking 7 elements in fist array: \n”);
  for(int i=0; i<7; i++)
      scanf(“%d” , &a[i] );
  //Copying elements from first to second array
  for(int i=0; i<7; i++)
      b[i]=a[i] ;
  printf(“Displaying second array after copying: \n”);
  for(int i=0; i<7; i++)
      printf(“%d \n”, b[i] ) ;
  return 0;            
}

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.

Answer:-
The strategy to find the summation of all the even numbers:
1) Declare an integer type array.  
2) Calculating the summation of all the even numbers
3) Declare of the result

A program is given below:
#include<stdio.h>
int main( )
{
      int num[9]={1,2,4,3,5,6,7,7,8};
      int sum=0;
      //finding summation of even numbers
      for(int i=0; i<9; i++)
      {
             if(num[i]%2 == 0)
              sum= sum + num[i] ;
       }             
       printf(“\n Summation is %d”, sum);
      return 0;             
}

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.

Answer:-
The strategy to find the summation of even positioned numbers:
1) Declare an integer type array.  
2) Calculating the summation of all the even positioned numbers
3) Declare of the result

A program is given below:
#include<stdio.h>
int main( )
{
    int num[9]={1,2,4,3,5,6,7,7,8};
    int sum=0;
   //finding summation of even positioned numbers
    for(int i=1; i<9; i=i+2)
       sum= sum + num[i] ;    
    printf(“\n Summation is %d”,sum);
   return 0;             
}

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.

Answer:-
The logic to replace only the first occurrence of an element in an array:
1) Declare an integer type array.  
2) Replacing the first occurrence element 3 by 0
3) Declare of the result

A program is given below:
#include<stdio.h>
int main( )
{
    int num[8]={1,2,3,4,5,1,2,3};
   //replacing the first occurrence element 3 by 0
    for(int i=0; i<8; i++)
    {
       if( num[i] == 3 )
        {
          num[i] = 0 ;
        break ;
        }
    }
    printf(“Displaying the result after replacing: “);
    for(int i=0; i<8; i++)
        printf(“%d”, num[i] ) ;
    return 0;           
}

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.

Answer:-
The logic to replace only the last occurrence of an element in an array:
1) Declare an integer type array.  
2) Replacing the last occurrence element 3 by 0
3) Declare of the result

A program is given below:
#include<stdio.h>
int main( )
{
    int num[8]={1,2,3,4,5,1,2,3};
   //replacing the last occurrence element 3 by 0
    for(int i=7; i>=0; i=i-1)
    {
       if( num[i] == 3 )
        {
          num[i] = 0 ;
        break ;
        }
    }
    printf(“Displaying the result after replacing: “);
    for(int i=0; i<8; i++)
        printf(“%d”, num[i] ) ;
    return 0;           
}

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

Answer:-
#include<stdio.h>
int main( )
{
    int num[9]={1,2,3,9,5,5,7,1,9};
   //replacing all even positioned elements by 0
    for(int i=1; i<9; i=i+2)
        num[i]=0;
    printf(“Displaying result after replacing: “);
    for(int i=0; i<9; i++)
        printf(“%d”, num[i] ) ;
    return 0;            
}

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.

Answer:-
#include<stdio.h>
int main( )
{
    int num[9]={1,2,3,9,5,5,7,1,9};
   //replacing all odd numbers by 0
    for(int i=0; i<9; i=i+1)
        {
            if(num[i]%2 == 1)
             num[i] = 0 ;
         }
    printf(“Displaying result after replacing: “);
    for(int i=0; i<9; i++)
        printf(“%d”, num[i] ) ;
    return 0;           
}

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

Answer:-
#include<stdio.h>
int main( )
{
    char a[20], b[20];
      printf(“\n Enter your name:”);
       gets(a);
       printf(“\n Enter your mother name:”);
       gets(b);
       printf(“\n Your name is:”);
       puts(a);
       printf(“\n Your mother name is:”);
       puts(b);
       return 0;           
}

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.

#include <stdio.h>
int main()
{
    int eng[10], sci[10], comp[10];
    float avg;
 
    for(int i = 0; i < 10; i++)
    {
        printf(“Enter English, Science and Computer marks for Roll %d: “, i + 1);
        scanf(“%d%d%d”, &eng[i], &sci[i], &comp[i]);
    }
 
    for(int i = 0; i < 10; i++)
    {
        avg = (eng[i] + sci[i] + comp[i]) / 3.0;
        printf(“Roll %d: Average = %.2f “, i + 1, avg);
 
        if(avg >= 45)
            printf(“PASS\n”);
        else
            printf(“FAIL\n”);
    }
 
    return 0;
}

⭐ Particularly Important for Exams

Students should remember these points:

  • Array index starts from 0.
  • Last index of an array is size − 1.
  • In int num[7]; , num is the name of the array. The array name represents the base address of the array.
  • Array stores elements of the same data type.
  • Array elements are stored in continuous memory locations.
  • Accessing an invalid index can cause undefined behavior.
  • for loops are frequently used to process array elements.
  • break can be used to stop a search after finding the first occurrence.
  • Arrays can contain duplicate elements.
error: Content is protected !!