0% found this document useful (0 votes)
3 views

PROGRAMMING FUNDAMENTALS LAB

This document is a laboratory manual for the Programming Fundamentals Lab (CL1002) at the National University of Computer and Emerging Sciences for Spring 2025. It includes tasks related to arrays, with example C++ programs demonstrating how to access array elements, find the frequency of an element, and handle odd-sized arrays. The manual is prepared and verified by multiple engineers, with the last edit date noted as October 23, 2023.

Uploaded by

i222222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

PROGRAMMING FUNDAMENTALS LAB

This document is a laboratory manual for the Programming Fundamentals Lab (CL1002) at the National University of Computer and Emerging Sciences for Spring 2025. It includes tasks related to arrays, with example C++ programs demonstrating how to access array elements, find the frequency of an element, and handle odd-sized arrays. The manual is prepared and verified by multiple engineers, with the last edit date noted as October 23, 2023.

Uploaded by

i222222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PROGRAMMING

FUNDAMENTALS LAB
(CL1002)

LABORATORY MANUAL
Spring 2025

LAB 02
ARRAYS

Ahmad Rafique 24i-6083 A


________________________________________ __________ ____

STUDENT NAME ROLL NO SEC

______________________________________

LAB ENGINEER'S SIGNATURE & DATE


Nimra Fatima
Fasih Ahmed

MARKS AWARDED: /10


______________________________________________________________________
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES (NUCES), ISLAMABAD
Prepared by: Engr. Aamer Munir Version: 1.3
Last edited by: Engr. Maryam Wasim, Engr. Sana Saleh
Date last
Verified by: Engr. Azhar Rauf Oct 23, 2023
edited:

Task no 1:
Program:
#include <iostream>
using namespace std;

int main()
{
int arr[] = {10, 20, 30, 40, 50};
int size = sizeof(arr) / sizeof(arr[0]);
int index;
cout << "Enter the element number (1 to " << size << ") to print: ";
cin >> index;
while (index < 1 || index > size)
{
cout << "Invalid input! Please enter a number between 1 and " << size << ": ";
cin >> index;
}
cout << "Element at position " << index << " is: " << arr[index - 1] << endl;
return 0;
}
Out put:

Task No 3:
Program:
#include <iostream>
using namespace std;

int main()
{
int arr[10];
cout << "Enter 10 elements of the array:" << endl;
for (int i = 0; i < 10; i++)
{
cin >> arr[i];
}
int element;
cout << "Enter the element to find its frequency: ";
cin >> element;
int frequency = 0;
for (int i = 0; i < 10; i++)
{
if (arr[i] == element)
{
frequency++;
}
}
cout << "Occurrence of " << element << ": " << frequency << endl;
return 0;
}
Output:

Task no 3:
Program:
#include<iostream>
using namespace std;
int main()
{
int n;
int a[n];
int q;

int i,j,k;
cout<<"Enter number of elements in odd:"<<endl;
cin>>n;

if(n%2!=0)
{
cout<<"Array:"<<endl;

for(int i=0;i<n;i++)
{
cin>>a[i];
}
q=((n+1)/2);
for(int i=0;i<q;i++)
{

cout<<a[i]<<" ";

}
cout<<endl;
for(i=q;i<n;i++)
{
cout<<a[i]<<" ";
}
}
return 0;
}
Output:
Task no 4

You might also like