Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Capgemini C Language Questions

Last Updated on June 28, 2023 by Mayank Dham

The Capgemini Exceller selection process for 2023 graduates now includes a new round of Capgemini Exceller Coding Questions. This round will be conducted using CoCubes and will consist of two coding questions to be answered in 45 minutes. This round was added to evaluate candidates’ programming, logical, and problem-solving skills. We have provided some previous year sample based questions for the Capgemini Exceller Coding Round below; please practice all of them.

Most Asked Capgemini Questions in C

1. You must write a function that accepts a string of length "len", the string contains some "#", and you must move all the hashes to the front of the string, return the entire string, and print it.

Capgemini C language questions

#include
#include
char *moveHash(char str[],int n)
{
char str1[100],str2[100];
int i,j=0,k=0;
for(i=0;str[i];i++)
{
if(str[i]=='#')
str1[j++]=str[i];
else
str2[k++]=str[i];
}
strcat(str1,str2);
printf("%s",str1);
}
int main()
{
char a[100], len;
scanf("%[^\n]s",a);
len = strlen(a);
moveHash(a, len);
return 0;
}

2. The online written test from Capgemini includes a coding question in which students are given a string containing multiple characters that are repeated consecutively. You must use the mathematical logic shown in the example below to shorten this string.

Capgemini C language questions

#include
int main()
{
    char str[100];
    scanf("%[^\n]s",str);
    int i, j, k=0, count = 0;
    char str1[100];
    for(i=0; str[i]!='\0'; i++)
    {
        count = 0;
        for(j=0; j<=i; j++)
        {
            if(str[i]==str[j])
            {
                count++;
            }
        }
        if(count==1)
        {
            str1[k] = str[i];
            k++;
        }
    }
    for(i=0; i<k; i++)
    {
        count = 0;
        for(j=0; str[j]!='\0'; j++)
        {
            if(str1[i]==str[j])
            {
                count++;
            }
        }
        if(count==1)
        {
            printf("%c",str1[i]);
        }
        else
        {
            printf("%c%d",str1[i],count);
        }
    }
    return 0;
}

3. Create code to traverse a spiral-formatted matrix.

Capgemini C language questions

#include
int main()
{
int a[5][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16},{17,18,19,20}};
int rs = 0, re = 5, cs = 0, ce = 4;
int i, j, k=0;
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\n");
while(rs) 
{
for(i=cs;i<ce;i++)
{
printf("%d\t",a[rs][i]);
}
rs++;

for(i=rs;i<re;i++)
{
printf("%d\t",a[i][ce-1]);
}
ce--;
if(rs=cs; --i)
{
printf("%d\t", a[re - 1][i]);
}
re--;
}
if(cs=rs; --i)
{
printf("%d\t", a[i][cs]);
}
cs++;
}
}
return 0;
}

4. Given an integer array, print the number of times each integer appears in the array.

Capgemini C language questions

#include 
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int count;
    int k=0;
    for(int i=0; i<n; i++)
    {
        scanf("%d",&arr[i]);      
    }
    int newarr[n];
    for(int i=0; i<n; i++)
    {
        count = 0;
        for(int j=0; j<=i; j++)
        {
            if(arr[i]==arr[j])
            {
                count++;
            }
        }
        if(count==1)
        {
            newarr[k] = arr[i];
            k++;
        }
    }
    for(int i=0; i<k; i++)
    {
        count = 0;
        for(int j=0; j<n; j++)
        {
            if(newarr[i]==arr[j])
            {
                count++;
            }
        }
        printf("%d occurs %d times\n",newarr[i],count);
    }
    return 0;
}

5. Write a function to solve the following equation a3 + a2b + 2a2b + 2ab2 + ab2 + b3.

Capgemini C language questions

#include 
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int sum;
    sum=(a+b)*(a+b)*(a+b);
    printf("%d",sum);
}

6. There is a function that displays the number of dealerships and the total number of cars in each dealership. Your job is to figure out how many tyres are in each dealership.

Capgemini C language questions

#include 
int main()
{
    int t,cars,bikes;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%d%d",&cars,&bikes);
        printf("%d\n",cars*4+bikes*2);
    }
}

7. Reverse a String: Write a C program to reverse a given string without using any library functions.

Capgemini C language questions

#include 
#include 


void reverseString(char str[]) {
    int start = 0;
    int end = strlen(str) - 1;


    while (start < end) {
        char temp = str[start];
        str[start] = str[end];
        str[end] = temp;
        start++;
        end--;
    }
}


int main() {
    char str[100];
    printf("Enter a string: ");
    scanf("%s", str);


    reverseString(str);
    printf("Reversed string: %s\n", str);


    return 0;
}


8. Check Palindrome Number: Write a C program to check if a given number is a palindrome or not.

Capgemini C language questions

#include 
int isPalindrome(int num) {
    int reversed = 0;
    int original = num;


    while (num != 0) {
        int remainder = num % 10;
        reversed = reversed * 10 + remainder;
        num /= 10;
    }
    return (reversed == original);
}


