What will be the output of the following C++ code?
#include <cmath>
#include <iostream>
using namespace std;
void Cipher(string str)
{
int r, c;
for (int i = 0; str[i]; i++)
{
r = ceil((str[i] - 'a') / 5) + 1;
c = ((str[i] - 'a') % 5) + 1;
if (str[i] == 'k')
{
r = r - 1;
c = 5 - c + 1;
}
else if (str[i] >= 'j')
{
if (c == 1)
{
c = 6;
r = r - 1;
}
c = c - 1;
}
cout << r << c;
}
cout << endl;
}
int main()
{
string str = "nsit";
Cipher(str);
}
#include <cmath>
#include <iostream>
using namespace std;
void Cipher(string str)
{
int r, c;
for (int i = 0; str[i]; i++)
{
r = ceil((str[i] - 'a') / 5) + 1;
c = ((str[i] - 'a') % 5) + 1;
if (str[i] == 'k')
{
r = r - 1;
c = 5 - c + 1;
}
else if (str[i] >= 'j')
{
if (c == 1)
{
c = 6;
r = r - 1;
}
c = c - 1;
}
cout << r << c;
}
cout << endl;
}
int main()
{
string str = "nsit";
Cipher(str);
}
A. 33344244
B. 44332434
C. 33432444
D. 11444323
Answer: Option C
Join The Discussion