Professional Documents
Culture Documents
Exercise 1: Department of Computer Science Semester BSCS-1A
Exercise 1: Department of Computer Science Semester BSCS-1A
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];
for(int i=0,j=9;i<=9,j>=0;i++,j--)
{
arr2[j]=arr1[i];
}
OUTPUT
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";
}
Ouput