Taib Abdullah
Taib Abdullah
Taib Abdullah
Programming fundamental
Course Title & Code:----------------------------------------------------------------
Dr .Habib
Submitted To: --------------------------------------------------------------------------
18/11/2022
Submission Date: ---------------------------------------------------------------------
}
(output)
int main()
{
int space, rows;
char h;
cout<<"Enter number which you want to print"<<endl;
cin>>h;
while(k != 2*i-1)
{
cout<<h;
++k;
}
cout<<endl;
}
return 0;
}
(output)
6://program that show the arrithemetic average of N grades
#include<iostream>
using namespace std;
int main()
{
int n, i;
float number, sum=0, arithmetic_average; //calculating the arithmetic average.
cout<<"Enter numbers to check their arithmetic average?"<<endl;
cin>>n;
cout<<"Enter "<<n<<" Number: "<<endl;
for(i=0; i<n; i++)
{
cin>>number;
sum = sum+number;
}
arithmetic_average= sum/n;
cout<<"Arithmetic Average = "<<arithmetic_average;
cout<<endl;
return 0;
}
(output)
ARRAYS
1://program that ask user to enter numbers of hours that six employes work nd store values in
array
#include<iostream>
using namespace std;
int main(){
int hours[6];
for(int e=1;e<=6;e++)
{
cout<<"working hour of "<<e<<endl;
cin>>hours[6];
}
for(int i=0;i<6;i++){
cout<<"passing from array"<<endl;
cin>>hours[i];
cout<<endl;
}
return 0;
}
2://ask user to enter 10 integers of an array the program must compute nd write how many
intergers are greater than or equal to 10
#include<iostream>
using namespace std;
int main()
{
int a[10];
int count =0;
cout<<"Enter 10 integers of an array :"<<endl;
for(int i=0;i<10;i++)
{
cin>>a[i];
if(a[i]>=10)
{
count++;
}
}
cout<<"There are "<<count<<" integers which are greater than or equal to 10."<<endl;
}
(output)
3://to swap 1st and last element of an array
for(int i = 0;i<n;i++){
cin>>arr[i]; #include<iostream>
using namespace std;
int main()
{
int n, temp;
cout<<"Enter Number of elements you want to enter :: ";
cin>>n;
intarr[n];
}
temp = arr[0];
arr[0] = arr[n-1];
arr[n-1] = temp;
cout<<"Array after swapping first and last elements "<<endl;
for(int i = 0;i<n;i++){
cout<<arr[i]<<"\t";
}
return 0;
}
sum+= array[k];
avg=sum/num;
cout<< "Average of "<<num<< " numbers is: "<<avg;
}
(OUTPUT)
LAB///07
Write a C++ program which declares two 3 x 3int arrays (Matrices). Store random values using
nested for loops in array and perform Addition and Multiplication of Matrices, stores the result
of operation in another Matrix (output arrays). And displays the results.
#include<iostream>
using namespace std;
int main(){
int arr1[3][3],arr2[3][3],arr_sum[3][3],arr_prod[3][3],i,j,k;
// First array
// Second array
cout<<"\n";
cout<<"\n";
cout<<"\n";
// Displaying addition
cout<<"Result of addition of both matrices: "<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<" "<<arr_sum[i][j];
}
cout<<endl;
}
cout<<"\n";
// Displaying Multiplication
cout<<"Result of Mulitplication of both matrices: "<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<" "<<arr_prod[i][j];
}
cout<<endl;
}
}
(output)
Q.2 WRITE A PROGRAM SEARCH THOURGH THE ARRAY AND FIND MAXIMUM
AND MINIMUM VALUE
#include<iostream>
#include <cstdlib>
using namespace std;
int main(){
int arr[10][10],i,j,max,min,inst;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
arr[i][j] = rand()%10;
}
}
max=arr[0][0];
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(arr[i][j]>max)
max=arr[i][j];
}
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(max==arr[i][j])
{
cout<<"Found at location "<<"["<<i+1<<"]"<<"["<<j+1<<"]"<<endl;
if((i>-1)&&(j>-1))
inst++;
}
}
}
cout<<inst<<" instances found. \n";
cout<<"\n";
/* MINIMUM
VALUE---------------------------------------------------------------------------------------*/
min=arr[0][0];
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(arr[i][j]<min)
min=arr[i][j];
}
}
cout<<"Minimum value in array is: "<<min<<endl;
inst=0;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(min==arr[i][j])
{
cout<<"Found at location "<<"["<<i+1<<"]"<<"["<<j+1<<"]"<<endl;
if((i>-1)&&(j>-1))
inst++;
}
}
}
cout<<inst<<" instances found. \n";
cout<<"\n";
#include<iostream>
#include <cstdlib>
using namespace std;
int main(){
int arr[10][10],inst,i,j,n;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
arr[i][j] = rand()%10;
}
}
cout<<"\n";
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(n==arr[i][j])
{
cout<<"Found at location "<<"["<<i+1<<"]"<<"["<<j+1<<"]"<<endl;
if((i>-1)&&(j>-1))
inst++;
}
}
}
if(inst==0)
{
cout<<"Value not found."<<endl;
exit(0);
}
{
for(j=0;j<10;j++)
{
cout<<" "<<arr[i][j];
}
cout<<endl;
return 0;
}
(OUTPUT)