Posts

Showing posts with the label learn c

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             {              ...

Maximum Negative Elements - Column

The program must accept an integer matrix of size  RxC  as the input. The program must print the column number which has the most number of negative numbers in the given matrix as the output. If more than one column have the most number of negative numbers then the program must print the first ocurring such column number as the output. If the matrix does not contain any negative element then the program must print  -1  as the output. Boundary Condition(s): 1 <= R, C <= 100 Input Format: The first line contains two integers R and C separated by a space. The next R lines contain C integers separated by space(s). Output Format: The first line contains either the column number which has the most number of negative numbers or -1. Example Input/Output 1: Input: 3 4 10 20 11 -12 -22 -23 89 -79 -89 10 29 -12 Output: 4 Explanation: The 1 st  column contains  2  negative numbers. The 2 nd  column contains...