You are on page 1of 4

CSL-113 : Computer Programming Lab

Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)

EXERCISE 1
Write a C++ program that ask user to enter 10 integer values. Store those values in one dimension
array. Create another one dimension array of same size, and store the values of first array in
reverse order. Print the results on screen.

SOURCE CODE:
#include<iostream>
using namespace std;

int main()
{
int arr1[10],arr2[10];

cout<<"matrix A orignal :\n";

for(int i=0 ; i<=9;i++)


{
cin>>arr1[i];

for(int i=0,j=9;i<=9,j>=0;i++,j--)
{
arr2[j]=arr1[i];
}

cout<<"\nmatrix A reverse :\n\n";


for(int j=0;j<=9;j++)
{
cout<<arr2[j]<<"\t";
Department of computer science Semester BSCS-1A
CSL-113: Computer Programming Lab Lab 04: Conditional Statements (if-else, Nested, switch statement
CSL-113 : Computer Programming Lab
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)

OUTPUT

Department of computer science Semester BSCS-1A


CSL-113: Computer Programming Lab Lab 04: Conditional Statements (if-else, Nested, switch statement
CSL-113 : Computer Programming Lab
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)

Exercise 2
Write a C++ Program that checks whether the two arrays are equal or not.
Declare two Integer Arrays with 7 elements, and fill up the array with keyboard input.
Test if every element in Array 1 is equal to corresponding element in Array 2. For example,
the program should check A[0] = B[0], A[0] = B[0], and so for.

Source code
#include <iostream>
using namespace std;
int main()
{
int arr1[7];
int arr2[7];
int i;
int j;

for(int i=0;i<7;i++)
{
cout<<"Element "<<i+1<<" in A :";
cin>>arr1[7];
}
cout<<"==============================="<<endl;

for(int j=0;j<7;j++)
{
cout<<"Element "<<j+1<<" in B :";
cin>>arr2[7];
}
cout<<"==============================="<<endl;
if(arr1[7]==arr2[7])
cout<<"Two arrays are same";
else
cout<<"Two arrays are not same";
}

Department of computer science Semester BSCS-1A


CSL-113: Computer Programming Lab Lab 04: Conditional Statements (if-else, Nested, switch statement
CSL-113 : Computer Programming Lab
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)

Ouput

Department of computer science Semester BSCS-1A


CSL-113: Computer Programming Lab Lab 04: Conditional Statements (if-else, Nested, switch statement

You might also like