Friday 31 August 2012

Gate CSE Complete Study Material

                       Download all Set 

Books for GATE computer science covering almost all subjects and syllabus upto 4 years of Engineering. These are some of the recommended book to refer for your study.

Wednesday 29 August 2012

Star pattern programs in C

                                                                                                                  for looping statement go here
Q no 1.Write a C program to print the following pattern:
         *
      *  *
   *  *  *
*  *  *  *

solution

#include<stdio.h>
#include<conio.h>
void main() 
      char prnt = '*';
      int i, j, nos = 4, s;
      for (i = 1; i <= 5; i++)
      {  
         for (s = nos; s >= 1; s--)
         { // Spacing factor 
              printf(" "); 
         }
         for (j = 1; j <= i; j++)
               printf("%2c", prnt); 
         printf("\n"); 
         --nos; // Controls the spacing factor 
       }
       return 0; 
}


Q. No 2 .Write a C program to print the following pattern:

*   *   *   *   *
  *   *   *   *
    *   *   *
      *   *
        *
      *   *
    *   *   *
  *   *   *   *
*   *   *   *   *
Solution :


#include<stdio.h>
#include<conio.h>
int main() 
{
 char prnt = '*';
 int i, j, s, nos = 0;
 for (i = 9; i >= 1; (i = i - 2)) {
  for (s = nos; s >= 1; s--) {
   printf("  ");
  }
  for (j = 1; j <= i; j++) {
   if ((i % 2) != 0 && (j % 2) != 0) {
    printf("%2c", prnt);
   } else {
    printf("  ");
   }
  }
  printf("\n");
  nos++;
 }
 nos = 3;
 for (i = 3; i <= 9; (i = i + 2)) {
for (s = nos; s >= 1; s--) {
   printf("  ");
  }
  for (j = 1; j <= i; j++) {

   if ((i % 2) != 0 && (j % 2) != 0) {
    printf("%2c", prnt);
   } else {
    printf("  ");
   }
  }
  nos--;
  printf("\n");
 }
 return 0;
}

