Posts

Showing posts from January, 2018

Zoho second round Print the elements of an array in the decreasing frequency.

Print the elements of an array in the decreasing frequency.   Examples: Input: arr[] = {2, 5, 2, 8, 5, 6, 8, 8} Output: arr[] = {8, 8, 8, 2, 2, 5, 5, 6} Input: arr[] = {2, 5, 2, 6, -1, 9999999, 5, 8, 8, 8} Output: arr[] = {8, 8, 8, 2, 2, 5, 5, 6, -1, 9999999} C programming #include<stdio.h> #include<conio.h> int main() { int i=0,n,num[100],j=0,temp=0,count=0,k=0,max=0,l=0,m=0; int a[100],b[100]; scanf("%d",&n); for (i=0;i<n;i++) {     scanf("%d",&num[i]); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(num[i]<num[j]) { temp =num[i]; num[i]=num[j]; num[j]=temp; } } } for(i=0;i<n;i=j) { for(j=i+1;num[i]==num[j];j++) { count+=1; } a[k]=num[i]; b[k]=count+1; k+=1; count=0; } for(i=0;i<k;i++) { for(j=0;j<k;j++) { if(max<b[j]) {max=b[j];l=j;} } for(m=0;m<max;m++){printf("%d ",a[l]);} b[l]=0; max=0; } getch(); return 0; } Happy coding

Zoho Second round - adding a digit to all the digits of a number

Adding a digit to all the digits of a number eg digit=4, number = 2875, o/p= 612119 C Program: #include<stdio.h> #include<conio.h> #include<string.h> int main() {     int t,n,i=0;     char num[100];     printf("Enter the digit: ");     scanf("%d",&n);     printf("Enter the number: ");     scanf("%s",num);     printf("o/p ");     for(i=0;i<strlen(num);i++)     {     printf("%d",num[i]-'0'+n);     }  getch();  return 0; }  

Zoho Second round - count odd and even number

Print the total number of odd and even digits in the given number. Ex. Input : 1234567 Output : ODD 4 EVEN 3     #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> int main() { int n,odd=0,even=0; int i=0,num,t; scanf("%d",&n); while(n>0) { t=n%10; n/=10; if(t%2==0) {even+=1;} else {odd+=1;} } printf("Even :%d\n",even); printf("Odd : %d",odd); getch(); return 0; }   Happy coding!!!

Zoho Second round question - X Form String

Print the word with odd letters as P M R A O R G O R R A P M      Print in X form  C++ Program: #include<iostream> #include<conio.h> #include<string.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); for(int i = 0; i<=(n-1)/2;i++) { if(i!=n-1-i) { for(int j=0;j<i;j++) {cout<<" ";} cout<<s[i]; for(int j=i+1;j<n-i;j++) {cout<<" ";} cout<<s[n-1-i]; cout<<"\n"; } else { for(int j=0;j<i;j++) {cout<<" ";} cout<<s[i]<<"\n"; } } int k =(n-1)/2; int m = (n-1)/2; int l=(n-1)/2; for(int i = 0; i<=(n-1)/2;i++) { m=m-1; l=l+1; for(int j=0;j<m;j++) { cout<<" "; } cout<<s[m];

Zoho - Second round- Reversing the vowels

Given a string, reverse only the vowels present in it and print the resulting string. Input : First line of the input file contains an integer T denoting the number of test cases. Then T test cases follow. Each test case has a single line containing a string. Output : Corresponding to each test case, output the string with vowels reversed. Example: Input: practice Output: prectica C++ Program: #include<iostream> #include<conio.h> #include<string.h> using namespace std; int main() {     string a,b;     cin >> a;     int len= a.length();     int count=0;     for(int i=0;i<len;i++)     {     if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')     {     b=b+a[i];     count+=1;     }     }     for(int i=0;i<len;i++)     {     if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')     {     count -=1;     a[i]=b[count];         }     }     cout <&

Zoho interview question Question and Answer

Given an array of integers, rearrange the array in such a way that the first element is first maximum and second element is first minimum. Example —> Input: {1, 2, 3, 4, 5, 6, 7} | Output : {7, 1, 6, 2, 5, 3, 4} C++ Program  #include <iostream> #include<conio.h> using namespace std; int main() { int a[100],n=0,temp,max,min; cin >> n; for(int i=0;i<n;i++) { cin>>a[i]; } cout<<"\n"; for(int i=0 ;i<n;i++) { for( int j=i+1;j<n;j++) { if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } max=0; min=n-1; for(int i=1 ;i<=n;i++) { if(i%2==0) { cout<<a[min--]; } else { cout<<a[max++]; } } getch(); return 0; }   Happy Coding!!