Posts

Showing posts from October, 2019

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; }