int main() {
    int num;
    printf("Enter a number: ");
    scanf("%d", &num);


    if (isPalindrome(num)) {
        printf("%d is a palindrome number.\n", num);
    } else {
        printf("%d is not a palindrome number.\n", num);
    }
    return 0;
}

9. Find Prime Numbers: Write a C program to print all prime numbers from 1 to N.

Capgemini C language questions

#include 
int isPrime(int num) {
    if (num <= 1) {
        return 0;
    }
    for (int i = 2; i <= num / 2; i++) {
        if (num % i == 0) {
            return 0;
        }
    }
    return 1;
}
int main() {
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);


    printf("Prime numbers up to %d:\n", n);
    for (int i = 2; i <= n; i++) {
        if (isPrime(i)) {
            printf("%d ", i);
        }
    }
    printf("\n");


    return 0;
}

10. Fibonacci Series: Write a C program to print the Fibonacci series up to a given number N.

Capgemini C language questions

#include 

void fibonacciSeries(int n) {
    int i, num1 = 0, num2 = 1, nextNum;

    printf("Fibonacci Series up to %d: ", n);

    printf("%d, %d, ", num1, num2);

    for (i = 2; i < n; i++) {
        nextNum = num1 + num2;
        printf("%d, ", nextNum);
        num1 = num2;
        num2 = nextNum;
    }

    printf("\n");
}

int main() {
    int N;

    printf("Enter the number N: ");
    scanf("%d", &N);

    fibonacciSeries(N);

    return 0;
}

11. Find Maximum and Minimum Elements: Write a C program to find the maximum and minimum elements in an array.

Capgemini C language questions

#include 
void findMinMax(int arr[], int size, int *min, int *max) {
    *min = arr[0];
    *max = arr[0];
    for (int i = 1; i < size; i++) {
        if (arr[i]  *max) {
            *max = arr[i];
        }
    }
}
int main() {
    int arr[] = {12, 45, 6, 78, 23, 9};
    int size = sizeof(arr) / sizeof(arr[0]);
    int min, max;
    findMinMax(arr, size, &min, &max);
    printf("Minimum element: %d\n", min);
    printf("Maximum element: %d\n", max);
    return 0;
}

Conclusion
These coding questions cover different concepts such as string manipulation, number manipulation, prime numbers, series generation, and array manipulation. Familiarize yourself with these types of questions and practice solving them to improve your coding skills and prepare for your Capgemini technical interview.

Frequently Asked Questions (FAQs)

Q1. How does Capgemini assess programming skills in C during the interview process?
Capgemini evaluates programming skills in C through a combination of technical questions, coding exercises, and problem-solving scenarios. Interviewers may ask questions about fundamental concepts in C such as pointers, arrays, functions, and memory management. They may also present coding challenges to assess your ability to write efficient and error-free code. Demonstrating a strong understanding of C programming principles, problem-solving techniques, and the ability to translate logic into working code will greatly benefit you in Capgemini interviews.

Q2. What is the significance of pointers in C, and how are they commonly used in programming projects at Capgemini?
Pointers are a fundamental concept in C programming and have various applications in software development. Capgemini recognizes the importance of pointers and their usage in optimizing memory management and data manipulation. Pointers are commonly used in projects at Capgemini for tasks such as dynamic memory allocation, accessing data structures efficiently, and implementing algorithms that involve linked lists or trees. Familiarity with pointer concepts, including pointer arithmetic and passing pointers to functions, is beneficial for succeeding in C-related interviews at Capgemini.

Q3. How does Capgemini evaluate problem-solving abilities in C interviews?
Capgemini assesses problem-solving abilities in C interviews by presenting candidates with real-world scenarios or coding challenges and evaluating their approach to solving them. This evaluation includes analyzing your understanding of the problem, your ability to devise an efficient algorithm or solution, and your implementation skills in C. Emphasize the importance of understanding the problem requirements, designing a logical solution, and writing clean, well-structured code. Practice problem-solving exercises in C to enhance your abilities and demonstrate your problem-solving skills effectively during Capgemini interviews.

Q4. What are some important concepts and functions in C that candidates should be familiar with for Capgemini interviews?
Candidates appearing for Capgemini interviews in C should have a strong grasp of core concepts such as arrays, strings, pointers, structures, and file handling. Additionally, a good understanding of functions like malloc() and free() for dynamic memory management, strcmp() and strcpy() for string manipulation, and fread() and fwrite() for file operations is essential. Familiarity with concepts like recursion, bitwise operators, and error handling techniques can also be advantageous when discussing C-related topics during Capgemini interviews.

Q5.How important is code optimization in C during Capgemini interviews, and what techniques can be employed to improve code efficiency?
Code optimization is a significant aspect of software development in C, and it is valuable to demonstrate an understanding of efficient coding practices during Capgemini interviews. Interviewers may appreciate candidates who can identify and improve areas of code that consume excessive memory, execute slowly, or have poor algorithmic complexity. Techniques such as reducing unnecessary memory allocations, minimizing loop iterations, utilizing appropriate data structures, and employing efficient algorithms can greatly enhance code efficiency. Being able to discuss and apply these optimization techniques in C can positively impact your performance in Capgemini interviews.

Leave a Reply

Your email address will not be published. Required fields are marked *