Interview Question
Country: United States
# include <iostream>
# include <cmath>
# include <cstring>
# include <ctype.h>
using namespace std;
int main()
{
char data[9] = "pulchowk";
// cout<<"test data[0]:"<<data[0];
for (int row = 0; row< 8; row++)
{
for (int col = 0; col<= row; col++)
{
if (row % 2 == 0 )
{
if (col % 2 == 0)
{
cout<<data[col];
//putchar(col);
}
else
{
char t = toupper (data[col]);
cout<<t;
//putchar(col);
}
}
else
{
if (col % 2 == 0)
{
char t = toupper (data[col]);
cout<<t;
}
else
{
cout<<data[col];
}
}
}cout<<endl;
}
return (0);
}
# include <iostream>
# include <cmath>
# include <cstring>
# include <ctype.h>
using namespace std;
int main()
{
char data[9] = "pulchowk";
// cout<<"test data[0]:"<<data[0];
for (int row = 0; row< 8; row++)
{
for (int col = 0; col<= row; col++)
{
if (row % 2 == 0 )
{
if (col % 2 == 0)
{
cout<<data[col];
//putchar(col);
}
else
{
char t = toupper (data[col]);
cout<<t;
//putchar(col);
}
}
else
{
if (col % 2 == 0)
{
char t = toupper (data[col]);
cout<<t;
}
else
{
cout<<data[col];
}
}
}cout<<endl;
}
return (0);
}
# include <iostream>
# include <cmath>
# include <cstring>
# include <ctype.h>
using namespace std;
int main()
{
char data[9] = "pulchowk";
// cout<<"test data[0]:"<<data[0];
for (int row = 0; row< 8; row++)
{
for (int col = 0; col<= row; col++)
{
if (row % 2 == 0 )
{
if (col % 2 == 0)
{
cout<<data[col];
//putchar(col);
}
else
{
char t = toupper (data[col]);
cout<<t;
//putchar(col);
}
}
else
{
if (col % 2 == 0)
{
char t = toupper (data[col]);
cout<<t;
}
else
{
cout<<data[col];
}
}
}cout<<endl;
}
return (0);
}
# include <iostream>
# include <cmath>
# include <cstring>
# include <ctype.h>
using namespace std;
int main()
{
char data[9] = "pulchowk";
// cout<<"test data[0]:"<<data[0];
for (int row = 0; row< 8; row++)
{
for (int col = 0; col<= row; col++)
{
if (row % 2 == 0 )
{
if (col % 2 == 0)
{
cout<<data[col];
//putchar(col);
}
else
{
char t = toupper (data[col]);
cout<<t;
//putchar(col);
}
}
else
{
if (col % 2 == 0)
{
char t = toupper (data[col]);
cout<<t;
}
else
{
cout<<data[col];
}
}
}cout<<endl;
}
return (0);
}
String s="pulchowk";
for(int i=0;i<s.length();i++){
if(i%2==0){
for(int j=0;j<=i;j++){
Character c=s.charAt(j);
if(j%2==0){
System.out.print(c.toString().toLowerCase());
}else{
System.out.print(c.toString().toUpperCase());
}
}
}else{
for(int j=0;j<=i;j++){
Character c=s.charAt(j);
if(j%2==0){
System.out.print(c.toString().toUpperCase());
}else{
System.out.print(c.toString().toLowerCase());
}
}
}
System.out.println();
}
private static void PrintPattern()
{
string str = "pulchowk";
bool startCase = false;
for(int i=0;i<str.Length;i++)
{
if (i % 2 == 0)
startCase = false;
else
startCase = true;
for (int j = 0; j <= i; j++)
{
if (startCase)
{
Console.Write(char.ToUpper(str[j]));
startCase = false;
}
else
{
Console.Write(char.ToLower(str[j]));
startCase = true;
}
}
Console.WriteLine();
}
}
private static void PrintPattern()
{
string str = "pulchowk";
bool startCase = false;
for(int i=0;i<str.Length;i++)
{
if (i % 2 == 0)
startCase = false;
else
startCase = true;
for (int j = 0; j <= i; j++)
{
if (startCase)
{
Console.Write(char.ToUpper(str[j]));
startCase = false;
}
else
{
Console.Write(char.ToLower(str[j]));
startCase = true;
}
}
Console.WriteLine();
}
}
private static void printPattern(String word){
int lenght = word.length();
StringBuffer oddWord = new StringBuffer();
StringBuffer evenWord = new StringBuffer();
for(int i = 0 ; i < lenght ; i++){
char c = word.charAt(i);
if(i%2 != 0){
oddWord.append(c);
evenWord.append(Character.toUpperCase(c));
}else{
oddWord.append(Character.toUpperCase(c));
evenWord.append(c);
}
if(i%2 != 0){
System.out.println(oddWord);
}else{
System.out.println(evenWord);
}
}
}
Which company?
- Animesh February 23, 2015