Tuesday, 19 February 2013

Assignment – 8

                         Assignment – 8

Question-1: State whether the following statements are True or false.
(a) When initializing a string variable during its declaration, we must include the null character as part of the string constant, like ‘GOOD\0’.
Answer: False.
(b) The gets function automatically appends the null character at the end of  the string read from the keyboard.
Answer: True.
(c) When reading a string with scanf, it automatically inserts the terminating null character.
Answer: True.
(d) String variables cannot be used with the assignment operator.
Answer: True.    
(e) We cannot perform arithmetic operations on character variables.
Answer: False.
(f) We can assign a character constant or a character variable to an int type variable.
Answer: False.
(g) The function scanf cannot be used in any way to read a line of text with the white spaces.
Answer: False.
(h) The ASCII character set consists of 128 distinct characters.
Answer: True.
(i)  In the ASCII collating sequence, the uppercase letters precede lowercase letters.
Answer: True.
(j) In C, it is illegal to mix character data with numeric data in arithmetic operations.
Answer: False.
(k) The function getchar skips white-space during input.
Answer: False.
(l) In C, strings cannot be initialized at run time.
Answer: False.
(m) The input function gets has one string parameter.
Answer: True.
(n) The function call strcpy (s2, s1); copies string s2 into string s1.
Answer: False.
(o) The function call strcmp ( ‘abc’ , ‘ABC’ ); returns a positive number.
Answer: True.



Question-2: Fill in the blanks in the following statements.
(a) We can use the conversion specification ….. in scanf to read a line of text.
Answer: code.
(b) We can initialize a string using the string manipulation function ……...
Answer: strcpy()
(c) The function strncat has (three) parameters.
Answer: three
(d) To use the function atoi in a program, we must include the header file ……. .
Answer: <std.lib.h>
(e) The function ……. does not require any conversion specification to read a string from the keyboard.

Answer: gets.
(f) The function ……… is used to determine the length of a string.
Answer: strlen.

(g) The ……….string manipulation function determines if a character is contained in a string.
Answer: strstr.
(h) The function ………..is used to sort the strings in alphabetical order.
Answer: strcmp().
(i) The function call strcat (s2,s1); appends …s1… to …s2….
Answer: s1, s2.
(j) The printf may be replaced by ……… function for printing trings.
Answer: Puts().



Question-3: Assuming the variable string  contain  the  value “ The sky is the limit. ”, determine 
  what output of the following segments will be.
(a) printf (“%s”,string);
  Output:  The sky is the limit
(b) printf(“%25.10s”,string);
 Output:    The sky is
(c) printf(“%s”,string[0]);
output:  abnormal termination of program due to %s instead of %c
(d) for(i=0;string[i]!= “.”,i++)
      printf(“%c”,string[i]);
output: error due to "." instead of '.'
(e) for(i=0;string[i]!= ‘\0’;i++)
         printf(“%d\n”,string[i]);

output:  ascii value of each character (84 104 101 32 115 107 121 32 105 115 32 108 105 109 105 116 46)

(f) for(i=0;i<=strlen[string]; ;)
 {
          string[i++]=i;
          printf(“%s\n”,string[i]);
       }
output:   error due to wrong declaration of for statement

(g) printf(“%c\n”,string[10]+5);

output:  %

(h) printf(“%c\n”,string[10]+5’);

output: error
Question - 4: Which of the following statements will correctly store  the  concatenation  of  strings s1 and s2 in string s3?
 (a) s3=strcat (s1,s2);
    Answer: error.
(b) strcat(s1,s2,s3);
   Answer: error.
(c) strcat(s3,s2,s1);
  Answer: error.
(d) strcpy(s3,strcat(s1,s2));
  Answer: correct.
(e) strcmp(s3,strcat(s1,s2));
  Answer: false.
(f) strcpy(strcat(s1,s2),s3);
  Answer: false.

Question -5: What will be the output of the following statements?
    printf(“%d”,strcmp(“push”, “pull”));
  output:        7
