• Write a function subtract that takes 2 positive integers, say num1 and num2, subtracts the smallest integer from the larger and returns the result. The function should perform the subtraction, as we do manually i.e., on a digit-by-digit basis. You must perform the subtraction by extracting individual digits of the 2 integers. Assume that the two integers can have a maximum of 9 digits each. Hint: It is a common practice to use arrays for such problems!
    [Solution]

  • Write a complete C program that accepts a C program as input, removes all the valid comments fromm it and prints the input program devoid of all comments.  Scan the input program until a @  symbol is encountered in the input.
    NOTE:
    The start of a valid C comment is characterized by the presence of a / character immediately followed by a * character. The end of a comment is indicated by the presence of a * and a / character immediately following it.
    But if the above pattern comes within a string literal then it is not treated as a comment.

    Example:
    If the input to your program is:
            main() {
                    x=y; /*This is a comment*/
    /*              printf("Hello"); /* This is a comment 
                                    and more comments to follow*/
    /*              i=0;
                    printf("/*This is not a comment*//*");
            }@
    The the output must be:
            main() {
                    x=y;
                    printf("Hello"); 
                    i=0;
                    printf("/*This is not a comment*//*");
            }
                            - O -
    Congratulations! You have implemented a part of the C Preprocessor!!!!
    [Solution]

  • You are developing an employee management application for Macrohard Inc. Loharu.  The organization has 1000 employees.  Each employee's employee number, name, designation pay scale and salary has to be stored.  There are 10 different pay scales in the company; the salary depends on an employee's pay scale.  Excluding Gill Bates Chaudhary the CEO, the organizational structure has ten different designations each of which is associated with a rank.  the rank ranges from 1 to 10 with lowest rank given to the lowest and the highest rank, given to the highest designation.  
    You are required to write a complete C program that takes an employee number as input and generates the following details:
     
    Employee name, designation, salary, date of joining and the list of designations above his designation in the organizational hierarchy.
     
    If the given employee number is not found among the records, print an appropriate error message and exit.
     
    Assume that the following piece of code exists.  You need to build this code.  Also note that a variable of rank_desig structure has already been defined and sorted in increasing order of rank.  Also assume that all the values for the structure variable have already been input.

    Since you are developing the application for Macrohard, let your code be well indented with suitable comments.
    [Solution]

  • Write a complete C program to do the following task: 
      (a) accept input for 2 integer arrays of size 10, 
      (b) form a third array that will contain the elements of 
           both the arrays sorted in ascending order.  
      The new array should not have duplicate elements.
    [Solution]

  • Write a program that takes a positive number with a fractional part 
     and round it to two decimal places.  
     For example, 32.4851 would round to 32.49 and 32.4431 would round to 32.44.
     Do not use the precision specifier of the control string in printf function.
    [Solution]

  • Write a program to find the minimum number of currency notes required 
    to make up the given amount as input. 
    (Assume that 500,100,50,20,10,5,2,1 currency notes are available).
     
    If the given input is 638  
    Output:
           500*1=500
           100*1=100
           20*1=20
           10*1=10
           5*1=5
           2*1=2
           1*1=1
    [Solution]

  • A long sentence terminated by a new line character('\n') is given as input to a C program.  the sentence may contain alphabets, digits and special characters.  You are required to write a C program that counts the number of alphabets, digits, blanks, tabs and other characters and output them in a suitable manner.
     
    Example: 
    Input         : Output them (:,*,; etc.) in a suitable manner!
    Output      : 
                             Alphabets     : 30
                             Digits           : 0
                             Blanks         : 7
                             Tabs            : 0
                             Others         : 9
    [Solution]

  • Taking a two-dimensional array (N x N) of integers as input to your program, display only the elements in the upper-triangle of the matrix. The program should display the diagonal and the lower-triangle elements of the matrix as X irrespective of its values.
     
    Example:     
    Input:
                   2       3       4       5
                   6       0       2       6
                   9       8       -9      7
                   8       -9      10      0
    Output:
                   X       3       4       5
                   X       X       2       6
                   X       X       X       7
                   X       X       X       X
    [Solution]

  • Assume that you are given a 10-element array of characters.  The values in the array are limited to '+','-', and '0' through '9'.  Each character of the array represents a single digit of a number along with its sign.
    Write a program that converts the characters in the array into the correct integer value and display its square.

    Ex:  if Arr="-361" the it's corresponding square value is 130321.  
      
    By doing this, you have almost implemented the atoi function!!
    [Solution]

  • Write a function reverse(char s[]); that reverses the character string s.  
    Use it to write a program that reverses its input a line at a time.
    [Solution]

  • Write a program to remove trailing blanks and tabs from each line of input, and to delete entirely blank lines.
    [Solution]

  • You are required to write a program in C to generate a pattern
     as shown below.
     
                                    *
                           $       *
                   #      $       *
           *      #      $       *
                  #      $       *
                          $       *
                                   *
     
    To generate the above pattern, you are required to take the characters to be displayed as input from the user.  The first character would form the central symbol, the second would be the symbol on the left side of the central symbol and so on.
     
    For the above pattern the input sequence would be *$#a.
    [Solution]

  • Write a program to declare an array of structures to contain the details of 10 books.  The information of the book number, the title of the book and the name of the author(s) should be made available. If the user enters the book number, other details of the corresponding book should be displayed.
    [Solution]

  • Your program takes a sentence (terminated by '\n') and two additional words, word1 and word2 as input.  You are required to write a program in C that will replace every occurrence of word1 in the sentence by word2.  The program should display the new sentence, the number of words replaced in the sentence and the column number where word1 occurred in the original sentence.  If no occurrence of word1 is found in the sentence, a suitable message should be displayed.  
      
    You can assume that the length of word1 is equal to the length of word2. You can also assume that the input is in lowercase letters. 
     
    Ex:
    Input: 
           this is my old gold book
           old
           new
    Output:
           this is my new gnew book
           The number of replacements: 2
           Columns: 12 17
    [Solution]

  • Write a complete C program to fold long lines into lines of 40 characters.  A word must not be split across two lines. The program must scan lines from the user until he enters "STOP" as the first word of a line.  A line is defined as a set of characters terminated by a '\n'.  
     
    You can assume that there are no punctuation marks in the input.
     
    Example: 
    Input:
           this is a gift from all the would be cp2 team members
           to all the would be students
           STOP
    The output must be:
           this is a gift from all the would be cp2
            team members
           to all the would be students
           
      Note how a line has been split into two lines.
      Both the lines satisfy the condition that their length is utmost
      40 characters, and no word is split across lines.
     
      The fold command in UNIX can do this job.
    [Solution]

  • Write a complete C program that first reads, row by row, a n X n array, where n is an input.  The program should then determine wether the array just read falls into any of the following special cases:
      (a) Symetric (a[j,i]=a[i,j] for all i,j)
      (b) Upper triangular (aij=0 whenever i<j)
      (c) diagonal (aij=0 whenever i!=j)
    [Solution]

. [Home] [Ramu] [Gnet] [Software] [Apti] [Study Material] [Resume] [Photos] [Contact] [MMS] [BITS] [Interface]
.