<< Chapter < Page Chapter >> Page >

2.4) Write a C++ function that checks if a square matrix with order of n is symmetric or not. And then write a C++ program that inputs a square matrix with order of n and then checks if it is symmetric or not.

2.5) A palindrome is a string that reads the same both forward and backward. Some examples are

Given the following function that returns true if the parameter string is a palindrome or false , otherwise.

bool palindrome(char strg[])


int len, k, j;

len = strlen(strg);

k = len/2;

j = 0;

bool palin = true;

while ( j<k&&palin)

if (strg[j] != strg[len -1-j])

palin = false;


++ j;

return (palin)


Write a C++ program that reads several strings, one at a time and checks if each string is a palindrome or not. Use a while loop in your program. The loop terminates when the user enters a string starting with a ‘*’.

2.6) Write a boolean function that can checks if all the elements in integer array are unique (i.e. we can not find any pair of elements that are equal to each other).

Write a C++ program that inputs an integer array and invokes the function to check if all the elements in integer array are unique.

2.7) Given the following formula for computing the number of combinations of m things out of n, denote C(n, m).

C(n, m) = 1 if m = 0 or m=n

C(n, m) = C(n-1, m) + C(n-1, m-1) if 0<m<n

  1. Write a recursive function to compute C(n,m).
  2. Write a complete C++ program that reads two integers N and M and invokes the function to compute C(N,M) and prints the result out.

2.8) The greatest common divisor of two positive integers is the largest integer that is a divisor of both of them. For example, 3 is the greatest common divisor of 6 and 15, and 1 is the greatest common divisor of 15 and 22. Here is a recursive function that computes the greatest common divisor of two positive integers:

int gcd(int p, int q)


int r ;

if (( r = p%q == 0)

return q ;


return gcd(q, r) ;


a. First write a C++ program to test the function.

b. Write and test an equivalent iterative function.

Lab session 7: pointers

1. objective

The objectives of Lab session 7 are to get familiar with how to use pointers in C++.

2. experiment

2.1) Run the following program to determine the size of two data types long and byte.

# include<iostream.h>

void main()


byte* a;

long* b;




2.2) Given the following code segment:

float pay;

float *ptr_pay;


ptr_pay =&pay;

determine the values of the following expressions:

a. pay

b. *ptr_pay

c. *pay


2.3) Read for understanding the following program:


void main()


int a;

int *aPtr; // aPtr is a pointer to an integer

a = 7;

aPtr =&a; //aPtr set to address of a

cout<<“The address of a is “<<&a

<<“\nThe value of aPtr is “<<aPtr;

cout<<“\n\nThe value of a is “<<a

<<“\nThe value of *aPtr is “<<*aPtr



Run the program and explain the output.

2.4) Given the following array and pointer declarations:

int ara[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

int *ip1, *ip2;

Determine which of the following assignments are valid.

a. ip1 = ara;

b. ip2 = ip1 =&ara[3];

Questions & Answers

How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Programming fundamentals in c++. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10788/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Programming fundamentals in c++' conversation and receive update notifications?