Wipro Coding Questions - Set 1
Wipro Coding Questions - Set 1
Wipro Coding Questions - Set 1
1) Find the distinct elements in a given array. (Assume size of an array n<=20)
Sample Input:
9 = size of an array
2 3 4 5 6 1 2 3 4 = array elements
Sample Output:
234561
Program:
// C program to print all distinct elements in a given array
#include
void distict_elements(int a[], int n);
int main()
{
int size_array, i, arr[20];
// Get the array size
scanf(“%d”, &size_array)
// Get the array elements
for(i=0; i<size_array; i++)
{
scanf(“%d”, &arr[i]);
}
}
}
Input:
5
86927
Output:
26789
98762
Program:
// C program to sort the given array elements in ascending and descending order
#include
int main(void)
{
int arr[10], i=0, j=0, size, temp;
// Get the size of an array
scanf (“%d”, &size);
// Get the array elements as an input
for (i = 0; i <size; i++)
{
scanf (“%d”, &arr[i]);
}
// Sorting elements in ascending order
for (j=0 ; j<(size-1) ; j++)
{
for (i=0 ; i<(size-1) ; i++)
{
if (arr[i+1] < arr[i])
{
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
// Print the elements from index value 0 to (size-1) –> ascending order
for (i=0 ; i
// Print the elements from the index value (size-1) to 0 –> descending order
for (i=size-1; i>=0 ; i–)
{
Wipro Coding questions – set 1
3) Sort first half of an array in ascending and second half in descending order.
Example 1:
Input:
8
24793168
Output:
12349876
Example 2:
Input:
6
123456
Output:
123654
Algorithm:
Program:
#include
void sorting_elements(int arr[], int n);
void display(int arr[], int n);
int main()
{
int size, arr[20], i;
scanf(“%d”, &size);
for(i=0; i<size; i++)
{
scanf(“%d”, &arr[i]);
}
display(arr, size);
return 0;
}
// Sort the elements in the ascending order
void sorting_elements(int arr[], int n)
{
int i,j,temp;
for (j=0 ; j<(n-1) ; j++)
{
Wipro Coding questions – set 1
// Print the second half in the reverse order (i.e. from n-1 to midlle)
for (j=n-1; j>=n/2; j–)
{
printf(“%d “, arr[j]);
}
}
Input:
3 4
Output:
3
44
555
6666
555
44
3
Input :
4 4
Output:
Wipro Coding questions – set 1
4
55
666
7777
666
55
4
Program:
#include
int main()
{
int i,j,s,N,count=0;
scanf(“%d%d”,&s,&N);
for(i=s;count<4;count++)
{
for(j=0;j<count+1;j++)
printf(“%d”,i);
printf(“\n”);
i=i+1;
}
for(i=s+N-2;count>0;count–)
{
for(j=0;j<count-1;j++)
printf(“%d”,i);
printf(“\n”);
i=i-1;
}
return 0;
}
Input :
3
Output:
1
2*2
3*3*3
3*3*3
2*2
1
Input :
4
Output:
1
2*2
Wipro Coding questions – set 1
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1
Program:
#include
int main()
{
int i,j,k,N,count=0;
scanf(“%d”,&N);
for(i=1;i<=N;i++)
{
k=1;
for(j=0;j<i;j++)
{
printf(“%d”,i);
if(k<i)
{
printf(“*”);
k=k+1;
}
}
printf(“\n”);
}
for(i=N;i>0;i–)
{
k=1;
for(j=0;j<i;j++)
{
printf(“%d”,i);
if(k<i)
{
printf(“*”);
k=k+1;
}
}
printf(“\n”);
}
return 0;
}
Wipro Coding questions – set 1
Input:
4
Output:
1
2*3
4*5*6
7*8*9*10
7*8*9*10
4*5*6
2*3
1
Program:
#include
int main() {
int i,j,count=1,n;
printf(“Enter a number\n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(j<i)
printf(“%d*”,count++);
else
printf(“%d”,count++);
} printf(“\n”);
}
count=count-n;
for(i=n;i>=1;i–)
{ for(j=1;j<=i;j++)
{
if(j<i)
printf(“%d*”,count++);
else
printf(“%d”,count++);
}
count=(count+1)-2*i;
printf(“\n”);
}
return 0;
}