. Remove all the blank spaces between
character.Matrix is of 10* 10.
eg: INPUT
------------------------------------
| N | A | | V | |T
-------------------------------------
| |G | U | |P |
--------------------------------------
|T | | | A | |
------------------------------------
OUTPUT:
------------------------------------
| N | A | V | T | |
-------------------------------------
|G |U | P | | |
--------------------------------------
|T | A | | | |
------------------------------------

Answers were Sorted based on User's Feedback



. Remove all the blank spaces between character.Matrix is of 10* 10. eg: INPUT -----------..

Answer / indrasen singh

follow these steps..
a) Create 10 by 10 matrix of char array and fill with '|'

b) Now in a loop check your first matrx whether it have alphabet character if found then insert it into the new matrix in the desired position....

char str1[10][10] // suppose it contains your data
char str2[10][10] //it store result

int i,j;

for(i=0;i<10;i++)
for(j=0;j<10;j++)
str2[j]='|';

int charfound;

for(i=0;i<10;i++)
{
charfound=0;
for(j=0;j<10;j++)
{
if(isalpha(str1[j]))
{
charfound++;
str2[((charfound*2)-1)]=str1[j];
}
}
}

Is This Answer Correct ?    1 Yes 5 No

. Remove all the blank spaces between character.Matrix is of 10* 10. eg: INPUT -----------..

Answer / kiran

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package removespacesfrommatrix;

/**
*
* @author Sunshine
*/
public class RemoveSpacesFromMatrix {

void print(char[][] matrix) {
char temp;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (matrix[i][j] != ' ') {
System.out.println(matrix[i][j]);
} else {
temp = matrix[i][j + 1];
matrix[i][j] = temp;
matrix[i][j + 1] = ' ';
System.out.println(matrix[i][j]);
}
}
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
char[][] matrix;
matrix = new char[][]{{'a', 'b', ' ', 'c'}, {' ', 'd', ' ', 'f'}, {' ', ' ', 'x', 'y'}, {'m', 'n', 'o', 'p'}};
RemoveSpacesFromMatrix r = new RemoveSpacesFromMatrix();
r.print(matrix);
}
}

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More C++ Code Interview Questions

Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

0 Answers   Facebook, Webyog, Wipro,


How reader and writer problem was implemented and come up with effective solution for reader and writer problem in case we have n readers and 1 writer.

6 Answers   Microsoft, NetApp,


write a function -oriented program that generates the Fibonacci, the current numbers of n(as input) and display them (series). In Fibonacci, the current third number is the sum of the previous number.

3 Answers  


3. Program to find the Sum of give series. a. (1)+(1+2)+(1+2+3)+(1+2+3+4)+……………………………….. b. 1/1+1/9+1/25+1/49+……………...

0 Answers  


A Binary no. is given, we hav to find it's decimal equivalent.

2 Answers   Microsoft,






Complexity T(n) What is the time complexity T(n) of the following portions of code? For simplicity, you may assume that n is a power of 2. That is, n = 2k for some positive integer k. a) ? for (i = 1; i <= n; i++) { j = n; cout << i << ? ? j << ? ? << endl; } b) ? for (i = 0; i <= n; i += 2) { j = n; cout << i << ? ? j << ? ? << endl; } c) ? for (i = n; i >= 1; i = i/2) { j = n; cout << i << ? ? j << ? ? << endl; } d) for (i = 1; i <= n; i++) { j = n; while (j >= 0) { cout << i << ? ? j << ? ? << endl; j = j - 2; } }

0 Answers   Qatar University,


An array of size 5X5 is given to us. The elements from 1 to 25 are to be inserted in the array, such that starting from a particular position for an element i, the next element i+1can be inserted only at the mentioned positions (u,v), and if these all positions are occupied then it returns giving a count of how many positions have been occupied in the array: (u,v) = (x+/-3 , y) (u,v) = (x , y+/-3) (u,v) = (x+/-2 , y+/-2). Example: if the starting element is 1 with the given positions (1,2), then next element 2 can be placed at any one of the positions marked with *. _ _ _ _ _ 1 _ _ _ * _ _ _ _ _ _ _ * _ _ * _ _ _ _

0 Answers   Nagarro,


using friend function find the maximum number from given two numbers from two different classes.write all necessary functions and constructor for the classes.

1 Answers   TCS,


Write a program using one dimensional array that accept five values from the keyboard. Then it should also accept a number to search. This number is to be searched if it among the five input values. If it is found, display the message “Search number is found!” otherwise, display “Search is lost”. Example: Enter 5 numbers: 10 15 20 7 8 Enter number to search: 7 Search number is found!

2 Answers   College School Exams Tests,


Ask the user to input three positive integers M, N and q. Make the 2 dimensional array of integers with size MxN, where all the elements of I (I = 1,…,M) line will be members of geometrical progression with first element equal to the number of line (I) and denominator q.

0 Answers  


Complexity T(n) Write a linear-time algorithm that sorts n distinct integers, each of which is between 1 and 500. Hint: Use a 500-element array. (Linear-time means your algorithm runs in time c*n + b, where c and b are any constants that do not depend on n. For example, your algorithm can run in time n, or time 2n + 1, or time 5n + 10, or time 100n + 6, but not time c*n*n = c*n?.)

1 Answers   Qatar University,


Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

3 Answers   TCS, Vimukti Technologies, Wipro,


Categories