Q. no 3.Write a C program to print the following pattern:



  • * * * * * * * * * * * * * * * * *
      * * * * * * *   * * * * * * *
        * * * * *       * * * * *
          * * *           * * *
            * * * * * * * * *
              * * * * * * *
                * * * * *
                  * * *
                    *
  • Solution :

    #include<stdio.h>
    #include<conio.h> 
    int main() 
    {
     char prnt = '*';
     int i, j, k, s, sp, nos = 0, nosp = -1;
     for (i = 9; i >= 3; (i = i - 2)) {
      for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
    printf("%2c", prnt);
    }
    for (sp = nosp; sp >= 1; sp--) {
       printf("  ");
      }
      for (k = 1; k <= i; k++) {
     if (i == 9 && k == 1) {
    continue;
    }
    printf("%2c", prnt);
    }
    nos++;
    nosp = nosp + 2;
    printf("\n");
    }
    nos = 4;
    for (i = 9; i >= 1; (i = i - 2)) {
      for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
       printf("%2c", prnt);
      }
      nos++;
      printf("\n");
     }
    
     return 0;
    }


  • Q no 4.Write a C program to print the following pattern:
              *
            * * *
          * * * * *
        * * * * * * *
      * * * * * * * * *
        * * * * * * *
          * * * * *
            * * *
              *
            * * *
          * * * * *
  • Solution:
    #include<stdio.h>
    #include<conio.h>
    int main()
     {
     char prnt = '*';
     int i, j, k, s, nos = 4;
     for (i = 1; i <= 5; i++) {
    for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
       printf("%2c", prnt);
      }
      for (k = 1; k <= (i - 1); k++) {
    if (i == 1) {     continue;
    }
    printf("%2c", prnt);
    }
     printf("\n");   nos--;
    }
     nos = 1;
    for (i = 4; i >= 1; i--) {
      for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
       printf("%2c", prnt);
      }
      for (k = 1; k <= (i - 1); k++) {
       printf("%2c", prnt);
      }
      nos++;
      printf("\n");
     }
     nos = 3;
     for (i = 2; i <= 5; i++) {
    if ((i % 2) != 0) {
    for (s = nos; s >= 1; s--) {
        printf("  ");
       }
       for (j = 1; j <= i; j++) {
        printf("%2c", prnt);
       }
      }
      if ((i % 2) != 0) {
       printf("\n");
       nos--;
      }
     }
     return 0;
    }
    
    
    
    
    
    
                                        ........to be continued         R.P

    Tuesday 28 August 2012

    Instruction Pipeline

    The simplest way to speed up the processor operation is to pipeline it. Pipelining is one specific form of parallelism, where the execution of several instructions can be interleaved on the same hardware. Pipelining does not reduce the time to complete an instruction, but increases the number of instructions that can be processed at once.
    Each instruction is split into a sequence of dependent steps.
    Different stages of a instruction pipeling :
    1. Fetch operands
    2. Instruction Decode
    3. ALU operation
    4. Memory access
    5. Register write                                             


                                                            pipeline stages are shown:

                                     Pipeline Performance
    The cycle time  of an instruction pipeline can be determined as:
    T=max[Ti]+d=Tm+d with 1  i k
    where:
    Tm = Maximun stage delay through stage
    k = number of stages in instruction pipeline
    d = time delay of a latch.
    In general, the time delay d is equivalent to a clock pulse and Tm >> d. Suppose that n instruction are processed with no branched.
    • The total time required Tk to execute all n instruction is:
    Tk= [k + (n-1)]
    • The speedup factor for the instruction pipeline compared to execution without the pipeline is defined as:
    SK=T1TK=nkτ[k+(n1)]τ=nkk+(n1)
    • An ideal pipeline divides a task into k independent sequential subtasks
    – Each subtask requires 1 time unit to complete
    – The task itself then requires k time units tocomplete. For n iterations of the task, the execution times will be:
    – With no pipelining: nk time units
    – With pipelining: k + (n-1) time units
    Speedup of a k-stage pipeline is thus
    S = nk / [k+(n-1)] ==> k (for large n)        


    Pipeline Limitation
    Several factors serve to limit the pipeline performance. If the six stage are not of equal duration, there will be some waiting involved at various pipeline stage. Another difficulty is the condition branch instruction or the unpredictable event is an interrupt. Other problem arise that the memory conflicts could occur.

    Pipeline Hazard :
    The ideal pipeline executes instructions during each clock cycle so that the pipeline hardware is always doing something useful.  Real pipelines with real instructions can encounter situations where an instruction would not execute correctly because of problems with other instructions already in the pipeline.  These situations are called hazards.
    1. Structural hazards - When hardware units are being used by instructions already in the 
    pipeline, these units will not be available for use by other instructions.  Any situation 
    where there is not enough hardware is a structural hazard.
    2. Data hazards - Data hazards can occur when two instructions use data from the same 
    register.  Data hazards are divided into three categories.
                 a. RAW (read after write) hazards - the current instruction must wait to read data 
                                                              until after a previous instruction writes the correct data.
                 b. WAR (write after read) hazards - the current instruction must wait to write data 
                                                              until after a previous instruction reads the old data.
                 c. WAW (write after write) hazards - the current instruction must wait to write data 
    until after a previous instruction writes to the same register.  This hazard is more 
    subtle in that neither instruction executes incorrectly.  However, subsequent 
    instructions can be incorrect if the writes occur out of order.
    Note that RAR (read after read) is not really a hazard because it makes no difference 
    which order the same operand is read.
    3. Control hazards - In the ideal pipeline, we fetch instructions one after another in order.  
    As long as location of the next instruction is known, this process can go forward.  When 
    a branch instruction is fetched, the next instruction location is not known until the 
    branch instruction finishes execution.  Thus, we may have to wait until the correct loca-
    tion of the next instruction is known before fetching more instructions.  This is a con-
    trol hazard.

    for more detail  go to Hazards in Pipelining


        
                                                                   ........to be continued                          R.P

    C Interview Questions


    1. Difference between arrays and pointers?
    2. What is the purpose of realloc( )?
    3. What is static memory allocation and dynamic memory allocation?
    4. How are pointer variables initialized?
    5. Are pointers integers?
    6. What is a pointer variable?
    7. What is a pointer value and address?
    8. What is a method?
    9. What are the advantages of the functions?
    10. What is the purpose of main( ) function?
    11. What is an argument ? differentiate between formal arguments and actual arguments?
    12. What is a function and built-in function?
    13. What is modular programming?
    14. When does the compiler not implicitly generate the address of the first element of an array?
    15. What are the characteristics of arrays in C?
    16. Differentiate between a linker and linkage?
    17. What are advantages and disadvantages of external storage class?
    18. Diffenentiate between an internal static and external static variable?
    19. What are the advantages of auto variables?
    20. What is storage class and what are storage variable ?
    21. Which expression always return true? Which always return false?
    22. Write the equivalent expression for x%8?
    23. why n++ executes faster than n+1?
    24. what is a modulus operator? What are the restrictions of a modulus operator?
    25. What is the difference between a string and an array?
    26. Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
    27. Can the sizeof operator be used to tell the size of an array passed to a function?
    28. Is using exit() the same as using return?
    29. Is it possible to execute code even after the program exits the main() function?
    30. What is a static function?
    31. Why should I prototype a function?
    32. How do you print an address?
    33. Can math operations be performed on a void pointer?
    34. How can you determine the size of an allocated portion of memory?
    35. What is a “null pointer assignment” error? What are bus errors, memory faults, and core dumps?
    36. What is the difference between NULL and NUL?
    37. What is the heap?
    38. Can the size of an array be declared at runtime?
    39. What is the stack?
    40. When should a far pointer be used?
    41. What is the difference between far and near?
    42. Is it better to use malloc() or calloc()?
    43. Why should we assign NULL to the elements (pointer) after freeing them?
    44. When would you use a pointer to a function?
    45. How do you use a pointer to a function?
    46. Can you add pointers together? Why would you?
    47. What does it mean when a pointer is used in an if statement?
    48. Is NULL always defined as 0?
    49. What is a void pointer?
    50. What is a null pointer?
    51. How many levels of pointers can you have?
    52. What is indirection?
    53. How do you print only part of a string?
    54. How can I convert a string to a number?
    55. How can I convert a number to a string?
    56. What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
    57. How can you check to see whether a symbol is defined?
    58. How do you override a defined macro?
    59. What is #line used for?
    60. What is a pragma?
    61. What are the standard predefined macros?
    62. How can type-insensitive macros be created?
    63. How many levels deep can include files be nested?
    64. Can include files be nested?
    65. Can you define which header file to include at compile time?
    66. What is the difference between #include and #include “file”?
    67. Is it better to use a macro or a function?
    68. How are portions of a program disabled in demo versions?
    69. What is the benefit of using an enum rather than a #define constant?
    70. What is the benefit of using #define to declare a constant?
    71. Can a file other than a .h file be included with #include?
    72. How can you avoid including a header more than once?
    73. What will the preprocessor do for a program?
    74. What is a macro, and how do you use it?
    75. What is Preprocessor?
    76. How can I make sure that my program is the only one accessing a file?
    77. How can I open a file so that other programs can update it at the same time?
    78. How do you determine whether to use a stream function or a low-level function?
    79. What is the difference between text and binary modes?
    80. How can you restore a redirected standard stream?
    81. How do you redirect a standard stream?
    82. How can I search for data in a linked list?
    83. How can I sort a linked list?
    84. What is hashing?
    85. What is the quickest searching method to use?
    86. What is the easiest searching method to use?
    87. How can I sort things that are too large to bring into memory?
    88. What is the quickest sorting method to use?
    89. What is the easiest sorting method to use?
    90. What is the benefit of using const for declaring constants?
    91. Can static variables be declared in a header file?
    92. What is the difference between declaring a variable and defining a variable?
    93. Is it acceptable to declare/define a variable in a C header?
    94. When should a type cast not be used?
    95. When should a type cast be used?
    96. How can you determine the maximum value that a numeric variable can hold?
    97. How reliable are floating-point comparisons?
    98. Can a variable be both const and volatile?
    99. when should the volatile modifier be used?
    100. When should the register modifier be used? Does it really help?


    Friday 24 August 2012

    NET Computer Science and Application Question paper

                                         About the N E T



    The Council of Scientific and Industrial Research (CSIR) conducts the UGC-CSIR NET for other Science subjects, namely, Life Sciences, Physical Sciences, Chemical Sciences, Mathematical Sciences and Earth Atmospheric Ocean & Planetary Sciences jointly with the UGC. The tests are conducted twice in a year generally in the months of June and December. For candidates who desire to pursue research, the Junior Research Fellowship (JRF) is available for five years subject to fulfillment of certain conditions. UGC has allocated a number of fellowships to the universities for the candidates who qualify the test for JRF. The JRFs are awarded to the meritorious candidates from among the candidates qualifiying for eligibility for lectureship in the NET. JRFs are available only to the candidates who opt for it in their application forms.
           


    NET Computer Science and Application  Question paper               

                                              Net 2012(June)

                                              NET 2011 (Dec)

                                              NET 2011(June)

                                              NET 2010(Dec)

                                              Net 2010(June)

                                              Net 2009(Dec)

                                              Net 2009(June)



                                                                   ...........Best of luck..........  
                                                                                                                                                   R.P