NAME = JAWAD AHMAD
S/O MUHAMMAD NAEEM
ROLL NO = 04
DEPT = BCS AI
SUBJECT = PROGRAMMING FUNDAMENTAL
TUTOR = SIR M ASIF
Question 1:
Write a Program in C++ to Check if Two Arrays Are Equal or Not.
An array is said to be equal if the elements at the given index are equal in both arrays. In this program,
you have to take two arrays, and then check whether the two arrays are equal.
Solution:
#include<iostream>
using namespace std;
int main() {
int sum;
int n;
int arr[4];
float avg=arr[n];
for(n=0; n<4; n++)
{
cout<<"Enter a number:";
cin>>arr[n];
sum=arr[n]+sum;
}
avg=sum/4;
cout<<"Sum of numbers is= "<<sum<<endl;
cout<<"Average of numbers is= "<<avg<<endl;
return 0;
}
Question 2:
Write a Program in C++ to Calculate the Average of All the Elements present in an Array.
In this problem, you have to calculate the average of all the elements present in the array and print it on
the console screen.
Solution:
#include <iostream>
using namespace std;
int main(){
int arr[2][6] = {{1, 2, 3, 4, 5}, {1, 2, 3, 4, 5,6}};
bool equal = true;
for (int x = 0; x < 5; x++)
{
if (arr[0][x] != arr[1][x])
{
equal = false;
break;
}
}
if (equal)
cout << "Arrays are equal." << endl;
else
cout << "Arrays are not equal." << endl;
return 0;
}