Sapient Corporation Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
2
of 2 vote

#include<iostream>
using namespace std;
int main()
{

long int a;
cin>>a;

int last= a%10;
int sum=0;
a=a/10;
int temp;
while(a!=0)
{

temp=a%10;
temp*=temp;
temp%=10;
sum+=temp;
sum%=10;

a=a/10;


}

if(last== sum)
{

cout<<"valid";

}
else
{
cout<<"invalid";
}
}

- T-Bon3 February 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

no need to use this segment of code :: temp%=temp;

- john October 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

main()
{
int i,last,q,s,sum=0;
printf("enter");
scanf("%d",&i);
q=i/10;
last=i%10;
while(q)
{
s=q%10;
sum=sum+s*s;
q=q/10;
}

if(last==(sum%10))
printf("valid");
else
printf("invalid");
getch();
}

- Anonymous August 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Checksum {

public static void main(String[] args) {
String num = "321541";
char[] ch = num.toCharArray();
int mult = 0;
for (int i = 0; i < ch.length - 1; i++) {
int val = ch[i] - '0';
mult += val * val;
}
int t = checkCheckSum(mult);
if (t == ch[num.length() - 1]-'0') {
System.out.println("Check Sum Valid");
} else {
System.out.println("Check Sum Invalid :: " + t);
}
}

private static int checkCheckSum(int number) {
String mul = String.valueOf(number);
while (mul.length() > 1) {
char a[] = mul.toCharArray();
int sum = 0;
for (Character c : a) {
int v = c - '0';
sum = sum + v;
}
mul=String.valueOf(sum);
}
return Integer.parseInt(mul);
}
}

- Sunil Kumar Tamoli October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package Interview_Specific;

import java.util.Scanner;

/**
 * Created by GOOGLE on 8/21/2015.
 */
public class ValidChecksum {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("--------PLEASE ENTER INPUT CHECKSUM-------\n");
        int inputNum = in.nextInt();
        int lastDigit = (inputNum % 10);
        System.out.println("last digit: " + lastDigit);
        int remainingNum = (inputNum / 10);
        System.out.println("remaining number: " + remainingNum);
        int checksum = 0;
        while ((remainingNum % 10) > 0) {
            checksum = checksum + calculatePower((remainingNum % 10), 2);
            System.out.println("checksum at this point of time: " + checksum);
            remainingNum = remainingNum / 10;
        }
        if (checksum == calculatePower(lastDigit, 2))
            System.out.println("----CHECKSUM IS VALID----" + checksum);
        else
            System.out.println("----CHECKSUM IS INVALID----" + checksum);
    }

    private static int calculatePower(int i, int j) {
        System.out.println("value of i and j :" + i + " " + j);
        if (j == 0)
            return 1;
        else {
            i = i * calculatePower(i, --j);
        }
        System.out.println("final value of power: " + i);
        return i;
    }
}

- aditya15goyal August 20, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More