Mindtree Coding
Mindtree Coding
Coding section consists of 2 questions from coding , wherein the student is required to code in
any language of their choice
1) Pattern
for n=5
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15
1
2*3
4*5*6
2) for n=4,s=3
3
44
555
6666
6666
555
44
3
3) Print all the prime numbers which are below the given number separated by comma.
4) Remove all the vowels from a given string using pointers concept
6) A pattern.
1
22
333
4444
55555
4444
333
22
1
7. Write a function to return a sorted array after merging two unsorted arrays, the parameters will
be two integer pointers for referencing arrays and two int variable, the length of arrays (Hint: use
malloc() to allocate memory for 3rd array):
8. calculate GCD of two integers a and b which is a direct question and second was merge sort in
Array
12. Arranging K number of elements of an array in ascending order, remaining in descending order.
2
33
444
5555
5555
444
33
2
21. you have three dice each side is numbered as 1,2,3,4,5,6 .you have to take a
number from user check that number as sum of any side number of these
three dice.like we take number as 5 then the possibility are (1,1,3) (1,2,2)
(1,3,1) (2,1,2) (2,2,1) (3,1,1) and is 6 possibility. So write to a program for that.
You can write program in c.
/**
*/
#include <stdio.h>
int main()
{
int i, j, n, isPrime; //isPrime is used as flag variable
/* Reads upper limit to print prime */
scanf("%d", &n);
isPrime = 1;
/*
*/
if(i%j==0)
isPrime = 0;
break;
if(isPrime==1)
return 0;
Note: For checking whether a number is Prime or not we just need to check that the number
should not be divisible by any number between 2 to n-1 . Apart from that you can also check
between 2 to n/2 . Since any number more than (n/2)+1 cannot be exactly divided by n except
self n .
Output
Find prime numbers between 1 to : 100
/**
*/
#include <stdio.h>
int main()
/*
*/
/*
*/
hcf = i;
}
printf("HCF of %d and %d = %d\n", num1, num2, hcf);
return 0;
Output
Enter any two numbers to find HCF: 12
30
HCF of 12 and 30 = 6
/**
*/
#include <stdio.h>
int main()
/*
*/
i = max;
while(1)
lcm = i;
break;
i += max;
return 0;
}
Output
Enter any two numbers to find LCM: 12
30
LCM of 12 and 30 = 60
/**
*/
#include <stdio.h>
#include <string.h>
int main()
gets(string);
len = strlen(string);
index = 0;
wordStart = len - 1;
wordEnd = len - 1;
while(wordStart > 0)
// If a word is found
i = wordStart + 1;
reverse[index] = string[i];
i++;
index++;
wordEnd = wordStart - 1;
wordStart--;
reverse[index] = string[i];
index++;
return 0;
/**
*/
#include <stdio.h>
#define BASE 10
int main()
int i, lastDigit;
int freq[BASE];
scanf("%lld", &num);
freq[i] = 0;
while(n != 0)
lastDigit = n % 10;
freq[lastDigit]++;
n /= 10;
return 0;
}
Output
Example:
Input N: 5
Output:
1
11
101
1001
11111
/**
*/
#include <stdio.h>
int main()
int i, j, N;
printf("Enter N: ");
scanf("%d", &N);
for(i=1; i<=N; i++)
printf("1");
else
printf("0");
printf("\n");
return 0;
Enter N: 5
1
11
101
1001
11111
*/
#include <stdio.h>
int main()
int i, j, N;
printf("Enter N: ");
scanf("%d", &N);
printf("%d", j);
printf("\n");
printf("%d", j);
printf("\n");
return 0;
Enter N: 5
1
123
12345
1234567
123456789
1234567
12345
123
1
Program to print the given number pattern
Example:
Input N:
Output:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
/**
*/
#include <stdio.h>
int main()
int i, j, N;
printf("Enter N: ");
scanf("%d", &N);
for(j=i; j<=(i*i); j += i)
printf("%-3d", j);
printf("\n");
return 0;
</stdio.h>
Enter N: 5
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25