You are on page 1of 8

COMSATS Institute of Information Technology, Wah Campus

Department of Computer Science

SYED WASAY ALI BSE-2A


FA18-BSE-049\WAH 07/MAY/2019.

Assignment 06
Q. No. 1
Read an array of 10 characters in reverse order. Display all elements of the array separately.

#include<iostream>
using namespace std;
int main(){

char arr[10]={'a','b','c','d','e','f','g','h','i','j'};
for(int i=9;i>=0;i--){
cout<<"arr["<<i<<"]=="<<arr[i]<<"\n";

return 0;
}
Q. No. 2
Read an array of 10 floats in reverse order then display every second element of the array in
original order (not reverse order) using a do-while loop.

Q. No. 3
Read the entries of an array of 10 integers from a user. Compute x as the average of the 10
entries and then compute the average of those entries that are greater than or equal to x. Print this
final average.
Q. No. 4
Initialize an array of 5000 integers with zeros. Print last thousand elements of the array using
while loop where every line of the console should print only 10 elements separated with tabs.

#include<iostream>
using namespace std;
int main(){

int arr[5000]={0};
cout<<"array with 5000 elements with zero enteries are";
int i=4000;
while(i<=5000){
cout<<arr[i]<<"\t";
if(i%10==0){
cout<<"\n";
}
i++;
}

return 0;
}
Q. No. 5
Use for loop to insert values in an integer array of 5000 elements in reverse order. First element
of the array should contain 1 and last element should contain 5000.

#include<iostream>
using namespace std;
int main(){

int arr[5000];

for(int a=4999;a>=0;--a){
arr[a]={4};
}
arr[4999]=5000;
arr[0]=1;
cout<<"the last and first element of array are\t"<<arr[4999]<<"and\t"<<arr[0];

return 0;
}
Q. No. 6
Use while loop to check if an array of 9 characters is a palindrome or not. (Hint this is not a
string)

#include<iostream>
using namespace std;
int main(){

int a=0,i=0,count=0,j;
char arr[9]={'a','b','c','d','e','f','g','h','i'};
char ar1[9]={'a','b','c','a','e','a','g','b','i'};

while(a<9){

if(arr[i]==arr[j])

count++;
i++;
j--;
a++;
}
if(count!=0){
cout<<"value is panidrome";
}
return 0;
}
Q. No. 7
Initialize an array of 5000 integers with random values. Print this array using while loop. Sort
this array in descending order using a do-while loop(s). Then print this sorted array in reverse
order using while loop.

Q. No. 8
Initialize a 2D array with all zeros using initializer list and print this 2D array using do-while
loops.

#include<iostream>
using namespace std;
int main(){

int arr[10][10]={0};
int i=0;
do{
int j=0;
do{
cout<<arr[i][j];
j++;
}while(j<10);

i++;
}while(i<10);
return 0;
}

Q. No. 9
Initialize an array of 5000 integers with random values and display the highest value in the array.
Q. No. 10
Initialize an array of 5000 integers with random values and display the smallest value.

You might also like