5.1.4. Using Arrays in Programs:, Chapter - 5, Arrays and String, HSSC-II (12th Class) Computer Science Key Point Notes

5.1.4. Using Arrays in Programs:, Chapter - 5, Arrays and String, HSSC-II (12th Class) Computer Science Key Point Notes

12th Class (HSSC-II) Computer SLO Based Key Point Notes

(National Book Foundation - As Federal Textbook Board, Islamabad 
Based on National Curriculum Pakistan 2023-2024 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards) 

{Contact WhatsApp 03339719149 for Class-XII Computer Science Complete SLO-Based Key Points notes in pdf format as well as in PowerPoint Presentation for preparing/delivering the Lectures}

************************************

👉👉👉 Computer Science 12th Class Notes (Main Page)

************************************

Unit 5: Arrays and String


5.1.4. Using Arrays in Programs:

To perform any operation on the arrays like entering data, printing the data values, searching for the data, comparing the data, sorting the data, etc. a loop should be used. 

For example to fill an array using the cin function:

        int myArray[6];
        for(int i=0; i<=5; i++)
        {
                cout<<“Please enter the value: “;
                cin>>myArray[i];
        }


To print the data values from an array:

        for (int i=0; i<=5; i++)
        {
                cout<<myArray[i]<<endl;;
        }



Example # 1

Write a program that reads 5 integer values in an array and finds their total and average.

#include<iostream.h>
#include<conio.h>
void main()
{
        clrscr();
        int a[5], sum = 0;
        float avg;
        for(int i=0; i<=4; i++)
        {
                cout<<“Enter a number: “;
                cin>>a[i];
        }
        for(int j=0; j<=4; j++)
        sum = sum + a[j];
        avg = sum/5;
                cout<<“\n Sum of all numbers is: “<<sum;
                cout<<“\n Average = “<<avg;
        getch();
}


Example # 2:

Write a program that reads ten integer data values and prints the largest data values?

#include<iostream.h>
#include<conio.h>
void main()
{
        clrscr();
        int arr[10], max;
        for(int i=0; i<=9; i++)
        {
                cout<<“Enter a number: “;
                cin>>arr[i];
        }
        max = arr[0];
        for(int j=0; j<=9; j++)
        {
        if(max < a[j])
        max = a[j];
        }
                cout<<“The largest value is: “<<max;
        getch();
        }

Exercise Problem:

Problem ii:
Write a program that reads ten numbers in any array and prints them in reverse.

Problem iii:
Write a program that reads ten numbers and prints the smallest along with its index?

Problem iv:
For the given array:

int a[15]={4,8,5,1,3,5,0,12,5,7,3,15,8,4,11}

Write a program that prints the number of times the number 5 appears in the array.


************************************
👉👉👉 Computer Science 12th Class Notes (Main Page)

************************************


************************************
Shortcut Links For:

1.  5th Class All Subjects Notes

2.  8th Class All Subjects Notes

3.  Easy English Grammar Notes



1. Website for School and College Level Physics   
2. Website for School and College Level Mathematics  
3. Website for Single National Curriculum Pakistan - All Subjects Notes 

© 2023 & onwards Academic Skills and Knowledge (ASK  

Note:  Write me in the comments box below for any query and also Share this information with your class-fellows and friends.

Post a Comment

0 Comments

cwebp -q 80 image.png -o image.webp