SEBA Class X Computer Science Chapter 6 - Array in C Notes PDF

SEBA Class 10 Computer Science Chapter 6 – Array in C

Complete Notes • C Programs • Important Questions • PDF

Chapter 6 Array In C

📘 Chapter 6 – Array in C

Welcome to CompGuide2. In this chapter of SEBA Class 10 Computer Science, we learn about Arrays in C and how arrays can be used to store and process multiple values efficiently.

An array is a collection of similar types of data items stored in contiguous memory locations. Arrays allow us to store multiple values using a single variable instead of declaring separate variables for each value.

This chapter also introduces array indexing, accessing array elements, copying arrays, finding sums, replacing elements, working with strings, and using arrays to calculate student averages.



📑 Table of Contents

  1. Array – Definition and Uses
  2. Array Data Types
  3. Array Index
  4. Address of Array Elements
  5. Copying One Array to Another
  6. Sum of Even Numbers
  7. Sum of Even Positioned Elements
  8. Replacing First Occurrence
  9. Replacing Last Occurrence
  10. Replacing Even Positioned Elements
  11. Replacing Odd Numbers
  12. Arrays and Strings
  13. Student Marks and Average
  14. Limitations of Arrays
  15. Quick Revision
  16. Important Questions
  17. Chapter 6 PDF

1. What is an Array?

An array is a collection of similar types of data items where the elements are stored in contiguous memory locations.

Arrays are used in C programs to store multiple values in a single variable instead of declaring a separate variable for every value.

💡 Example

If we want to store the marks scored by Class X students, we can store the marks in an array instead of creating a separate variable for each student's marks.

Advantages of Using an Array

  • Stores multiple values using one variable.
  • Makes handling a large number of values easier.
  • Elements can be accessed using their index.
  • Arrays are useful with loops for processing multiple values.

2. Can an Array Store Different Data Types?

A normal array in C can store only one type of data. Therefore, an integer and a float value cannot normally be stored together in the same array.

The chapter also explains that a union can hold different data types, although only one member can contain a valid value at a time.

Example: Integer and Float Arrays

#include <stdio.h>

int main()
{
    int a[3] = {10, 20, 30};
    float b[3] = {10.5, 20.5, 30.5};

    printf("Integer Array:\n");

    for(int i = 0; i < 3; i++)
        printf("%d ", a[i]);

    printf("\n\nFloat Array:\n");

    for(int i = 0; i < 3; i++)
        printf("%.1f ", b[i]);

    return 0;
}

3. Array Index

The position of an element in an array is represented using an index.

In C, array indexing starts from 0.

Example

char city[7] = {'S','I','L','C','H','A','R'};
Element Index
S 0
I 1
L 2
C 3
H 4
A 5
R 6
Important: For an array containing 7 elements, the first index is 0 and the last index is 6.

4. Displaying the Address of Array Elements

Each element of an array occupies a location in memory. The address operator & can be used to obtain the address of an element.

#include <stdio.h>

int main()
{
    int num[7] = {1,2,3,4,5,6,7};
    int i;

    for(i = 0; i < 7; i++)
    {
        printf("Address for %d is %p\n",
               num[i], (void*)&num[i]);
    }

    return 0;
}

The program displays the memory address associated with each element of the array.


5. Copy Elements from One Array to Another

One array can be copied into another array by using a loop and assigning each element individually.

#include <stdio.h>

int main()
{
    int num1[7], num2[7], i;

    /* Input to num1 */
    for(i = 0; i < 7; i++)
    {
        printf("Enter a number %d\n", i + 1);
        scanf("%d", &num1[i]);
    }

    /* Copy num1 to num2 */
    for(i = 0; i < 7; i++)
    {
        num2[i] = num1[i];
    }

    /* Display num2 */
    printf("The elements of Num2 are:\n");

    for(i = 0; i < 7; i++)
    {
        printf("%d\n", num2[i]);
    }

    return 0;
}

6. Sum of All Even Numbers in an Array

We can find the sum of all even numbers in an array by checking each element using the modulus operator %.

If num[i] % 2 == 0, the element is even and can be added to the sum.

Program 1: Using a Predefined Array

#include <stdio.h>

int main()
{
    int num[9] = {1,2,4,3,5,6,7,7,8};
    int i, sum = 0;

    for(i = 0; i < 9; i++)
    {
        if(num[i] % 2 == 0)
            sum = sum + num[i];
    }

    printf("Sum is %d", sum);

    return 0;
}

For the given values, the output is:

Sum is 20

Program 2: Taking Values from the User

#include <stdio.h>

