Software engineer Interview Questions | Glassdoor.co.in

# Software engineer Interview Questions

89,857

software engineer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

23 Apr 2010

17 Apr 2018
hai

16 Feb 2016

4 Oct 2017

24 Dec 2015

20 Aug 2017

### PHP Developer at WebKul was asked...

11 Sep 2016
 Q1. Draw star pattern like. n=1. * n=2. ** * n=3. *** ** * n=4 **** *** ** * n=5. ***** **** *** ** *16 Answers#include int main() { int n=10,i,j,s,sum=1,l,k; for(k=1;k=1;i--){ l=sum-i; for(s=1;s<=l;s++){ printf(" "); } for(j=1;j<=i;j++){ printf("*"); } l=l+1; sum=l; printf("\n"); } return 0; }#include int main() { int n,i,j,k,l=1; for(n=1;n=1;i--) { if(n==3) {for(k=i-1;k>=1;k--) printf(" "); } if(n==4) { if(i>2) {for (k=i-1;k>=l;k--) printf(" "); } l++; } if(n==5) { if(i>2) { for(k=i+2;k>=l-2;k--) { printf(" "); } l++; } } for(j=i; j>=1;j--) { printf("*"); } printf("\n"); } printf("\n"); } }import java.util.Scanner; class New { public static void main(String ... args) { Scanner sc =new Scanner(System.in); int n=sc.nextInt(); int p=n-2; for(int i=1;i<=n;i++) { for(int j=1;j<=(p*(p+1))/2;j++) System.out.print(" "); p--; for(int k=1;k<=n-i+1;k++) System.out.print("*"); System.out.println(""); } } }Show more responsesspace is 1+2+3+...(n-2) Code is as follow: public class Pattern { public static void main(String ...args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=n;i>=1;i--) { for(int j=1;j<=(i-1)*(i-2)/2;j++) System.out.print(" "); for(int j=1;j<=i;j++) System.out.print("*"); System.out.println(); } } }public class Pattern11 { public static void main(String[] args) { int number = 6, count = number; for (int i = 1; i <= number; i++) { for (int j = 1; j <= (number - i) + count; j++) { if (j <= number - i) { System.out.print(" "); } else { System.out.print("*"); } } count = count - 1; System.out.println(); } } }int main() { int i,j,s,n; scanf("%d",&n); for(i=1;i<=n;i++) { for(s=1;s<=n-i;s++) { printf(" "); } for(j=1;j<=(n+1)-i;j++) { printf("*"); } printf("\n"); } }x=int(input()) for i in range(x,0,-1): for k in range(i-1,0,-1): print(" ",end="") for j in range(i,0,-1): print("*",end="") print()#include int main() { // Input n from user and make h,s,n all equal // Input 5 is taken randomly it can be any thing int h = 5; int n = 5; int s ; s=n; for(int u = 0; u 0 ; s-- ) { printf(" "); } for(int s = h ; h>0 ; s-- ) { printf("*"); h--; } printf("\n"); h = n - 1; }import java.util.*; import java.io.*; class Starpattern5 { public static void pattern(int n) { int i,j; for (i=n;i>=1;i--) { for (j=1;j<=((2*i)-1);j++ ) { if (jimport java.util.*; import java.io.*; class Starpattern5 { public static void pattern(int n) { int i,j; for (i=n;i>=1;i--) { for (j=1;j<=((2*i)-1);j++ ) { if (j2){ for(\$j=3;\$j= 2){ echo " "; } \$count--; for(\$k=\$val;\$k>=\$i;\$k--){ echo "*"; } echo "
"; } } ?>Import java.util.Scanner; Class web { Static void web(int n) { for(int i=n;i>=1;i--) { for(int j=0;j<=n;j++) System.out.print("*"); } System.out.println("\t"); } } Public static void main(String args[]) { Scanner sc =new Scanner(System.in); Int n=sc.nextInt(); Web(n); } }#in python n= int(input('enter the max no.')) for i in range(n): print('*'*(n-i), end=' ')Show more responsesn=int(input("")) for i in range(n+1): print(" "*(n-i-1 )+"*"*(n-i))=(\$n+1-\$i) && \$j One or more comments have been removed. Please see our Community Guidelines or Terms of Service for more information.