Question - 6: Assume that s1, s2 and s3 are declared as follows:
char s1[10]= “he”, s2[20]= “she”, s3[30], s4[30];
 What will be the output of following statements executed in sequence?
printf(“%s”, strcpy(s3, s1));
printf(“%s”,strcat(strcat(strcpy(s4,s1),“or”),s2));
printf(“%d%d”,strlen(s2)+strlen(s3),strlen(s4));
  output:
                    he
                     heorshe
                     5  7
Question 7-: Find errors if any, in the following code segments;  
 (a) char str[10]
     strncpy(str, “GOD”, 3);
     printf(“%s”,str);
     Answer: error.
   Correct answer: char str[10];
                                 strcpy(str, “GOD”, 3);
                                  printf(“%s”,str);

    (b) char str[10];
          strcpy(str, “Balagurusamy”);
        Answer: no error.
                  

 (c) if strstr(“balagurusamy”, “guru”)==0);
          printf(“Substring is found”);
   
 Answer: no error.sss


(d) char s1[5], s2[10],
         gets(s1, s2);
  Answer: error.
  Correct answer: char s1[5], s2[10];
                                         gets(s1);
                                            gets(s2);




Question -8: What will be the output of the following segment ?
                     char s1[]= “Kolkata”;
                     char s2[]=  “Pune”;
                     strcpy(s1, s2);
                     printf(“%s”,s1);
   Output:
                    Pune

Question -9: What will be the output of the following segments ?
                     char s1[]= “NEW DELHI”
                     char s2[]= “BANGALORE”
                     strncpy(s1, s2, 3);
                     printf(“%s”, s1);
 Output:
                     BAN DELHI
        Question - 10: What will be the output of the following code?
                     char s1[]= “Jabalpur”
                     char s2[]= “Jaipur”
                     printf(strncmp(s1, s2, 2))
     Output:
                     0

Question -11: What will be the output of the following code?
              char s1[]= “ANIL KUMAR GUPTA
              char s2[]= “KUMAR”
               printf(strstr(s1,s2));
    Output:
                     KUMAR GUPTA


Question - 12: Compare the working of the following functions:
(a)  stcpy and strncpy;
 Answer: The function strcpy copies one string to another string but    the function strncpy    copies  only  the  left-most  n  characters of the  source  string  to  the target string variable. 
(B) strcat and strncat
 Answer: The function   strcat  joins   two   strings   together   but  the  function  strncat
    concanate left-most n characters of target string to source string.

  (C) strcmp and strncmp; and
  Answer: The strcmp function compares two  strings  identified  by  the  arguments  but
 strncmp function compares the left-most n characters of two string .

Tuesday, 5 February 2013

L.D.P Assignment L-7



Q.1 state whether the following statement are true or false.
     (a) The type of all elements in an array must be the same.
         Ans:-true
      (b) When an array is declared, C automatically initializes its elements to zero.
         Ans:-false
      (c) An expression that evaluates to an integral value may be used as a subscript.
         Ans:-true
      (d) Accessing an array outside its range is a compile time error.
        Ans:-true
      (e) A char type variable cannot be used as a subscript in an array.
       Ans:-false
      (f) An unsigned long int type can be used as a subscript in an array.
        Ans:-true
      (g) In C, by default, the first subscript is zero.
         Ans:-true
  (h) When initializing a multidimensional array, not specifying  all its dimensions is an error.
        Ans:-false
(i)When we use  expressions as a subscript, its result should be always greater than zero.
       Ans:-false
(j) In C, we can use a maximum of 4 dimensions  for an array.
      Ans:-false
(k)In declaring an array, the array size can be a constant or variable or an expression.
     Ans:-true
(l)The declaration int x[2]={1,2,3}; is illegal.
      Ans:-true

Q.2 Fill in the blanks in the following statements.
(a)The variable used as a subscript in an array is popularly known as  -----------  variable.
    Ans:-index
(b)An array can be initialized either at compile time or at --------.
   Ans:-run time
(c) An array created using malloc function at run time is referred to as ----------array.
     Ans:-dynamic
(d) An array that uses more than two subscript is referred to as      
        ---------array.
         Ans:-multidimensional
  (e) -------- is the process of arranging the elements of an array in order.
     Ans:-sorting   