int main()
{
    int n;

    printf("Enter the no of elements\n");
    scanf("%d", &n);

    int num[n], i, sum = 0;

    for(i = 0; i < n; i++)
    {
        printf("Enter Element %d\n", i + 1);
        scanf("%d", &num[i]);
    }

    for(i = 0; i < n; i++)
    {
        if(num[i] % 2 == 0)
            sum = sum + num[i];
    }

    printf("Sum is %d", sum);

    return 0;
}

7. Sum of Even-Positioned Elements

The chapter also demonstrates how to calculate the sum of elements stored at even positions in an array.

Because C array indexing begins with 0, the program uses the appropriate index positions while traversing the array.

#include <stdio.h>

int main()
{
    int n;

    printf("Enter the no of elements\n");
    scanf("%d", &n);

    int num[n], i, sum = 0;

    for(i = 0; i < n; i++)
    {
        printf("Enter Element %d\n", i + 1);
        scanf("%d", &num[i]);
    }

    for(i = 1; i < n; i = i + 2)
    {
        sum = sum + num[i];
    }

    printf("Sum is %d", sum);

    return 0;
}

For the example discussed in the chapter, the output is 18. :contentReference[oaicite:2]{index=2}


8. Replace the First Occurrence of an Element

Suppose the array is:

{1,2,3,4,5,1,2,3}

If we want to replace the first occurrence of 3 by 0, the resulting array is:

{1,2,0,4,5,1,2,3}

Program

#include <stdio.h>

int main()
{
    int n;

    printf("Enter the number of elements:\n");
    scanf("%d", &n);

    int num[n], i;

    for(i = 0; i < n; i++)
    {
        printf("Enter element %d:\n", i + 1);
        scanf("%d", &num[i]);
    }

    num[2] = 0;

    printf("The Elements of the Array after change\n");

    for(i = 0; i < n; i++)
    {
        printf("%d ", num[i]);
    }

    return 0;
}

9. Replace the Last Occurrence of an Element

If the array is:

{1,2,3,4,5,1,2,3}

and we want to replace the last occurrence of 3 by 0, the resulting array becomes:

{1,2,3,4,5,1,2,0}

Program

#include <stdio.h>

int main()
{
    int n;

    printf("Enter the number of elements:\n");
    scanf("%d", &n);

    int num[n], i;

    for(i = 0; i < n; i++)
    {
        printf("Enter element %d:\n", i + 1);
        scanf("%d", &num[i]);
    }

    num[n - 1] = 0;

    printf("The Elements of the Array after change\n");

    for(i = 0; i < n; i++)
    {
        printf("%d ", num[i]);
    }

    return 0;
}

10. Replace All Even-Positioned Elements by 0

The chapter gives an example where:

{1,2,3,9,5,5,7,1,9}

becomes:

{1,0,3,0,5,0,7,0,9}

Program

#include <stdio.h>

int main()
{
    int n;

    printf("Enter the number of elements:\n");
    scanf("%d", &n);

    int num[n], i;

    for(i = 0; i < n; i++)
    {
        printf("Enter element %d:\n", i + 1);
        scanf("%d", &num[i]);
    }

    for(i = 0; i < n; i++)
    {
        if(i % 2 == 1)
        {
            num[i] = 0;
        }
    }

    printf("The Elements of the Array after change\n");

    for(i = 0; i < n; i++)
    {
        printf("%d ", num[i]);
    }

    return 0;
}

11. Replace All Odd Numbers by 0

The chapter also demonstrates how all odd numbers in an integer array can be replaced with 0.

Example:

{1,2,3,9,5,5,7,1,9}

becomes:

{0,2,0,0,0,0,0,0,0}

Program

#include <stdio.h>

int main()
{
    int n;

    printf("Enter the number of elements:\n");
    scanf("%d", &n);

    int num[n], i;

    for(i = 0; i < n; i++)
    {
        printf("Enter element %d:\n", i + 1);
        scanf("%d", &num[i]);
    }

    for(i = 0; i < n; i++)
    {
        if(num[i] % 2 == 1)
        {
            num[i] = 0;
        }
    }

    printf("The Elements of the Array after change\n");

    for(i = 0; i < n; i++)
    {
        printf("%d ", num[i]);
    }

    return 0;
}

12. Arrays and Strings

A character array can be used to store a string. The chapter provides a program that stores a person's name and mother's name in two different character arrays and displays them one after another.

#include <stdio.h>

int main()
{
    char name[20], mother[20];

    printf("Enter your Name:\t");
    gets(name);

    printf("Enter Mother's Name:\t");
    gets(mother);

    printf("You Entered\n");

    puts(name);
    puts(mother);

    return 0;
}
Note: The code above follows the program presented in your provided chapter PDF.

13. Student Marks, Average and Result

The chapter presents a program using three integer arrays to store the marks of 10 students in three different subjects.