19 Mar 2009
 Come out with an algorithm for getting the column number provided the column name in a excel sheet and vice versa. Excel has a naming convention of A,B..Z,AA,AB,AC..ZZ,AAA... This had to be converted to the column numbers. A will be 1 and AA will 27.. Also the algorithm to find the name provided column number.13 AnswersIts conversion from decimal to base 26 with some exception like there is nothing maps to zero. There might be a better way to do it.void printColumn(uint32_t col) { col --; int div = 26; int add = 26; while( col / div ) { div *= 26; } div /= 26; while( div != 1) { printf("%c", (col / div) + 'a' - 1); col = col % div; div /= 26; } printf("%c\n", col + 'a'); }Opps above does not work after ZZ. The correct one is void printColumn(uint32_t col) { int a = 26; int denominator = 1; while(a 0; i /= 26) low += i; // if value is lower than lower bound, decrease quotient by one if( denominator != 1 && col < (quotient * denominator + low) ) { quotient --; } printf("%c", quotient - 1 + 'A'); col = col - denominator * quotient; denominator /= 26; } }Show more responsesLet the size of the string asked is 3 e.g GHD . The formula to this : [ 26+26^2+...+ 26^(size-1) + (LetterIndex-1)*{26^(size-1)+....+(LetterIndex-1)*26}+Index ]In the code the above formula will use recursion to find the column number.The answer can be as simple as finding the first combination of number * i such that it is less then xcelcolvalue; ie repeat this till xcelColValue >= 26 ( 0 = 26){ int i = 1, num = 1; while((num * (i + 1)) 26){ i = 1; num++;} else i++; xcelNum -= num*i; sb.append((char) i); } if (xcelNum > 0) sb.append((char) xcelNum); return sb.toString(); }Also the above code is rough idea and not tested but gives enough idea on simplifying the solution. The code does not use lot of / and % calcuations but could elegantly find the solution. Note the Gaurd if(i > 26){ i = 1; num++;} else i++; which is important in finding the combination of num and i which multiples at least to xcelNum.I think the above is incorrect and it should be : public static String xcelString(int xcelNum) { StringBuffer sb = new StringBuffer(); while(xcelNum >= 26){ int i = 1; for(;(26 * (i + 1)) 0) sb.append((char) xcelNum); return sb.toString(); }Edge conditions aside, the program would be /* inputString - the column name. For e.g. "BZC" */ char [] columnName = inputString.toUpperCase().toCharArray(); int columnNumber = 0; for(int i = 0; i < columnName.length - 1; i++){ columnNumber = columnNumber + (int) Math.pow(26, (columnName.length - 1 - i)) * (columnName[i] - 64) ; } columnNumber = columnNumber + (columnName[columnName.length - 1] - 64); System.out.println("Column number is " + columnNumber);Edge conditions aside, the program would be /* inputString - the column name. For e.g. "BZC" */ char [] columnName = inputString.toUpperCase().toCharArray(); int columnNumber = 0; for(int i = 0; i < columnName.length - 1; i++){ columnNumber = columnNumber + (int) Math.pow(26, (columnName.length - 1 - i)) * (columnName[i] - 64) ; } columnNumber = columnNumber + (columnName[columnName.length - 1] - 64); System.out.println("Column number is " + columnNumber);int columnNumber(String col) { result = 0; for(i = 0;i< strlen(col) ; i++) { result *= 26; result + = col[i] - 'A' +1; } }int columnNumber(String col) { result = 0; for(i = 0;i< strlen(col) ; i++) { result *= 26; result + = col[i] - 'A' +1; } }public static String numToExcel(int n) { if(n 0) { int remainder = n%26; char newChar = (char) ('Z' - (26 -remainder)%26); result = newChar + result; n = (n-1)/26; } return result; }

### Software Developer at Knab was asked...

27 Aug 2016
 Scan an integer and print the alphabet so that: 1-A; 2-B...26-Z; 27-AA,28-AB,29-AC...52-AZ; 53-AAA,54-AAB,55-AAC...78-AAZ...etc.. If you provide an integer, say 28-it should print AB. If you scan another integer say 55, it should show AAC12 AnswersI was not able to complete within 20 minutes, hence got rejected.#include #include int main() { int n=0,ap=0; printf("Enter no - "); scanf("%d",&n); ap=n%26; while(n>26) { printf("A"); n-=26;; } switch(ap) { case 1 : printf("A"); break; case 2 : printf("B"); break; case 3 : printf("C"); break; case 4 : printf("D"); break; case 5 : printf("E"); break; case 6 : printf("F"); break; case 7 : printf("G"); break; case 8 : printf("H"); break; case 9 : printf("I"); break; case 10 : printf("J"); break; case 11 : printf("K"); break; case 12 : printf("L"); break; case 13 : printf("M"); break; case 14 : printf("N"); break; case 15 : printf("O"); break; case 16 : printf("P"); break; case 17 : printf("Q"); break; case 18 : printf("R"); break; case 19 : printf("S"); break; case 20 : printf("T"); break; case 21 : printf("U"); break; case 22 : printf("V"); break; case 23 : printf("W"); break; case 24 : printf("X"); break; case 25 : printf("Y"); break; case 0 : printf("Z"); break; default : break; } }#include #define N 26 int main(){ int i,no,no1; printf("\n Enter number : "); scanf("%d",&no); if(no 26){ printf("A"); no1 -= 26; } if(no == 0) no = 26; // code for finding the particular alphabet from A-Z for(i = no; i <=no; i++){ printf("%c",'@'+i); } } return 0; }Show more responses#include int main(){ int i,no,no1; printf("\n Enter number : "); scanf("%d",&no); if(no 26){ printf("A"); no1 -= 26; } if(no == 0) no = 26; // code for finding the particular alphabet from A-Z for(i = no; i <=no; i++){ printf("%c",'@'+i); } } return 0; }import java.util.Scanner; public class Alpha { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(),temp=0, count = 0,rem=0; String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if(n26){ count = n/26; rem = n%26; if(rem != 0){ for (int i = 0; i < count; i++) { System.out.print("A"); } temp = n - count*26; System.out.print(alpha.charAt(temp-1)); } else{ for (int i = 0; i < count-1; i++) { System.out.print("A"); } System.out.println("Z"); } } } }#include int main() { int num; printf("enter a number\n"); scanf("%d",&num); while(num>26) { printf("A"); num=num-26; } if(num<=26) { printf("%c",num+64); } return 0; }#include int main() { int n; printf("Enter a Number ::: "); scanf("%d",&n); int tmp =n/26; int val=0; while (tmp>0) { tmp--; if (tmp==0 && n%26==0) { printf("Z"); val++; break; } if (!(tmp<0)) { printf("%c",65); } } if (val!=1) { printf("%c", (n%26)+64); } printf("\n"); }By mistake I pressed down vote. Nice code - > PoornimaBimport java.util.*; public class Program3 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n26)&&(n52)&&(n<78||n<=78)) { int a=n%26; a--; int b=65+a; char ch=(char)b; if(n==78) ch='Z'; System.out.println("AA"+ch); } } }import java.util.*; public class Program3 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n26)&&(n52)&&(n<78||n<=78)) { int a=n%26; a--; int b=65+a; char ch=(char)b; if(n==78) ch='Z'; System.out.println("AA"+ch); } } }LANGUAGE OF MY CODE IS JAVA BUT IT WILL HELP YOU TO GET LOGIC public class part2 { public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("enter a number"); int n=scan.nextInt(); int fact; fact=n/26; if(n%26==0){ fact=fact-1; } for(int i=0;iLEFT PORTION OF ABOVE CODE IS HERE for(int i=0;i

### Junior Software Engineer at Pratian Technologies was asked...

15 Jun 2015
 write a program to print the given series (user need to enter the nth series number from keyboard) 2,3,5,11,23,29,41,53,83,89 .....n11 Answersimport java.util.Scanner; public class prg2 { public static void main(String[] args) { //2,3,5,11,23,29,41,53,83,89 .....n int i,count=0,n,j,flag,x=0; System.out.println("Enter number of term:"); Scanner sc=new Scanner(System.in); n=sc.nextInt(); for(i=2;true;i++){ flag=1; for(j=2;j<=i/2;j++){ if(i%j==0){ flag=0; break; } } if(flag==1){ ++count; if(count%4!=0){ System.out.println(i); ++x; } } if(x==n) break; } } }import java.util.Scanner; public class Series2 { static Boolean prime(int p) { for(int i=2; iwhat's the logic?Show more responses#include main() { int i,k,n,m,count=0; scanf("%d",&n); for(i=2;i<=n;i++) { for(k=0;k<=i;k++) { if((i%k==0)) count++; } if(count==2) m=2*i+1; count==0; for(k=0;(m!=0)&&(k<=m);k++) { if((m%k==0)) count++; } if(count==0) printf("%d",m); } }#include main() { int i,n,p,k,count=0,plus=0; printf(:enter the no\n"); scanf("%d",&n); for(i=2;i#include int prime(int num) { int i,c=0; for(i=2;iAnswer is in java :100% correct public class ProgramDemo { public static void main(String[] args) { System.out.println("Enter the value :"); Scanner read = new Scanner(System.in); int number = read.nextInt(); for(int i=2;i<=number;i++){ if(Prime(i)){ if(Prime(2*i+1)){ System.out.print(" "+i); } } } } static boolean Prime(int a) { int temp, c; for (c = 2; c <= a - 1; c++) { temp = a % c; if (temp == 0) { return false; } } if (c == a) { return true; } return false; } } I Hope its helpful for you :) Plese give me one like for it ....Excellent broimport java.util.Scanner; public class HelloJava { public static void main(String args[]) { int i,flag=0; for( int x = 2 ;x<100 ;x++) { flag=0; for(i=2;i<=x-1;i++) { if(x%i==0) { flag = 1; break; } } if(flag==0) { for( i = 2; iCan anyone please explain the logic?#include #include void main() { int i; printf("Enter no. of terms \n"); for(i=2; i<=50 ; i= 2*i+1) { printf("\n %d", i); } return 0; }
110 of 89,857 Interview Questions