Posts

Height Pattern Printing

The height of  N  cats is passed as the input. The program must print the height of the cats graphically as a column chart represented by  #  and  -  as shown in the Example Input/Output section. Boundary Condition(s): 2 <= N <= 100 1 <= Height of each cat <= 100 Input Format: The first line contains N. The second line contains N integers representing the height of N cats separated by a space. Output Format: The lines contain the desired pattern as shown in the Example Input/Output section. Example Input/Output 1: Input: 6 10 4 2 6 7 2 Output: # - - - - - # - - - - - # - - - - - # - - - # - # - - # # - # - - # # - # # - # # - # # - # # - # # # # # # # # # # # # Example Input/Output 2: Input: 10 1 2 3 4 5 6 7 8 9 10 Output: - - - - - - - - - # - - - - - - - - # # - - - - - - - # # # - - - - - - # # # # - - - - - # # # # # - - - - # # # # # # - - - # # # # # # # - - # # # # # # # # - # # # # # # # # # # # # # # # # # # # Solution ;-  #include<stdio.

Odd Factors - (Error Identification) skillrack program id - 7306

The program given below must accept an integer N and must  print only the odd factors of N separated by a space . There is a logical error in the program and hence it does not print the desired output.  Please rectify the logical error so that the program prints the expected output. #include<stdio.h> int main() {     int N;     scanf("%d",&N);     for(int ctr=1; ctr <= N; ++ctr)     {         if(N%ctr == 0)         {             if(ctr%2 != 0)             {                 //Odd Factor. So print the output.                 printf("%d ",ctr);             }             else             {                 //Even factor. So dont print                 continue;             }         }     }     return 0; }

Two Matrix Spiral Print

The program must accept two square matrices which are of size  N*N . Then the values in the matrices must be printed spirally in clock wise direction in a single line. The values in a specific row or column of the first matrix must follow the values in the same row or column of the second matrix. Boundary Condition(s): 1 <= N <= 30 1 <= Integer value in the matrix <= 1000 Input Format: The first line contains N. Next 2N lines contain N values each (First N lines contain the values in the first matrix and the next N lines contain the values in the second matrix). Output Format: The first line contains 2*N*N values in the two matrices printed spirally. Example Input/Output 1: Input: 5 10 20 30 40 50 60 70 80 90 91 88 86 34 35 36 21 22 23 24 25 71 72 73 74 75 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 Output: 10 20 30 40 50 101 102 103 104 105 91 36 25 75 110 115 120 125 74 73 72 71 124 123 122 121 21 88 60 1

Swap - Multiples of X and Y

The program must accept  N  integers and two integers  X  and  Y  as the input. The program must swap the first occurring mutiple of X and the last occurring multiple of Y among the N integers. Then the program must print modified values of the N integers as the output. Note : At least one multiple of X and Y are always present in the N integers. Boundary Condition(s): 2 <= N <= 100 1 <= X, Y <= 100 1 <= Each integer value <= 10^8 Input Format: The first line contains the value of N. The second line contains the value of N integers seperated by space(s). The third line contains the value of X and Y seperated by space(s). Output Format: The first line contains the modified value of N integers as per the conditions. Example Input/Output 1: Input: 10 13 28 76 34 86 77 18 92 57 10 7 11 Output: 13 77 76 34 86 28 18 92 57 10 Explanation: The first occurring multiple of 7 among the 10 integers is 28. The last occurring multiple of 11 among the 10 integers is 77

Consonants in Range

The program must accept two lower case alphabets  CH1  and  CH2  as the input. The program must print all the consonants from CH1 to CH2 as the output. Input Format: The first line contains CH1 and CH2 separated by a space. Output Format: The first line contains all the consonants from CH1 to CH2. Example Input/Output 1: Input: a z Output: b c d f g h j k l m n p q r s t v w x y z Explanation: All the consonants (except the vowels) from  a  to  z  are printed as the output. Example Input/Output 2: Input: v h Output: v t s r q p n m l k j h Solution:- #include<stdio.h> #include <stdlib.h> int isvowel(char ch) {     if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')     return 1;     else     return 0; } int main() {     char ch1,ch2;     scanf("%c %c",&ch1,&ch2);       if(ch1<ch2)     {         while(ch1<=ch2)         {             if(!isvowel(ch1))

Longest Palindrome Length

The program must accept a string  S  as the input. The program must print the length of the longest palindrome that can be formed with the consonants in the string S as the output. Note : At least one consonant must be present in the string S. The string S contains only lower case alphabets. Boundary Condition(s): 1 <= Length of S <= 10^4 Input Format: The first line contains the string S. Output Format: The first line contains the length of the longest palindrome in the string S. Example Input/Output 1: Input: abcdeedb Output: 5 Explanation: The longest palindrome can be formed with bbddc (The order can be any but the length is 5). Example Input/Output 2: Input: racecar Output: 4 Solution:- #include<stdio.h> #include <stdlib.h> int main() {     char str[1000];     scanf("%s",str);     int hash[26]={0};     int count=0,c2=0;          int len=strlen(str);     for(int i=0;i<len;i++)     {         hash[str[i]-'a'

Sort the String Values Based on Length

The program must accept  N  string values as the input. The program must sort the string values based on the length of each string value in increasing order. Then the program must print the sorted string values as the output. Note : Each of the string values has a different length. Boundary Condition(s): 1 <= N <= 100 1 <= Length of each string value <= 100 Input Format: The first line contains the integer N. The next N lines contain the string value in each line. Output Format: The first N lines contain the sorted string values. Example Input/Output 1: Input: 4 lemon embezzling banana ant Output: ant lemon banana embezzling Explanation: The length of the string  lemon  is  5 . The length of the string  embezzling  is  10 . The length of the string  banana  is  6 . The length of the string  ant  is  3 . After sorting the string values based on their length are  ant ,  lemon ,  banana ,  embezzling . Hence the output is  ant lemon banana embezzling Example