Another array is used to store the average marks. The average is calculated from the marks obtained in the three subjects.

According to the chapter's rule:

Average ≥ 45 → PASS

Average < 45 → FAIL

Program

#include <stdio.h>

int main()
{
    int sub1[10], sub2[10], sub3[10];
    int avg[10];
    int i;

    /* Input marks of 10 students */
    for(i = 0; i < 10; i++)
    {
        printf("\nEnter marks of Student %d\n", i + 1);

        printf("Subject 1: ");
        scanf("%d", &sub1[i]);

        printf("Subject 2: ");
        scanf("%d", &sub2[i]);

        printf("Subject 3: ");
        scanf("%d", &sub3[i]);

        /* Calculate average */
        avg[i] = (sub1[i] + sub2[i] + sub3[i]) / 3;
    }

    /* Display average and result */
    printf("\n\nAverage Marks and Result\n");
    printf("-------------------------------\n");

    for(i = 0; i < 10; i++)
    {
        printf("Student %d : Average = %d ",
               i + 1, avg[i]);

        if(avg[i] >= 45)
            printf("PASS\n");
        else
            printf("FAIL\n");
    }

    return 0;
}

The original chapter gives this program on page 6 and specifies PASS if average ≥ 45 and FAIL otherwise. :contentReference[oaicite:3]{index=3}


14. Limitations of Arrays

The chapter identifies two important limitations of arrays.

1. Fixed Size

An array can store only a fixed number of elements according to its declared size.

2. Homogeneous Data

An array can store only similar types of data.

Can We Store Name and Roll Number in the Same Array?

No. A name is a string whereas a roll number is an integer. Since a normal array stores homogeneous data, they cannot be stored together in the same array.

This is the final concept of Chapter 6 in the provided PDF. :contentReference[oaicite:4]{index=4}


📝 Chapter 6 Quick Revision

Topic Remember
Array Collection of similar data items stored in contiguous memory locations.
Array Index Array indexing in C starts from 0.
Data Type A normal array stores one type of data.
Element Address The & operator can be used to obtain an element's address.
Copying Elements can be copied from one array to another using a loop.
Even Number Check using num[i] % 2 == 0.
Odd Number Check using num[i] % 2 == 1.
String A character array can be used to store a string.
Fixed Size An array has a fixed number of elements according to its size.
Homogeneous Data A normal array stores similar types of data.

❓ Important Questions

  1. Define array. Why do we use arrays in computer programs?
  2. Can we store both integer and float types of data in a single array? Explain.
  3. Write the indices of the first and last elements of a given array.
  4. Write a C program to declare an integer array with capacity 7 and take input from the keyboard.
  5. Write a C program to display the addresses of individual array elements.
  6. Write a C program to copy elements from one array to another.
  7. Write a strategy and C program to find the sum of all even numbers stored in an array.
  8. Write a strategy and C program to find the sum of even-positioned numbers in an array.
  9. Write a C program to replace the first occurrence of an element in an array.
  10. Write a C program to replace the last occurrence of an element in an array.
  11. Write a C program to replace all even-positioned elements in an integer array by 0.
  12. Write a C program to replace all odd numbers in an integer array by 0.
  13. Write a C program to store your name and your mother's name in two different strings and display them.
  14. Write a C program to store marks of 10 students in three subjects, calculate their averages and display PASS or FAIL.
  15. Write any two limitations of arrays. Can you store your name and roll number in the same array?

🎯 Exam Preparation Tips

  • Remember that array indexing starts from 0.
  • Understand the difference between an array element and its index.
  • Practise array programs using for loops.
  • Remember how to identify even and odd numbers using %.
  • Practise copying elements between two arrays.
  • Understand how array elements can be replaced.
  • Remember the two major limitations: fixed size and homogeneous data.
  • Practise the student average program carefully.

📚 Chapter 6 Summary

In this chapter, we learned about arrays in C. An array allows multiple values of the same type to be stored using a single variable. We also learned about indexing, accessing elements, memory addresses, copying arrays and processing array elements using loops.

The chapter further demonstrates programs for calculating sums, replacing elements, working with character arrays and calculating student averages.

Finally, we studied the limitations of arrays, including their fixed size and their ability to store homogeneous data.


📘 SEBA Class 10 Computer Science Chapter 6 PDF

Study the complete Chapter 6 – Array in C directly from the chapter PDF.

The PDF contains the complete set of chapter questions and C programs covered in this post.


📘 Chapter 6 PDF Notes

Read the complete chapter directly below.



🧠 Test Your Knowledge

Ready to test your understanding of Chapter 6 – Array in C?

🎯 Practice Chapter 6 MCQs

CompGuide2 – Building Concepts in Computer Science

SEBA Class 10 Computer Science Notes, Programs & Study Materials