Coding Questions
Coding Questions
// Output:=
/*
* * * * *
* @ @ @ *
* @ @ @ *
* @ @ @ *
* @ @ @ *
* * * * *
*/
#include <stdio.h>
void Display(int iRow, int iCol)
{
int i = 0, j = 0;
int main()
{
int iValue1 = 0;
int iValue2 = 0;
Display(iValue1, iValue2);
return 0;
}
2) ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////
// Write a program which accept string from user and accept one character. Return
index of last occurrence of that character.
//
// Input:
//
// "Marvellous Multi OS"
//
// M
//
// Output: 11
//
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////
#include <iostream>
using namespace std;
int iCnt = 0;
if (*str == ch)
{
ipos = iCnt;
}
str++;
}
return ipos - 1;
}
int main()
{
int iRet = 0;
char Arr[20];
char cValue = '\0';
return 0;
}
3) Write recursive program which accept number from user and return its product of
digits
//input- 523
// output- 30
#include <iostream>
using namespace std;
if (iNo != 0)
{
iDigit = iNo % 10;
iMult = iMult * iDigit;
iNo = iNo / 10;
ProductR(iNo);
}
return iMult;
}
int main()
{
int iValue = 0;
int iRet = 0;
iRet = ProductR(iValue);
cout << "Product is: " << iRet << endl;
return 0;
}
4) find the maximum value in an array for different data types (e.g., integers,
floats, or doubles) hint : use generic template function
#include <iostream>
using namespace std;
int main() {
// Test case 1: Finding the maximum value in an array of integers
int intArr[] = {3, 5, 7, 2, 8, 1};
int intSize = sizeof(intArr) / sizeof(intArr[0]);
cout << "Maximum value in integer array: " << findMax(intArr, intSize) << endl;
return 0;
}