Pergunta de entrevista da empresa GGK Tech

WAP to find and print second largest digit in the given number? ( without using arrays, functions and using only one loop).

Respostas da entrevista

Sigiloso

10 de jan. de 2017

while (num>0) { int dig = num % 10; if(dig > largest) { if(seclarg dig && dig > seclarg) seclarg = dig; num /= 10; }

78

Sigiloso

27 de jul. de 2017

while(n){ x=n%10; if(max1x) max2=x; n=n/10; } }

8

Sigiloso

1 de ago. de 2017

#include using namespace std; int main() { int n,x,max1=0,max2=0; cin>>n; while(n>0) { x=n%10; if(max1>x) {if(max2

3

Sigiloso

2 de ago. de 2017

Simple 1(Java) *************** public class Digitna { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int high=0,secondhigh=0,temp; while(n!=0){ temp=n%10; n=n/10; if(temp==high) high=temp; else if(temp>high){ secondhigh=high; high=temp; } else if(temp>secondhigh) secondhigh=temp; } System.out.println(secondhigh); } }

Sigiloso

5 de mar. de 2018

import java.util.*; class Codechef { public static void main (String[] args) { Scanner scan =new Scanner(System.in); System.out.printf("Enter the Numeber n = "); int n=scan.nextInt(); int max=0,secmaximum=0,temp=0,atemp=0; max=n%10; n=n/10; while(n!=0) { temp=secmaximum; secmaximum=n%10; if(max>secmaximum) { if(temp>secmaximum) { secmaximum=temp; } else; } else if(maxsecmaximum) { secmaximum=temp; atemp=max; max=secmaximum; secmaximum=atemp; } else { atemp=secmaximum; secmaximum=max; max=atemp; } } else { secmaximum=temp; } n=n/10; } System.out.printf("\nThe Second maximum number is %d",secmaximum); } }