You are on page 1of 3

FINAL PRACTICAL EXAM BSCS : PROGRAMMING FUNDAMENTAL

QUESTION #1

Write a function called zero_small() that has two integer arguments being passed by
reference and sets the smaller of the two numbers to 0. Write the main program to
access the function.

SOLUTION

Source Code

#include<iostream>
using namespace std;

void zero_small(int &,int &);

int main()
{
int x,y;
cout<<"Enter first number : ";
cin>>x;
cout<<"Enter second number : ";
cin>>y;
zero_small(x,y);
cout<<"First number is : "<<x;
cout<<"\nSecond number is : "<<y;

return 0;
}

void zero_small(int &a, int &b)


{
if(a<b)
a=0;
else
b=0;
}

Output

SAMPLE RUN # 1

Enter first number : 23


Enter second number : 6
First number is : 23
Second number is : 0
SAMPLE RUN # 2

Enter first number : 23


Enter second number : 56
First number is : 0
Second number is : 56

Question #2 write a program to check a string is palindrome or not by using DEV c++

SOLUTION

#include <iostream>
using namespace std;

int main(){
char string1[20];
int i, length;
int flag = 0;

cout << "Enter a string: "; cin >> string1;

length = strlen(string1);

for(i=0;i < length ;i++){


if(string1[i] != string1[length-i-1]){
flag = 1;
break;
}
}

if (flag) {
cout << string1 << " is not a palindrome" << endl;
}
else {
cout << string1 << " is a palindrome" << endl;
}
system("pause");
return 0;
}

You might also like