Tuesday 14 July 2015

zoho interview question and answer in programming round





Display Pattern

Problem Statement

Print the word with odd letters as

Input Format

String should have odd number of characters.

Output Format




 
Refer above pattern

Sample Input

PROGRAM

Sample Output

Refer above pattern



Code:


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    char a[100];
    int i,j,b,k,n;
    scanf("%s",a);
    n=strlen(a);
    for(i=0,j=n-1;i!=j;i++,j--)
        {
        printf("%c",a[i]);
        for(k=1;k<n/2;k++)
            {
            printf(" ");
        }
        printf("%c",a[j]);
        n=n-2;
        printf("\n");
     
    }
    n+=2;
   printf("%c\n",a[i]);
     for(i--,j++;i>=0;i--,j++)
        {
        printf("%c",a[i]);
        for(k=1;k<n/2;k++)
            {
            printf(" ");
        }
        printf("%c",a[j]);
        n=n+2;
        printf("\n");
    }
    return 0;
}


Twice the Vowel

Problem Statement

If a vowel is found in the given string twice that vowel character of a string in the same array efficiently.

Input Format

The first line contains the number of test cases T. Next T lines contains an input string.

Output Format

Print the modified string.

Sample Input

1
Tamil

Sample Output

Taamiil

Code:


#include<stdio.h>
int check_vowel(char);

int main()
{
  char s[100];
  int i, j = 0;
    int count=0;
    int n;
    scanf("%s",s);
    n=strlen(s);

printf("%d%s",n,s);
 for(i = 0; i<n; i++)
  {
    if(check_vowel(s[i])==1)
       
    {
        for(j=n-1;j>=i;j--){
            s[j+1]=s[j];}
        i++;
    }
    n++;
      }
   

  printf("String after repeating vowels: %s\n", s);
  return 0;
}


int check_vowel(char c)
{
  switch(c) {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
      return 1;
      break;
    default:
      return 0;
  }}





String Rotation 1


Problem Statement

Given two string s1 and s2 how will you check if s1 is a rotated version of s2 ?
If s1 = “crazyforcode” then the following are some of its rotated versions:
“forcodecrazy”
“codecrazyfor”

Input Format

Two strings S1 and S2.
Length(S1), Length(S2) > 1

Output Format

Print "YES" or "NO" without double quotes.

Sample Input

crazyforcode
codeforcrazy

Sample Output

NO




code:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

    char a[100],b[100],t[100];
    int i,j,n,count;
    scanf("%s%s",a,b);
    n=strlen(a);
        for(j=0,i=0;j<n;j++){
            if(b[i]==a[j])
                {
                count++;
                i++;
            }
            else{
                i=0;
                count=0;}
        }
    for(i=0,j=0;i<n;i++,count--)
        {
        if(count>0)
            t[i]=a[n-count];
        else{
            t[i]=a[j++];
        }
    }
    count=0;
    for(i=0;i<n;i++){
        if(b[i]==t[i])
            count++;
    }
    
    if(n==count)
        printf("YES");
    else
        printf("NO");
    return 0;
}





2 comments: