Wednesday 22 July 2015

Home

Thoughts of Praveen



MY THOUGHTS:





Aptitude




                                               









C Programming










Interview


























Thursday 16 July 2015

Complex Coding in C

COMPLEX CODING IN C








HOSPITAL MANAGEMENT SYSTEM:



















STUDENT DATABASE MANAGEMENT SYSTEM:



















RAILWAY RESERVATION SYSTEM:


















CONTACT MANAGEMENT SYSTEM;






























LIBRARY MANAGEMENT SYSTEM:












SNAKE GAME:
















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;
}





Monday 13 July 2015

zoho interview questions and answer


zoho Interview Questions










ROUND 1: WRITTEN

APTITUDE(1 hr and 20 minutes-20 questions): Problems on average, probability, time & distance, alligation&mixture,ratio, HCF & LCM and few a puzzles.
TECHNICAL(45 minutes-10 questions): Output for C questions. Practice questions in geekquiz.com and C output questions in geeksforgeeks.org. Questions in pointers, strings, matrix etc.
Nearly 60 students were selected out of 600 candidates. They didn’t select the top 60. They had a cutoff and those who cleared the cutoff were called for the next round

ROUND 2: SIMPLE CODING(3 hours)

1. Write a program to give the following output for the given input
Eg 1: Input: a1b10
       Output: abbbbbbbbbb
Eg: 2: Input: b3c6d15
          Output: bbbccccccddddddddddddddd
The number varies from 1 to 99.
2. Write a program to sort the elements in odd positions in descending order and elements in ascending order
Eg 1: Input: 13,2 4,15,12,10,5
        Output: 13,2,12,10,5,15,4
Eg 2: Input: 1,2,3,4,5,6,7,8,9
        Output: 9,2,7,4,5,6,3,8,1 
3. Write a program to print the following output for the given input. You can assume the string is of odd length
Eg 1: Input: 12345
       Output:
1       5
  2   4
    3
  2  4
1      5
Eg 2: Input: geeksforgeeks
         Output:
g                         s
  e                     k
    e                 e
      k             e
        s         g
          f      r
             o
          f     r
        s         g
      k             e
    e                 e
  e                      k
g                          s 
4. Find if a String2 is substring of String1. If it is, return the index of the first occurrence. else return -1.
Eg 1:Input:
        String 1: test123string
         String 2: 123
        Output: 4
Eg 2: Input:
        String 1: testing12
        String 2: 1234 
        Output: -1
5. Given two sorted arrays, merge them such that the elements are not repeated
Eg 1: Input:
        Array 1: 2,4,5,6,7,9,10,13
        Array 2: 2,3,4,5,6,7,8,9,11,15
       Output:
       Merged array: 2,3,4,5,6,7,8,9,10,11,13,15 
6. Using Recursion reverse the string such as
Eg 1: Input: one two three
      Output: three two one
Eg 2: Input: I love india
      Output: india love I 

ROUND 3: COMPLEX CODING(3 hours)

1) Design a Call taxi booking application
-There are n number of taxi’s. For simplicity, assume 4. But it should work for any number of taxi’s.
-The are 6 points(A,B,C,D,E,F)
-All the points are in a straight line, and each point is 15kms away from the adjacent points.
-It takes 60 mins to travel from one point to another
-Each taxi charges Rs.100 minimum for the first 5 kilometers and Rs.10 for the subsequent kilometers.
-For simplicity, time can be entered as absolute time. Eg: 9hrs, 15hrs etc.
-All taxi’s are initially stationed at A.
-When a customer books a Taxi, a free taxi at that point is allocated
-If no free taxi is available at that point, a free taxi at the nearest point is allocated.
-If two taxi’s are free at the same point, one with lower earning is allocated
-Note that the taxi only charges the customer from the pickup point to the drop point. Not the distance it travels from an adjacent point to pickup the customer.
-If no taxi is free at that time, booking is rejected
Design modules for
1)    Call taxi booking 
Input 1:
Customer ID: 1
Pickup Point: A
Drop Point: B
Pickup Time: 9

Output 1:
Taxi can be allotted.
Taxi-1 is allotted

Input 2:
Customer ID: 2
Pickup Point: B
Drop Point: D
Pickup Time: 9

Output 1:
Taxi can be allotted.
Taxi-2 is allotted 
(Note: Since Taxi-1 would have completed its journey when second booking is done, so Taxi-2 from nearest point A which is free is allocated)
Input 3:
Customer ID: 3
Pickup Point: B
Drop Point: C
Pickup Time: 12

Output 1:
Taxi can be allotted.
Taxi-1 is allotted 
2) Display the Taxi details
Taxi No:    Total Earnings:
BookingID    CustomerID    From    To    PickupTime    DropTime    Amount
   
Output:
Taxi-1    Total Earnings: Rs. 400

1     1     A    B    9    10    200
3    3    B    C    12    13    200

Taxi-2 Total Earnings: Rs. 350
2    2    B    D    9    11    350 
These were just sample inputs. It should work for any input that they give.
Those who finished both the
modules within 3 hours and if it worked for all the inputs they give, those candidates were given extra modules to work with.

ROUND 4 : FIRST FACE-TO-FACE(TECHNICAL)

Questions were on project, c, oops concepts, DBMS and a few puzzles. They might ask you more on new scenarios relating to your project.

ROUND 5: SECOND FACE-TO-FACE(TECHNICAL)

Question were on c, c++, java(like threads, synchronization etc.), Discussion about questions from first, second and third round. He even asked me to solve a few questions from the first round. He gave me a few puzzles to solve

ROUND 6: FIRST GENERAL HR

General questions about my pros and cons and discussion on my resume(be thorough with your resume). She finally asked me if I had any queries.

ROUND 7: SECOND GENERAL HR

She asked me some family details and gave some scenarios and asked me to what I will do in such situations(like if I am given the power to change 3 things in india, what all will I change) and a few general questions.


ANSWER;


ROUND 2;
1)

#include<stdio.h>
#include<string.h>
int main()
{
char a[100],t;
int i,j,x,f;
printf("Enter the string:");
scanf("%s",&a);
for(i=0;i<strlen(a);i=i+2)
{
t=a[i];
if((a[i+2]-48)>=0 && (a[i+2]-48)<=9)
{
int x;
x=((a[i+1]-48)*10)+(a[i+2]-48);
for(f=0;f<x;f++)
{
printf("%c",t);
}
i++;
}
else
{
for(j=0;j<a[i+1]-48;j++)
{
printf("%c",t);
}
}

}
return 0;
}

5)



#include<conio.h>
#include<string.h>
void main()
{
int a[100];
int i,j,s,temp;
clrscr();
printf("Enter the size of array:");
scanf("%d",&s);
for(i=0;i<s;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<s;i+=2)
{
for(j=i+2;j<s;j+=2)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=1;i<s;i+=2)
{
for(j=i+2;j<s;j+=2)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("array");
for(i=0;i<s;i++)
{
printf(" \t%d",a[i]);
}
getch();
}


3)

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j,l;
char a[100];
scanf("%s",&a);
l=strlen(a);
for(i=0;i<l;i++)
{
for(j=0;j<l;j++)
{
if(i==j)
{
printf("%c",a[i]);
}
else if(i+j==l-1 && i!=j)
{
printf("%c",a[i]);
}
else
{
printf(" ");
}
}
printf("\n");
}
getch();
}


6)

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[1000];
int i,j,count=0;
clrscr();
gets(a);
for(i=strlen(a)-1;i>=0;i--)
{
count=count+1;
if(a[i]==' '|| i==0)
{
for(j=i;j<=i+count;j++)
{
printf("%c",a[j]);
}
count=0;
}
}
getch();
}

Round 3


#include<stdio.h>
#include<conio.h>
#include<math.h>
#define pf printf
#define c() clrscr()

int check2(char,int);
int check_picpnt(char,int);
int booking();
void details();
int static id;
char dist[6]={'A','B','C','D','E','F'};           /* pick up points */
struct taxi{
     int index;                              /*for each customer*/
     char pic_pnt[10];
     char drp_pnt[10],cur_pos;                   /* struct variables */
     int str_time[10],cust_id[10],end_time[10];
     int wage[10],t_wage;
}t[5];

void main()                                      /* main function */
{
  c();
  for(int i=0;i<5;i++)
  {                                              /* initial position allot */
  t[i].cur_pos='A';
  }
  menu:
  pf("\t\t\t\tWELCOME TO TAXI BOOKING");
  pf("\n\n\n\n\n\t\t MENU");                    /* front page */
  pf("\n\n\n\t\t\t1.TAXI BOOKING");
  pf("\n\t\t\t2.DETAILS\n");
  pf("\t\t\t3.EXIT\n");
  int opt;
  pf("\n\n\t\t\tEnter your option:");
  scanf("%d",&opt);
  switch(opt)
  {
   case 1:
   booking();                               /* calling respective functions */
   c();
   goto menu;
   case 2:
   details();
   getch();
   c();
   goto menu;
   case 3:
   break;
   default:
   pf("Wrong option!!!");
   getch();
   c();
   goto menu;
  }
  getch();
}

int booking()
{                                             /*booking function,second page*/
c();
char p_pnt,d_pnt;
int tme,wag,taxi=0;
pf("\t\t\tbooking menu");
pf("\n\ncustomer_id %d",++id);
pf("\n\npickup_pnt:");
getchar();
scanf("%c",&p_pnt);                          /* getting booking details from user using temp variables */
pf("\ndrop_pnt:");
getchar();
scanf("%c",&d_pnt);
pf("\ntime:");
getchar();
scanf("%d",&tme);
taxi=check_picpnt(p_pnt,tme);            /* checking taxi availability by calling function */
if(taxi!=777)
{
int x=t[taxi].index;
pf("\n\ntaxi %d is alloted",taxi+1);      /* Assigning details to struct variables if function return respective taxis */
pf("\n\nthank for booking");                   /* display alloted taxi number */
int cost=((abs(p_pnt-d_pnt)*15)-5)*10+100; /* calculating cost based on distance*/
t[taxi].pic_pnt[x]=p_pnt;
t[taxi].drp_pnt[x]=d_pnt;
t[taxi].cust_id[x]=id;
t[taxi].wage[x]=cost;
t[taxi].cur_pos=d_pnt;
t[taxi].t_wage=t[taxi].t_wage+cost;
t[taxi].end_time[x]=abs(p_pnt-d_pnt)+tme; /*calculating taxi free time */
t[taxi].str_time[x]=tme;
t[taxi].index++;                    /*increasing for each customer*/
}
else
{pf("\n\nOOPs failed");}            /* taxi is not available*/
getch();
return 0;
}


int check_picpnt(char pic_pnt,int p_tme) /*function to check the pick point*/
{
int flag=0,min=10000,min_ind,get;      /* set the value for min*/
for(int i=0;i<5;i++)
{
 if(pic_pnt==t[i].cur_pos)  /*check the pickpoint of the customer with the current position of the taxi*/
 {
   if(t[i].end_time[(t[i].index-1)]<=p_tme)     /* check the previously allocated time of the customer with the current customer*/
     {
          if(t[i].t_wage<min) /* calculate the minimium wage who earned that day */
           {
            min=t[i].t_wage;
            min_ind=i;/* assigning the minimum index*/
            flag=1;
           }
     }
 }
}
  if(flag==1)
  {return (min_ind);}  /*returning the respective taxi index to the booking function */

  if(flag==0) /*if the taxi is not in that current position*/
  {
    for(int j=0;j<6;j++) /*getting the index of the pick point  */
      {
       if(pic_pnt==dist[j])
       {get=j;
       }
      }
     int k,m,m1,indx,indx1;
  for(j=get-1,k=get+1;j>=0||k<=6;j--,k++) /* checking both the sides of the pickpoint if the taxi is available or not*/
    {
      if(j>=0)
      {
          indx=check2(dist[j],p_tme);/* passing the neighbour value and pick up time */
            if(indx!=-1)
            m=t[indx].t_wage; /* storing the minimum wage in that current point */
            else
            m=10000;
      }
     if(k<=6)
      {
       indx1=check2(dist[k],p_tme);  /* passing the neighbour value and pick up time */
           if(indx1!=-1)
           m1=t[indx1].t_wage;  /* storing the minimum wage in that current point */
           else
           m1=10000;
     }
     if(m1!=10000||m!=10000) /* if both wages of taxi is same then return the lowest index of taxi */
      {
            if(m<m1)
                 {return (indx);}
            else if(m>m1)
                   {return (indx1);}
            else
           {
           if(indx<indx1)
                 {return (indx);}
           else
           {return (indx1);}
           }
     }
   }
 }
return(777);/*returning the error code if no taxi is availble*/
}

int check2(char pic_pnt,int p_tme) 
/*function to check the pick point*/
{
int flag=0,min=10000,min_ind,get; /* set the value for min*/
for(int i=0;i<5;i++)
{
 if(pic_pnt==t[i].cur_pos)   /*check the pickpoint of the customer with the current position of the taxi*/
 {
    if(t[i].end_time[(t[i].index-1)]<=p_tme)   /* check the previously allocated time of the customer with the current customer*/
    {
     if(t[i].t_wage<min) /* calculate the minimium wage who earned that day */
      {
          min=t[i].t_wage;
          min_ind=i;       /*assigning minimum index*/
          flag=1;
      }
   }
 }
}
if(flag==1)
{return (min_ind);}
if(flag==0)            /*returning minimum index to booking function*/
{return (-1);}
return 0;
}
 void details()
  {
   int i,j;
   pf("\t\t\t\tBOOKING DETAILS");
   for(i=0;i<3;i++)
   {
     pf("\n\nTaxi %d details",i+1);   /*print the details based on taxi*/
      pf("\nTotal wage:%d",t[i].t_wage);
     pf("\nc_id  p_pnt  d_pnt  s_tm  e_tm   wage\n");
     for(j=0;j<3;j++)/*print the details based on cust id*/
     {
       pf("%d      %c      %c    %d     %d     %d ",t[i].cust_id[j],t[i].pic_pnt[j],
          t[i].drp_pnt[j],t[i].str_time[j],t[i].end_time[j],t[i].wage[j]);
       pf("\n");
     }
   }
}