Wipro Coding Programming Questions and Answers

30

Wipro conducts the online test for on-campus as well as off-campus drives. In which there is a coding section
that includes two coding questions i.e. it has two problem statements for which the student has to write the
code for that problem statement. So here are some repeated asked questions that helps you with your preparation.

If you want to know more about the recruitment process and syllabus of the Wipro, then must check the below
links:

If you see the old question papers of the Wipro, then you will notice that, if there are two questions in the
coding section then at least one question will be on pattern printing. For that we already provided an
article listed below:

Now in this article, we will only see the most important coding questions of the Wipro. So here are the problem
statement as well as code for that problem statement.

Here is the list of question which covered in this article

Wipro Coding Question – 1

Program to convert decimal number to binary and print count of 1’s

#1. Write a C program to convert a decimal number to binary and print the count of 1’s in it. If 1’s
are not present in binary number, then print invalid input.

Input: 134

Output: 3

Solution in C:

#include<stdio.h>

int main()

{

    int n, rem ,f=1,count=0, bin=0;

    scanf(“%d”,&n);

    while(n>0)

    {

        rem = n%2;

       if(rem == 1)

            count++;

        bin = bin + rem * f;

        f = f * 10;

        n = n / 2;

    }

    if(count > 0)

        printf(“%d”, count);

    else

        printf(“invalid”);

    return 0;

}

Solution in C++:

#include<iostream>

using namespace std;

int main()

{

    int n, rem ,f=1, count=0, bin=0;

    cin>>n;

    while(n>0)

    {

        rem = n%2;

       if(rem == 1)

            count++;

        bin = bin + rem * f;

        f = f * 10;

        n = n / 2;

    }

    if(count > 0)

        cout<<count;

    else

       cout<<“invalid”;

    return 0;

}

Wipro Coding Question – 2

Program which generates following output

Sample Input 1:

4

Sample Output 1:

4 4 4 4

4 4 1 4

4 4 2 4

4 4 3 4

4 4 4 4

Sample Input 2:

3

Sample Output 2:

3 3 3

3 1 3

3 2 3

3 3 3

Solution in C:

#include<stdio.h>

int main()

{

  int n, i, j, c=1;

  scanf(“%d”, &n);

  for(i=1; i<=n+1; i++)

  {

    for(j=1; j<=n; j++)

    {

      if(i!=1 && j==n-1)

      {

        printf(“%d “, c);

        c++;

      }

      else

        printf(“%d “, n);

    }

    printf(“n”);

  }

  return 0;

}

Solution in C++:

#include<iostream>

using namespace std;

int main()

{

  int n, i, j, c=1;

  cin>>n;

  for(i=1; i<=n+1; i++)

  {

    for(j=1; j<=n; j++)

    {

      if(i!=1 && j==n-1)

      {

        cout<<c<<” “;

        c++;

      }

      else

        cout<<n<<” “;

    }

    printf(“n”);

  }

  return 0;

}

Wipro Coding Question – 3

Program to print the sum of digit of the given number

This program is very important and will be helpful for separating the number.

This program is separate the given number and add them in sum variable.

Solution in C:

#include<stdio.h>

#include<string.h>

int main()

{

  char n[20];

  scanf(“%s”, n);

  int len = strlen(n);

  int sum = 0;

  for(int i=0; i<len; i++){

               sum += n[i] – ‘0’;
//This line converts and seperate the string to number

  }

  printf(“%d”, sum);

  return 0;

}

Solution in C++:

#include<iostream>

#include<string.h>

using namespace std;

int main()

{

  char n[20];

  cin>>n;

  int len = strlen(n);

  int sum = 0;

  for(int i=0; i<len; i++){

               sum += n[i] – ‘0’;
//This line converts and seperate the string to number

  }

  cout<<sum;

  return 0;

}

Wipro Coding Question – 4

Program to rotate the given number of array

Input:

6

1 2 3 4 5 6

2

Output:

3       4      
5       6      
1       2

Solution in C:

#include<stdio.h>

int main(){

               int n, r, j=0;

               scanf(“%d”,
&n);

               int a[n];

               for(int i=0;i<n;i++)

                             
scanf(“%d”, &a[i]);

               scanf(“%d”,
&r);

               int temp[n-r];

               for(int i=r;i<n;i++)

                             
temp[i-r] = a[i];

               for(int
i=(n-r);i<n;i++){

                             
temp[i] = a[j];

                             
j++;

               }

               for(int i=0;i<n;i++)

                             
printf(“%dt”, temp[i]);

               return 0;

}

Solution in C++:

#include<iostream>

using namespace std;

int main(){

               int r, n,j=0;

               cin>>n;

               int a[n];

               for(int i=0;i<n;i++){

                             
cin>>a[i];

               }

               cin>>r;

               int temp[n-r];

               for(int i=r;i<n;i++)

                             
temp[i-r] = a[i];

               for(int
i=(n-r);i<n;i++){

                             
temp[i] = a[j];

                             
j++;

               }

               for(int i=0;i<n;i++)

                             
cout<<temp[i]<<“t”;

               return 0;

}

Make sure once you read or overlook this below links for Wipro First Round, this will help you if
any database or data structure related questions will be asked.

Print Prime number series for the given integer

Print the prime numbers from 1 to N, where N is an input.

Sample Input 1:

15

Sample Output 1:

2       3      
5       7      
11      13

Sample Input 2:

5

Sample Output 2:

2       3       5

Solution in C:

#include<iostream>

using namespace std;

bool isPrime(int);

int main(){

               int n;

              
cin>>n;

               for(int
i =
1; i <= n; i++) {

                             
int isPrimeNumber = isPrime(i);

                             
if(isPrimeNumber == true) {

                                            
cout<<i<<“t”;

                             
}

               }

               return
0;

}

// This function is identifying the number is prime or not 

bool isPrime(int n){

               bool
flag =
false;

               for(int
i=2;
i<=n/2; i++){

                             
if(n%i == 0){

                                            
flag = true;

                                            
break;

                             
}

               }

               if(flag
==
false && n > 1){


                             
// Number is prime

                             
return true;

               }

// Number is not a prime

               return
false;

}

Solution in C and for better understanding the concept of prime numbers, check it out this: Prime Number Program in C

LEAVE A REPLY

Please enter your comment!
Please enter your name here