Q.3 Identify errors, if any, in each of the following array declaration statements, assuming that ROW and COLUMN are declared symbolic constants:
(a) Int score (100);
   error: declaration syntax error  
   Ans:-[100];      
(b) Float values [10, 15];
    Ans:-float value[10][15];
(c) float average[row],[column];
    Ans:-float average[row][column];
(d) char name[15];
   Ans:-true
(e)  Int sum [];
   Ans:-value is not defined
(f)  Double salary [i + row]
     Ans:-semicolon
         Double salary [i+row];
(g)  Long int number [row]
    Ans:-long int number [row];
(h)  Int array x [column];
    Ans:-int x [column];

Q.4 Identify errors, if any, in each of the following initialization statements.
(a) Int number [] = {0,0,0,0,0};
   Ans:-true
(b) float item[3][2]={0,1,2,3,4,5};
    Ans:-true
(c) Char word [] = {‘A’,’R’,’R’,’A’,’Y’};
     Ans:-true
(d) int m[2,4]={(0,0,0,0)(1,1,1,1)};
      Ans:-int m[2][4]={(0,0,0,0)(1,1,1,1)};
(e) Float result [10] =0;
    Ans:-true


Q.5 Assume that the array A and B are declared as follows:
Int A [5] [4];
Float B [4];
Find the error (if any) in the following program segments.

(a)             for (i=1; i<=5; i++)
for (j=1; j<=4;j++)
A[i][j] = 0;
            Ans:-logic error
(b)             for (i=1; i<=4; i++)
                 Scanf (“%f”,B[i]);
            Ans:-not generate error of compile time but get three value
(c)               for (i=0; i<=4; i++)
             B[i]=B[i]+i;
       Ans:-compile time  no error but logical error
(d)            for (i=4; i<=0; i--)
for (j=0;j<4;j++)
A[i] [j]=B[j]+1.0;
           Ans:- compile time not generate error but logical value


Q.6 We want to declare a two-dimensional integer type array called matrix for 3 rows and 5 columns. Which of the following declarations are correct?
  
(a) Int maxtrix [3] , [5];
  Ans:-correct
(b) Int matrix [5] [3];
 Ans:- wrong  
(c) Int matrix [2+1] [2+3];
  Ans:-correct
(d) Int matrix [3,5];
   Ans:-wrong
(e) Int matrix [3] [5];
  Ans:-correct

Q.7 which of the following initialization statements are correct?
 (a) char str1 [4] = “GOOD”;
    Ans:-correct
 (b) char str2 [ ] = “C”;
    Ans:-wrong
 (c) char str3 [5] =”Moon”;
    Ans:-correct
 (d) char str4 [ ] = {‘S’,’U’,’N’};
     Ans:-correct
 (e)char str5 [10] = “SUN”;

Ans:-correct


Q.8 what is the error in the following program?

main( )
     {
         int x;
float y [ ] ;
…….
}
 *Error:-size of ‘y’ is unknown or zero


Q.9 what is the output of the following program?
  main()
    {
        int m [] = {1,2,3,4,5};
        int x, y=0;
        for(x=0;x<5;x++)
           y = y+m[x];
      printf(“%d”,y);
}
OUTPUT:- 15
           
Q.10 what is the output of the following program?
   main()
     {
        chart string [] =”HELLO WORLD”;
        int m;
        for(m=0;string [m] !=’\0’;m++)
          if((m%2) = = 0)
        printf(“%c”,string[m]);
}                    
OUTPUT:-HLOWRD

Friday, 23 November 2012

COA Most IMP QUE

K map
De-morgan
xs-3
hamming code
checksum
CPU with fig
BUS( data, address, control)
adder(half, full, binary)
Gates
Number system
conversion
parity bit(odd, even)

NOTE : BOOK KHOLEE NEY VACH JAO KHALI AANA PAR BHAROSO NA KAR TA..............

AA IMP CHE ANEY EK DAM PAKU KAREE KAD JOO 

LDP internal exam paper