6102 C Language Mca MCQ

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 93

MCA-Model Question Paper (C Programming Language)

PROGRAM MASTER OF COMPUTER APPLICATION (MCA)


SEMESTER SEMESTER 1
COURSE CODE & NAME DCA6102 – PROGRAMMING IN C

1.  Which of the following language is the predecessor to C Programming Language?


a) A
b) B
c) BCPL
d) C++
Ans: c

2. BPCL stands for

a) Basic Combined Programming Language

b) Basic Combo Programming Language

c) Basic Combo Program Language

d) None of these.

Ans: a

3. C programming language was developed by


a) Dennis Ritchie
b) Ken Thompson
c) Bill Gates
d) Peter Norton

Ans: a

4. C was developed in the year ___


a) 1970
b) 1972
c) 1976
d) 1980

Ans: b

5. C is a ___ language
a) High Level

pg. 1
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
b) Low Level
c) Middle Level
d) Machine Level

Ans: c

6. C language is available for which of the following Operating Systems?


a) DOS
b) Windows
c) Unix
d) All of these

Ans: d

7. Which of the following symbol is used to denote a pre-processor statement?


a) !
b) #
c) ~
d) ;

Ans: b

8. Which of the following are tokens in C?


a) Keywords
b) Variables
c) Constants
d) All of the above

Ans: d

9. Which symbol is used as a statement terminator in C?


a) !
b) #
c) ~
d) ;

Ans: d

 10. Which escape character can be used to begin a new line in C?


a) \a
b) \b
c) \m
d) \n

pg. 2
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
Ans: d

11. Which escape character can be used to horizontal tab in C?


a) \t
b) \b
c) \m
d) \n

Ans: a
12. Character constants should be enclosed between ___
a) Single quotes
b) Double quotes
c) Both a and b
d) None of these

Ans: a

13. String constants should be enclosed between ___


a) Single quotes
b) Double quotes
c) Both a and b
d) None of these

Ans: b

14.The __________ consists of an equal sign and an expression, which is usually a single
constant.
a) Initializer
b)Variable
c) Constant
d) None of these
Ans: a

15. A single declaration statement can contain variables of different types. (True/False)
Ans: False

16. In C, variable names are case sensitive. (True/False)


Ans: True

17. A variable name in C consists of letters, numbers and _________.

Ans: Underscore

 18. What will be the maximum size of a double variable?


a) 1 byte

pg. 3
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
b) 4 bytes
c) 8 bytes
d) 16 bytes
Ans: c

 19. What will be the maximum size of a float variable?


a) 1 byte
b) 2 bytes
c) 4 bytes
d) 8 bytes
Ans: c

20. The size of a String variable is


a) 1 byte
b) 8 bytes
c) 16 bytes
d) None of these
Ans: d

21.Using C language programmers can write their own library functions. (True/False)
Ans: True

22. C is a ________ level programming language.


Ans: Middle

23. The documentation section contains a set of __________ lines.


Ans: Comment

24. Every C program must have one main() function. (True/False)

Ans:True

25.The information that needs to be passed in when a function is called is______.


Ans: Argument

26. The main() function doesn’t return any value. (True/False)

Ans: False

27. The operator && is an example for ___ operator.


a) Assignment
b) Increment
c) Logical
d) Rational
Ans: c

pg. 4
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
28. The operator & is used for
a) Bitwise AND
b) Bitwise OR
c) Logical AND
d) Logical OR
Ans: a

29. The equality operator is represented by


a) :=
b) .EQ.
c) =
d) ==
Ans: d

30. The bitwise AND operator is used for


a) Masking
b) Comparison
c) Division
d) Shifting bits
Ans: a

31. An octal integer constant consists of any combination of digits from the set _________
through _________.
Ans: (0,7)

32. A sequence of digits preceded by 0x or 0X is considered as _____________ integer.


Ans: Hexa Decimal

33. A string constant is a sequence of __________ enclosed within double quotes.


Ans: Character

34. The size of the Integers in C language is same in all the machines. (True/False)
Ans: True

35. A ________ is a place where we can store values.


Ans: Variable

36. Size of int is _________ bits.


a) 8
b) 16
c) 32
d) 64
Ans: b

37. Which of the following tells the compiler the name and type of a variable you'll be using in
your program?

pg. 5
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
(a) declaration
(b) variables
(c) integers
(d) assignments

Ans: a

38. Which operator has the lowest priority?


a) ++
b) %
c) +
d) ||
Ans: d

39. Which operator has the highest priority?


a) ++
b) %
c) +
d) ||
Ans: a

40. Which of the following is a ternary operator?


a) ?:
b) *
c) sizeof
d) ^
Ans: a

41. What will be the output of the expression 11 ^ 5?


a) 5
b) 6
c) 11
d) None of these
Ans: d

42. The type cast operator is


a) (type)
b) cast()
c) (;;)
d) // ” ”
Ans: a

43. Explicit type conversion is known as


a) Casting
b) Conversion
c) Disjunction

pg. 6
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
d) Separation
Ans: a

44. The operator + in a+=4 means


a) a=a+4
b) a+4=a
c) a=4
d) a=4+4
Ans: a

45.What is the value of the arithmetic expression: 14 % 3 + 7 % 2


(a) 1
(b) 2
(c) 3
(d) 4
Ans: c
46. __________ operator can be only applied to integers.

a) Additional

b) Subtraction

c) Multiplication

d) Modulus

Ans: d

47. The logical operators ___________ and __________ are used when we want to test more
than one condition and make decisions.
Ans: &&, ||

48. State whether the following statement is correct or not. (Correct/Incorrect)


if(a<4<c)
b=c;

Ans: Incorrect

49. ____________________ are built-in functions that carry out various commonly used
operations or calculations
Ans: Library Function

50. Fill in the blanks as indicated by alphabets. The value of (a) floor(5.8),
(b) floor(-5.8), (c) ceil(5.8) and (d) ceil(-5.8) are ______ (a) _____,
____ (b) ______, ____ (c) _______ and _____ (d) ______ respectively.

Ans: (a) 5, (b) -6 ,(c) 6, (d) -5

pg. 7
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
51. Header files in C contain
a) Compiler commands
b) Library functions
c) Header information of C programs
d) Operators for files
Ans: b

52. Which pair of functions below are used for single character I/O.
a) Getchar() and putchar()
b) Scanf() and printf()
c) Input() and output()
d) None of these
Ans: a

53. The printf() function retunes which value when an error occurs?
a) Positive value
b) Zero
c) Negative value
d) None of these
Ans: c

54. Identify the wrong statement


a) putchar(65)
b) putchar(‘x’)
c) putchar(“x”)
d) putchar(‘\n’)
Ans: c

55. The output of the following program segment is ____________.


int a=97;
printf(“%c”, a);

a) C
b) A
c) a
d) none of these
Ans: c
56. gets() is a formatted input statement. (True/False)
Ans: False

57. The argument for a gets() and puts() functions are ____________variables.
a) char

pg. 8
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
b) String
c) Integer
d) Float
Ans: b

58. Using gets() function, you cannot include whitespace characters in the input string.
(True/False).
Ans: False

59. Which of the following is charecter oriented console I/O function?


a) getchar() and putchar()
b) gets() and puts()
c) scanf() and printf()
d) fgets() and fputs()
Ans: a

60. An Ampersand before the name of a variable denotes


a) Actual Value
b) Variable Name
c) Address
d) Data Type
Ans: c

61. Symbolic constants can be defined using


a) # define
b) const
c) symbols
d) None of these
Ans: b

62. Null character is represented by


a) \n
b) \0
c) \o
d) \e
Ans: b

63. When the accuracy provided by a float number is not sufficient, the type long float can be
used to define the number. (True/False)
Ans: False

64. A double data type uses __________ bits.


a) 8
b) 16
c) 32
d) 64

pg. 9
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
Ans: d

65. If the operands are of different data types, the ‘lower’ type is automatically converted to the
‘higher’ type before the operation proceeds. (True/False)
Ans: True

66. During the final assignment ________ to int causes dropping of the excess higher order
bits.
a) int
b) short int
c) long int
d) all of these
Ans: c

67. The value of the expression 22.0/10 is ________.

Ans: 2.2

68. Casting can be used to round-off a given value. (True/False)


Ans: True

69. The value of A in the expression A=(int)11.35/(int)14.5 is ___________.


a) 0
b) 1
c) 2
d) 4
Ans: a

70. If the value of X is 35.2, then the value of A in the expression: A = (int)(X+0.5); is
____________.
a) 35
b) 35.7
c) 36
d) None of these
Ans: a

71. What is the format character to display the value of a char variable?
a) %d
b) %f
c) %c
d) %s
Ans: c

72. The output of the following C statement: printf(“%c”, 70); is ___________.


Ans: False

pg. 10
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
73. All keywords must be written in ____________.
a) Uppercase
b) Lowercase
c) both (a) and (b)
d) none of these
Ans: b

74. default is not a valid keyword in C. (True/False)

Ans: False

75. getchar() function is an output function.(True/False)


Ans: False

76. In order to stop reading the input character, you can use a value called___________.
Ans: EOF

77. The __________ string consists of control characters, whitespace characters, and non-
whitespace characters.
Ans: Control

78. The control string used to read a hexadecimal character is _______________.


a) %u
b) %i
c) %x
d) %h
Ans: c
79. scanf() functions needs address of the data item to be read as the argument. (True/False)
Ans: True

80. The output of the following statement is ________________.


printf("%d %o %x\n", 64, 10, 75);
Ans: 64, 12, 4B

81. To print an int argument in octal, you can use ____________ format string.
a) %u
b) %i
c) %x
d) %o
Ans: d

82. Which header file is essential for using strcmp() function?


a) string.h
b) strings.h
c) text.h
d) strcmp.h
Ans: a
pg. 11
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
83. malloc() function used in dynamic allocation is available in which header file?
a) stdio.h
b) stdlib.h
c) conio.h
d) mem.h
Ans: b

84. Which among the following is an unconditional control structure


a) do-while
b) if-else
c) goto
d) for
Ans: c

85. The function main() is optional in a C program. (True/False)


Ans: False

86. If the function is defined elsewhere (not in the same program where it is called), the function
prototype must be preceded by the keyword
Ans: Extern
_____________.
87. The arguments that appear in function definition are called_____________ arguments
whereas the arguments that appear when the function is called are the ___________
arguments.
Ans: Formal,actual

88. A stopping condition must be there in a recursive definition. (True/False)


Ans: True

89. Continue statement is used


a) to go to the next iteration in a loop
b) come out of a loop
c) exit and return to the main function
d) restarts iterations from the beginning of the loop
Ans: a

90. Which operator in C is called a ternary operator


a) if..then
b) ++
c) ?:
d) ()
Ans: c

91. Which of the following header file is required for strcpy() function?
a) string.h

pg. 12
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
b) strings.h
c) files.h
d) strcsspy()
Ans: a

92. In the C language ‘a’ represents


a) a digit
b) an integer
c) a character
d) a word
Ans: c

93. Closing a file simply involves calling fclose with the ___________ as its argument.
Ans: File pointer

94. If you forget to close a file, it will be closed automatically when the program exits.
(True/False)
Ans: True

95. The companion function to putchar is putc, and the file pointer argument comes first.
(True/False)
Ans: false

96. Besides the file pointers which we explicitly open by calling fopen, there are also
____________ predefined streams.
Ans: Three

97. getchar() is the same as getc(stdin).(True/False)


Ans: True
98. __________ clears the error and EOF indicators for the stream.
Ans: clearerr

99. The number of relational operators in the C language is


a) Four
b) Six
c) Three
d) One
Ans: b

100. The library function used to copy one string to another is_________________.
Ans: strcpy

101. The library function atoi can be used for any string. (True/False)
Ans: False

pg. 13
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
102. Dereference operator is also known as ___________________.
Ans: indirection operator.

103. Pointer is a variable containing address of another variable. (True/False)


Ans: True

104. State whether the following statements are correct: (Correct/Incorrect)


int a, b;
b=&a;
Ans: Incorrect

105. In C, a Union is
a) memory location
b) memory store
c) memory screen
d) None of these
Ans: b

106. When the main function is called, it is called with the arguments
a) argc
b) argv
c) None of these
d) both a & b
Ans: d

107. Pointers are of


a) integer data type
b) character data type
c) unsigned integer data types
d) None of these
Ans: d

108. Maximum number of elements in the array declaration int a[5][8] is


a) 28
b) 32
c) 35
d) 40
Ans: d

109. The return data type, function name and the list of formal parameters enclosed in brackets
are separated by _______________.
Ans: Comma

110. Function prototype is also called ________.


Ans: Function Declaration

pg. 14
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
111. The function prototypes are optional. (True/False)
Ans: False

112. The function prototypes of the library functions is in the corresponding__________ files.
Ans: Header

113. The function prototype for the function fun() called in main() below is________________ .
Ans: double fun(double, double);

114. ______________ is a process by which a function calls itself repeatedly, until some
specified condition is satisfied
Ans: Recursion

115. Array subscripts in C always start at


a) -1
b) 1
c) 0
d) Value provided by the user
Ans: c

116. A Structure
a) can be read as a single entity
b) cannot be read as a single entity
c) can be displayed as a single entity
d) has member variables that cannot be read individually
Ans: b

117. Which is the correct way to declare a pointer?


a) int_ptr;
b) int *ptr;
c) *int ptr;
d) None of these.
Ans: b

118. The process of translating a source program into machine language is a function
of:
a) Compiler
b) Translator
c) Assembler
d) None of these.
Ans: a

119. _________________ let you work with the individual bits of a variable; one common use is
to treat an integer as a set of single-bit flags.

pg. 15
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
a) Bitwise operator
b) Logical Operator
c) Relational operator
d) None of these
Ans: a

120. Fill in the blanks as indicated by alphabets. If flag1=5, flag2=8, then


(a) flag1&flag2, (b) flag1|flag2, (c) ~flag1 and (d) flag1^flag2 is
computed to be ______ (a) _____, ____ (b) _______, ____ (c)_______
and _____ (d) ______ respectively.

Ans: (a) 0, (b) 13, (c) 10, (d) 13

121. Increment and Decrement operators are binary operators. (True/False)


Ans: False

122. The prefix form to increment i is _______ whereas the postfix form to increments i is
________.
Ans: ++i, i++

123. What is used as a terminator in C?


a) ?
b) ;
c) :
d) _
Ans: b

124. What is the answer of: 7%3


a) 2.5
b) 1
c) 2
d) 3
Ans: b

125. The _______ chars have values from -128 to 127.


a) signed
b) unsigned
c) long
d) none
Ans: a

126. What is the control character for “a single character”.


a) %c
b) %d
c) %i

pg. 16
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
d) %p
Ans: a

127. The goto requires a _________ in order to identify the place where the
branch is to be made.
Ans: Label

128. goto is an unconditional branching statement. (True/False)


Ans: True

129. The series of statements enclosed by braces after the expression in simple if statement is
itself a simple expression statement. (True/False)
Ans: False

130. In the cascaded if/else/if/else/... chain, each else clause is another _______ statement.
Ans: If

131. The conditional operator does not produce a lvalue. (True/False)


Ans: True

132. The condition of a switch statement is a _______.


Ans: Value

133. Switch statement is an unconditional branching statement. (True/False)


Ans: False

134. A ______________ loop starts out like an if statement .


Ans While:

135. while is an entry-controlled loop. (True/False)


Ans: True

136. What is the control character for “a decimal integer”.


a) %c
b) %d
c) %i
d) %p
Ans: b

137. What is the control character for “a floating point number”.


a) %c
b) %d
c) %i
d) %f
Ans: d

pg. 17
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
138. C supports the ______ statement to branch unconditionally from one point to another in
the program.
a) continue
b) goto
c) break
d) for
Ans: b

139. The _______ is used to break out of the case statements.


a) continue
b) break
c) default
d) case
Ans: b

140. On using the ________, the body of the loop is always executed at least once irrespective
of the expression.

Ans: Do….while

141. do…while is an entry-controlled loop. (True/False)


Ans: False

142. for loop is an exit-controlled loop. (True/False)


Ans:False

143. The “control variable'' of a for loop does not have to be an integer. (True/False)
Ans: True

145. The output of the following program is _______________.

#include<stdio.h>
main()
{
int n=5;
int fun(int n);
printf(“%d\n”, fun(n));
}
int fun(int n)
{
if(n==0)
return 0;
else
return (n+fun(n-1));

pg. 18
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
}

Ans: 15

146. Which one of the following is a loop construct that will always be executed once?

a. for
b. while
c. switch
d. do while

Ans d

147. In the C language, the constant is defined _______.

a. Before main
b. After main
c. Anywhere, but starting on a new line.
d. None of the these.

Ans c

148. What is the result after execution of the following code if a is 10, b is 5, and c is 10?

If ((a > b) && (a <= c))  
        a = a + 1;  
else  
    c = c+1;  

a. a = 10, c = 10
b. a = 11, c = 10
c. a = 10, c = 11
d. a = 11, c = 11

Ans: b

149. How many characters can a string hold when declared as follows?

char name[20]:  
a. 18

pg. 19
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
b. 19
c. 20
d. None of the these

Ans: c

150. What is the maximum number of characters that can be held in the string variable char
address line [40]?

a. 38
b. 39
c. 40
d. 41

Ans: b

151. The scope of an automatic variable is in ____________ in which it is declared.


Ans: The function in which it is declared.

152. Does an automatic variable retain its value once control is transferred out of its defining
function? (Yes/No)
Ans: No

153. The key word auto is must in the declaration of automatic variables. (True/False)
Ans: False

154. The variables declared in the main() function are the global variables.(True/False)
Ans: False

155. The global variables are more secured than the automatic variables in a program.
(True/False)
Ans: False

156. The scope of static variables and automatic variables is the same. (True/False)
Ans: True

157. ____________ variables retain their values throughout the life of the program. As a result,
if a function is exited and then reentered later, the static variables defined within that function
will retain their previous values.
Ans: Static

158. By default, a static variable is initialized to _______.


Ans: Zero

pg. 20
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
159. What will the result of len variable after execution of the following statements?

int len;  
char str1[] = {"39 march road"};  
len = strlen(str1);  
a. 11
b. 12
c. 13
d. 14

Ans c

160. Which is valid expression in c language?

a. int my_num = 100,000;


b. int my_num = 100000;
c. int my num = 1000;
d. int my num == 10000;

Ans b

161. What does this statement mean?

1. x - = y + 1;  

a. x = x - y + 1
b. x = -x - y - 1
c. x = x + y - 1
d. x = x - y - 1

Ans d

162. Study the following statement

main()  
{     
   char *s = "Hello,"  
   "World!";  
   printf("%s", s);  

pg. 21
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
}  

What will be the output?

a. Hello, World!
b. Hello,
World!
c. Hello
d. Compile error

Ans B

163. By modularizing the problem into different sub problems. Each sub problem can be
implemented as a __________.
Ans: Function

164. The main purpose of function is to save typing time. (True/False)

Ans: False

165. The visibility of a variable determines how much of the rest of the program can access that
variable. (True/False)
Ans:True

166. __________ class refers to the persistence of a variable and its scope within the program,
that is, the portion of the program over which the variable is recognized.
Ans: Storage

167. Visibility provides security for your data used in a program. (True/False)

Ans:True

168. The main purpose of using external variables is to access the same variable in different
______________ files.
Ans: Source

169. Compiler doesn’t allocate memory for an external variable where it is accessed.
(True/False)
Ans:True

170. Global variables and external variables have the same scope. (True/False)
Ans: False

171. In C, an array subscript starts from __________


Ans: 0

pg. 22
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
172. An array name is a pointer. (True/False)
Ans: True

173. Will there be a compilation error for the following program


segment?(Yes/No)
int a[5] = {1, 2, 3, 4, 5};
int b[5] = {5, 4, 3, 2, 1};
int c[5][5];

c=a+b;

Ans:Yes

174. Suppose that cPtr is a character pointer, and its current content is 300. What will be the
new value in cPtr after the following assignment?

cPtr = cPtr + 5;  

a. 305
b. 310
c. 320
d. 340

Ans a

175. Array is a _________ data structure.

a. Non-linear
b. Primary
c. Linear
d. Data type

Ans c

176. Which of the following statement is correct about the array?

a. In the array, users can only allocate the memory at the run time.
b. In the array, users can only allocate the memory at the compile time.
c. The array is a primitive and non-linear data structure that only stores a similar data type.

pg. 23
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
d. All of the these

Ans: b

177. In a two-dimensional matrix, the first subscript in the declaration specifies number of
__________.
Ans: Rows

188. A two-dimensional array is considered as an array of one-dimensional arrays. (True/False)


Ans:True

199. Will there be a compilation error for the following program? (Yes/No).
char str1[10];
str1=”Hello, world”;
printf(“%s”, str1);

Ans: Compilation Error

200. The contents-of operator * does not merely fetch values through pointers; it can also set
values through pointers. (True/False)
Ans: True

201. You can perform any type of arithmetic operation on pointers. (True or False)
Ans: False

202. For an int array a[10], If you declare a pointer variable ip then you can set it to point to the
beginning of an array by assigning: int *ip =____________ .
Ans: &a[0];

203. One common use of pointer comparisons is when copying arrays using pointers.
(True/False)
Ans: True

204. To increment what p points to, you can use the expression __________.
Ans: (*p)++.)

205. Which of the following statement is correct about the C language?

a. The C language is a binary language with some extra features.


b. The C language is a high-level language with some low features.
c. The C language is a mid-level language with some high features.
d. The C language is a low-level language.

pg. 24
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
Ans: c

206. Study the following statement : printf ("%d", 9/5);  

What will be the output of this statement?

a. 1.8
b. 1.0
c. 2.0
d. None of the these

Ans: d

207. A global variable is declared __________.

a. Outside of the function


b. Inside of the function
c. With the function
d. Anywhere in the program

Ans: a

208. Who defines the user-defined function?

a. Compiler
b. Computer
c. Compiler library
d. Users

Ans: d

209. Which of the following operations cannot be performed in file handling?

a. Open the file


b. Read the file
c. To write a file

pg. 25
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
d. None of the these

Ans: d

210. Which of the following function is used to write the integer in a file?

a. getw()
b. putw()
c. int value
d. f_int()

Ans: b

211. A ______ is a special pointer value that is known not to point anywhere.
Ans: Null pointer

212. A function that returns ____________ values can return a null pointer when it is unable to
perform its task.
Ans: Pointer

213. In general, C does not initialize pointers to null for you, and it never tests pointers to see if
they are null before using them. (True/False)
Ans: True

214. An array of characters is called as _________.


Ans: String

215. You can represent an array of strings using pointers by using an array of __________ to
character.
Ans: Pointers

216. A string must always be terminated with a __________ character.

Ans: Null

217. Which of the following statement is correct about the ftell() function?

a. It returns the current position.


b. It sets the file pointer to the given position.
c. It sets the file pointer at the beginning of the file.
d. It reads a character from the file.

pg. 26
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
Ans: a

218. In which of the following modes, the user can read and write the file?

a. r
b. w
c. r+
d. b+

Ans: c

219. The enum keyword is used to assign names to the ________ constants.

a. Integer
b. String
c. Character
d. All of the these

Ans: a

220. Which of the following operator's precedence order is correct (from highest to lowest)?

a. %, *, /, +, -
b. %, +, /, *, -
c. +, -, %, *, /
d. %, +, -, *, /

Ans: a

221. We can define a two dimensional array as a pointer to a group of contiguous _________
dimensional arrays.
Ans: One

222. A two-dimensional array can also be expressed in terms of an_________ of pointers rather
than as a pointer to a group of contiguous arrays.
Ans: Array

pg. 27
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
223. A ___________ is a convenient tool for handling a group of logically related data items.
Ans: structure

224. We can declare structure variables using the tag name anywhere in the program.
(True/False)
Ans: True

225. ____________ is a method for packing data of different types.


Ans: Array

226. If person1 and person2 are variables of the same type structure then the expression
person1>person2 is valid. (True/False)
Ans: False

227. _______________ is a method for packing data of different types.


Ans: Structure

228. The link between a member and a variable is established using the member operator
_________.
Ans: Dot(.)

229. Which of the following is not an arithmetic operation?

a. x * = 65;
b. x / = 42;
c. x % = 2;
d. x ! = 56;

Ans: d

230. Which of the following operator is represented a relational operation?

a. ==
b. ++
c. ||
d. &&

Ans: a

231. Which of the following keyword is used for union in c language?

pg. 28
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
a. un
b. unt
c. ion
d. union

Ans: d

232. Which of the following variable name is correct in c language?

a. For
b. for
c. Basic salary
d. hello.

Ans: a

233. We cannot write a function that returns the structure. (True/False)


Ans: True

234. We can modify a member of the structure by passing the structure as a_____________.
Ans: argument

235. We can use structures to describe the format of a number of related variables.
(True/False)
Ans: True

236. You can declare an array of structures where each element is defined to be of the type
_______.
Ans: struct

237. The parentheses around the de referenced pointer is necessary to enforce the correct
_______.
Ans: precedence

238. An alternative notation other than dot, permits simpler pointer access to structure members
is ____________.
Ans: ->

239. A __________ holds the value of one-variable at a time.


Ans: Union

240. The compiler allocates storage for the smallest member of the union. (True/False)

pg. 29
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
Ans: false

241. Which of the following header files is used for character type function in C language?

a. <assert.h>
b. <ctype.h>
c. <iostream.h>
d. <locale.h>

Ans: b

242. Which symbol is used to declare a pointer?

a. *
b. #
c. &
d. &&

Ans: a

243. Which function is used to reverse the string?


a) strcmp
b) strrev
c) strlen
d) strupr
Ans: b

244. Which header file is used for string functions?


a) math.h
b) stdio.h
c) string.h
d) conio.h
Ans: c

245. # include is called ________.


Ans: Preprocessor directive

246. Nesting of included files is not allowed. (True/False)


Ans: False

247. Defining instances of global variables is not recommended in the header files. (True/False)
Ans: True

pg. 30
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
248. The role of preprocessor in macro substitution is ______substitution according to the
macro definition.
Ans: Text

249. Macros and functions are synonyms. (True/False)


Ans: False

250. Nesting of macros is not allowed. (True/False)


Ans: False

251. In ANSI C, the function to delete a file is __________ .


Ans: remove

252. On older Unix systems, the function was called ______________.


Ans: unlink

253. You can use _______________ directive which compiles code depending on whether a
compile-time expression is true or false.
Ans: #if

254. Loops in C Language are implemented using.?


A) While Block
B) For Block
C) Do While Block
D) All the above

Ans: d

255. Choose correct statement about Functions in C Language.


A) A Function is a group of c statements which can be reused any number of times.
B) Every Function has a return type.
C) Every Function may no may not return a value.
D) All the above.
Ans: d

256. Choose a correct statement about C Language Functions.


A) A function name can not be same as a predefined C Keyword.
B) A function name can start with an Underscore( _ ) or A to Z or a to z.
C) Default return type of any function is an Integer.
D) All the above.
Ans: d

257. A function which calls itself is called a ___ function.


A) Self Function

pg. 31
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
B) Auto Function
C) Recursive Function
D) Static Function
Ans: c

258. What is the output of C Program with functions.?


void show();
int main()
{
show();
printf("ARGENTINA ");
return 0;
}

void show()
{
printf("AFRICA ");
}
A) ARGENTINA AFRICA
B) AFRICA ARGENTINA
C) ARGENTINA
D) Compiler error
Ans: b

259. The process of allocating memory at run time is known as _________________.


Ans: Dynamic Memory Allocation

260. malloc() function returns a pointer to integer. (True/False)


Ans: False

261. For deallocating memory, you can use _________ function.


Ans: free()

262. The function that is used to alter the size of a block previously allocated is
______________.
Ans: realloc()

263. A linked list is a data structure that is used to model a dynamic list of data items and is a
collection of ___________.
Ans: nodes.

pg. 32
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
264. Linked list make use of ____________ memory allocation technique.
Ans: dynamic

265. What is the limit for number of functions in a C Program.?


A) 16
B) 31
C) 32
D) None of the above
Ans: D

266. What is the minimum number of functions to be present in a C Program.?


A) 1
B) 2
C) 3
D) 4
Ans: a

267. What is the output of C Program with functions and pointers.?


int main()
{
int b=25;
//b memory location=1234;
int *p = b;
printf("%d %d", b, p);

return 0;
}
A) 25 1234
B) 25 0
C) 25 25
D) Compiler error
Ans: c

268. The type FILE is predefined in the header file ___________.


Ans: stdio.h

269. We may add a “+’’ character to the mode string in the fopen function to indicate that we
want to both read and write. (True/False)
Ans: True

pg. 33
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
270. __________ returns non-zero if the stream's error indicator is set, zero otherwise.
Ans: ferror

271. ____________ function returns the current value (measured in characters) of the file
position indicator if stream refers to a binary file.
Ans: ftell

272. fseek allows the file position indicator for stream to be set to an arbitrary value.
(True/False)
Ans: True

273. __________ stores the current file position indicator for stream in the object pointed to by
pos.
Ans: fgetpos

274. Command line argument is a parameter supplied to a program when the program is
invoked. (True/False)
Ans: true
275. In the command line arguments of main(), argv is an array-of-pointers to-___________.
Ans: char

276. The ____________ is a parameter supplied to a program when the program is invoked.
Ans: Command line argument

277. What is the dimension of the C array int ary[10][5].?


A) 1
B) 2
C) 5
D) 10
Ans: b

278. What is the dimension of the below C Array.?


int ary[]={1,3,5,7};
A) 1
B) 2
C) 3
D) 5
Ans: a

279. Choose facts about continue; statement is C Language.


A) continue; is used to take the execution control to next iteration or sequence
B) continue; statement causes the statements below it to skip for execution
C) continue; is usually accompanied by IF statement.
D) All the above.
Ans: d

pg. 34
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
280. Choose a correct statement about C break; statement.?
A) break; statement can be used inside switch block
B) break; statement can be used with loops like for, while and do while.
C) break; statement causes only the same or inner loop where break; is present to quit
suddenly.
D) All the above.
Ans: d

281. Choose a correct C Statement regarding for loop.


for(; ;);
A) for loop works exactly first time
B) for loop works infinite number of times
C) Compiler error
D) None of the above
Ans: b

282. Long Double data type size of (bit).

a) 8

b) 16

c) 64

d) 80

Ans: d

283. unsigned chars have values between 0 and 255. (True/False)

Ans: True

284. signed chars have values from

a) -128 to 127

b) 128 to 127

c) 1 to 127

d) none of these

Ans: a

pg. 35
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
285. putchar() function is an input function.(True/False)

Ans: false

286. puts() is a formatted input statement. (True/False)

Ans: false

287. getchar(),putchar(), scanf(), printf(), gets() and puts(). These functions can be

accessed within a program by including the header file.

a) stdio.h

b) math.h

c) conio.h

d) ctype.h

Ans: a

288. short int means?

a) Qualifier

b) short is the qualifier and int is the basic data type

c) data type

d) All of the above

Ans: b

289. User-defined data type ?

a) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;

b) struct {char name[10], int age};

c) typedef int Boolean;

d) All of the above

Ans: d

pg. 36
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
290. Which of the data types has the size that is variable?

a) struct

b) int

c) float

d) double

Ans: a

291. Tick the statement which is not supported by C.

a) Char str

b) char *str;

c) String str;

d) float I;

Ans: c

292. No of keywords in C ?

a) 35 Only

b) 36 Only

c) 34 Only

d) 32 Only

Ans: d

293. Can we pass a variable argument list to a function at run-time?

a) Ture.

b) False.

Ans: b

294. C variable cannot start with a

a) number

b) Both A and C

pg. 37
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
c) Any special symbol except underscore

d) None of the above

Ans: b

295. Which of the following symbol is used in variable name

a) &

b) _

c) #

d) @

Ans: b

296. We can not declare a multuple function with same name?

a) True

b) False

Ans: b

297. Which of the following is not an output ?

a) a / = 10;

b) a * = 10;

c) a ! = 10;

d) a % = 10;

Ans: c

298. Real number is treated as

a) double

b) long double

c) long int

d) float

Ans:a

pg. 38
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
299. getch() belongs to which header file .

a) math.h

b) stdio.h

c) iostream.h

d) conio.h

Ans: d

300. Can we run program without a main() function

a) Yes

b) No

Ans: b

Q1 Write a program to accept a number and check the number is even or odd?

Ans: #include<stdio.h>

int main()

int number;

printf("Enter a number:");

scanf("%d",&number);

if(number%2==0)

pg. 39
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
printf("%d is even number",number);

else

printf("%d is odd number",number);

return 0;

Q2. Write a program to accept three number and find out the largest of three number.

Ans: #include <stdio.h>

int main()

int a, b, c;

printf("Enter three numbers?");

scanf("%d %d %d",&a,&b,&c);

if(a>b && a>c)

printf("%d is largest",a);

else if(b>a && b > c)

printf("%d is largest",b);

else if(c>a && c>b)

pg. 40
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
printf("%d is largest",c);

else if(a == b && a == c)

printf("All are equal");

Q3. Write a program to accept the marks and check the grade depends of a condition
(marks >85 display grade A,marks >60 display grade B+, marks>40 display grade B,
marks>30 display grade C, other wise display fail).

Ans: #include <stdio.h>

int main()

int marks;

printf("Enter your marks?");

scanf("%d",&marks);

if(marks > 85 && marks <= 100)

printf("Congrats ! you scored grade A ...");

else if (marks > 60 && marks <= 85)

printf("You scored grade B + ...");

else if (marks > 40 && marks <= 60)

pg. 41
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
printf("You scored grade B ...");

else if (marks > 30 && marks <= 40)

printf("You scored grade C ...");

else

printf("Sorry you are fail ...");

Q4. What is constraint? Explain the types of constraint?

Ans: Constants in C refer to fixed values that do not change during the execution of a program. C
supports several types of constants:
1. Integer constants
An integer constant refers to a sequence of digits. There are three types of integers, namely decimal,
octal and hexadecimal.
Decimal integers consist of a set of digits, 0 through 9, preceded by an optional – or +.
Examples: 12, -546, 0, 354647, +56

2. Real constants
The numbers containing fractional parts like 67.45 are called real (or floating point) constants.
Examples: 0.0045, -8.5, +345.678

3. Character constants
A single character constant (or simple character constant) contains a single character enclosed within a
pair of single quote marks.
Examples: ‘6’, ‘X’, ‘;’

4. String constants
A string constant is a sequence of characters enclosed within double quotes.The characters may be
letters, numbers, special characters and blank space.
Examples: “Hello!”, “1947”, “5+3”

Q5. Write a program to accept a year and check the year is leap year or not a leap year.

Ans:

pg. 42
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
#include<stdio.h>
#include<conio.h>
int main()
{
int year;
printf("Enter Year: ");
scanf("%d", &year);
if((year%4==0) && (year%100!=0))
printf("\nIt's a Leap Year");
else if(year%400==0)
printf("\nIt's a Leap Year");
else
printf("\nIt's not a Leap Year");
getch();
return 0;
}

Q6. write a program in C that converts temperature given in degree Fahrenheit to


temperature in degree Celsius. 

Ans: #include<stdio.h>
#include<conio.h>
int main()
{
float fahrenheit, celsius;
printf("Enter Temperature Value (in Fahrenheit): ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit-32)/1.8;
printf("\nEquivalent Temperature (in Celsius) = %0.2f", celsius);
getch();
return 0;
}

Q7. What is operator? Explain the five types of operator?

An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.
Operators are used in programs to manipulate data and variables. There are very types of operator:

1. Arithmetic operators
2. Unary operator
3. Relational operators
4. Logical operators
5. Conditional operator

6. Bitwise operators
7. Increment and Decrement operators

pg. 43
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
1. Arithmetic Operators
The basic operators for performing arithmetic are the same in many computer languages:
+ addition
- subtraction
* multiplication
/ division
% modulus (remainder)

2. Unary Operator
A unary operator acts upon a single operand to produce a new value. Example (++,--)

3. Relational

The relational operators such as <, <=, >, and >= are in fact operators, just like +, -, *, and /. The
relational operators take two values, look at them, and “return'' a value of 1 or 0 depending on whether
the tested relation was true or false. The complete set of relational operators in C is:
< less than
<= less than or equal
> greater than
>= greater than or equal
== equal
!= not equal

4. Logical operators

You can also combine true/false values by using the Boolean operators(also called the logical
operators), which take true/false values as operands and compute new true/false values. The three
Logical operators are:
&& AND
|| OR
! NOT (takes one operand, “unary'')

Q8. Write a program to accept a number and find out a factorial number.

Ans:

#include<stdio.h>
#include<conio.h>
int main()
{
int num, i, fact=1;
printf("Enter any number: ");
scanf("%d", &num);
for(i=num; i>0; i--)
fact = fact*i;
printf("\nFactorial of %d = %d", num, fact);
getch();
return 0;
}

pg. 44
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
Q9. What is Library Function? write any five library function?
Ans:
The C language is accompanied by a number of library functions or built in functions that carry
out various commonly used operations or calculations. There are library functions that carry out
standard input/output operations, functions that perform operations on characters, functions that
perform
operations on strings and functions that carry out various mathematical calculations.
A library function is accessed simply by writing the function name, followed by a list of
arguments that represent information being passed to the function. A typical set of library
functions will include a large number of functions that are common to most C compilers.
pow(d1,d2) Return d1 raised to the power d2

putchar(c) Send a character to the standard output device

rand() Return a random positive integer

sin(d) Return sine of d

sqrt(d) Return the square root of d

tan(d) Return the tangent of d

toascii(c) Convert value of argument to ASCII

tolower(c) Convert letter to lowercase

toupper(c) Convert letter to uppercase

Q10. Write a program to accept a number and find out a factorial number using function.

Ans:
#include<stdio.h>
#include<conio.h>
int findFact(int);
int main()
{
int num, fact;
printf("Enter any number: ");
scanf("%d", &num);
fact = findFact(num);
printf("\nFactorial of %d = %d", num, fact);
getch();
return 0;
}

pg. 45
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
int findFact(int n)
{
int i=n, f=1;
while(i>0)
{
f = f*i;
i--;
}
return f;
}

Q11. write a  program that will calculate the factorial of any given number using recursive
function?

Ans: #include<stdio.h>
#include<conio.h>
int findFact(int);
int main()
{
int num, fact;
printf("Enter the number: ");
scanf("%d", &num);
fact = findFact(num);
printf("Factorial = %d", fact);
getch();
return 0;
}
int findFact(int val)
{
if(val==1)
return val;
else
return val*findFact(val-1);
}

Q12. Write a program to accept a character value and check the character value is vowel
or consonant. (using switch statement)

Ans:

#include <stdio.h>

int main()

char input;

pg. 46
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
printf( "Enter a character " );

scanf( "%c", &input );

switch ( input )

case 'a':

printf("vowel character is: %c",input);

break;

case 'e':

printf("vowel character is: %c",input);

break;

case 'i':

printf("vowel character is: %c",input);

break;

case 'o':

printf("vowel character is: %c",input);

break;

case 'u':

printf("vowel character is: %c",input);

break;

case 'A':

printf("vowel character is: %c",input);

break;

case 'E':

printf("vowel character is: %c",input);

break;

pg. 47
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
case 'I':

printf("vowel character is: %c",input);

break;

case 'O':

printf("vowel character is: %c",input);

break;

case 'U':

printf("vowel character is: %c",input);

break;

default:

printf( "Consonant" );

break;

return 0;

Q13. Write a program to accept a character value and check the character value is vowel
or consonant. (using if statement)

Ans:

#include <stdio.h>

int main()

char input;

printf( "Enter a character " );

scanf( "%c", &input );

pg. 48
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
if(input == ‘a’ || input == ‘A’ || input == ‘e’ || input == ‘E’ || input == ‘i’ || input == ‘I’ || input == ‘o’
|| input == ‘O’ || input == ‘u’ || input == ‘U’ )

printf( "Vowel character is: %c",input);

else

printf( "Consonant" );

return 0;

Q14. Write a Program to calculate the average of N numbers?

Ans:

#define N 10 /* SYMBOLIC CONSTANT */

Void main()

int count;

float sum, average, number;

sum = 0;

count = 0;

while (count<N)

Printf(“enter a number”);

scanf(“%f”, &number);

sum = sum + number;

pg. 49
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
count = count + 1;

average = sum / N;

printf(“N = % d Sum = %f “, N, sum);

printf(“Average = %f”, average);

Q15. write a program to accept any number and check number is prime or not.

Ans:

#include<stdio.h>

#include<conio.h>
int main()
{
int num, i, count=0;
printf("Enter a number: ");
scanf("%d", &num);
for(i=2; i<num; i++)
{
if(num%i == 0)
{
count++;
break;
}
}
if(count==0)
printf("\nIt's a prime number");
else
printf("\nIt's not a prime number");
getch();
return 0;
}

Q16. Write a Program to find largest of n numbers?

Ans:

#include<stdio.h>

#include<conio.h>

pg. 50
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
void main()

int num, large, n, i;

clrscr();

printf("enter number of numbers \n");

scanf(“%d”,&n);

large=0;

i=0;

while(i<n)

printf("\n enter number ");

scanf(“%d”, &num);

if(large<num)

large=num;

i++;

printf("\n large = %d”, large);

Q17. Program to add two matrices?

Ans:

#include <stdio.h>

Void main()

int a[5][5], b[5][5], c[5][5];

int i, j, m, n;

pg. 51
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
printf(“Enter the order of the matrices:”);

scanf(“%d%d”, &m, &n);

printf(“ Enter the elements of A matrix:\n”);

for(i=0;i<m;i++)

for(j=0;j<n;j++)

scanf(“%d”, &a[i][j]);

printf(“Enter the elements of B matrix:\n”);

for(i=0;i<m;i++)

for(j=0;j<n;j++)

scanf(“%d”, &b[i][j]);

/* Add the matrices */

for(i=0;i<m;i++)

for(j=0;j<n;j++)

c[i][j] = a[i][j]+b[i][j];

/* Print the sum */

printf(“The sum of matrices:\n”);

for(i=0;i<m;i++)

for(j=0;j<n;j++)

printf(“%d\t”, c[i][j]);

printf(“\n”);

Q18. Write a program to accept two number and swap the two number.

Ans: #include<stdio.h>
#include<conio.h>

pg. 52
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
int main()
{
int num1, num2, temp;
printf("Enter Two Numbers:-\n");
printf("First Number: ");
scanf("%d", &num1);
printf("Second Number: ");
scanf("%d", &num2);
printf("\nBefore Swap:\n");
printf("First Number = %d\tSecond Number = %d", num1, num2);
temp = num1;
num1 = num2;
num2 = temp;
printf("\n\nAfter Swap:\n");
printf("First Number = %d\tSecond Number = %d", num1, num2);
getch();
return 0;
}

Q19. write a program in C that reverse a number using for loop.


Ans:
#include<stdio.h>
#include<conio.h>
int main()
{
int num, rev, rem;
printf("Enter the Number: ");
scanf("%d", &num);
for(rev=0; num!=0; num=num/10)
{
rem = num%10;
rev = (rev*10)+rem;
}
printf("\nReverse = %d", rev);
getch();
return 0;
}

Q20. create a program that checks for a Palindrome number.


Ans:

#include<stdio.h>
#include<conio.h>
int main()
{
int num, rev=0, rem, temp;

pg. 53
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
printf("Enter a Number: ");
scanf("%d", &num);
temp = num;
while(temp>0)
{
rem = temp%10;
rev = (rev*10)+rem;
temp = temp/10;
}
if(rev==num)
printf("\nIt's a Palindrome Number");
else
printf("\nIt's not a Palindrome Number");
getch();
return 0;
}

Q21. Write a Program to swap two integers using pointers?

Ans:

#include<stdio.h>

main()

int a, b;

void swap(int *a, int *b);

printf(“ Read the integers:”);

scanf(“%d%d”, &a, &b);

swap(&a, &b); /* call by reference or call by address*/

printf(“ \nAfter swapping:a=%d b=%d”, a, b);

void swap(int *x, int *y)

pg. 54
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
{

int temp;

temp=*x;

*x=*y;

*y=temp;

return;

Q22. write a program prints half pyramid using star pattern.

Ans: #include<stdio.h>
#include<conio.h>
int main()
{
int i, j;
for(i=0; i<5; i++)
{
for(j=0; j<=i; j++)
printf("* ");
printf("\n");
}
getch();
return 0;
}

Output

Q23.  write a program to accept the array and finding the largest number from given list
(or array) 

pg. 55
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
Ans:
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[10], i, large;
printf("Enter 10 Array Elements: ");
for(i=0; i<10; i++)
scanf("%d", &arr[i]);
i=0;
large = arr[i];
while(i<10)
{
if(large<arr[i])
large = arr[i];
i++;
}
printf("\nLargest Number = %d", large);
getch();
return 0;
}

Q24. Write a program to accept name and find out of length of name.
Ans:

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[20];
int len;
printf("Enter the string: ");
gets(str);
len = strlen(str);
printf("\nLength of the string = %d", len);
getch();
return 0;
}

Q25. write a program to accept any two string and display full string using concatenate
function in string.

Ans:
#include<stdio.h>

pg. 56
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
#include<conio.h>
#include<string.h>
int main()
{
char str1[50], str2[50];
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
strcat(str1, str2);
printf("\nString after concatenation is:\n%s", str1);
getch();
return 0;
}

Q26. print a Fibonacci series 0 1 1 2 3 5 8 13 21 34……….n .

Ans:

#include<stdio.h>

int main()

int n1=0,n2=1,n3,i,number;

printf("Enter the number of elements:");

scanf("%d",&number);

printf("\n%d %d",n1,n2);//printing 0 and 1

for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed

n3=n1+n2;

printf(" %d",n3);

n1=n2;

n2=n3;

pg. 57
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
return 0;

Q27. To print the Name, Salary and date of joining of a person.(using Structures)

Ans:

#include<conio.h>

#include<stdio.h>

struct personal

char name[30];

int day;

int month;

int year;

float salary;

};

void main()

struct personal p;

printf(“Enter the name:\n)";

gets(p.name);

printf(“Enter the day of joining:\n)";

scanf(“%d”,&p.day);

printf(“Enter the month of joining:\n");

scanf(“%d”,&p.month);

printf(“Enter the year of joining:\n)";

scanf(“%d”,&p.year);

pg. 58
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
printf(“Enter the salary:\n)";

scanf(“%f”, & p.salary);

printf(“\nName:",p.name);

printf("\nDate of joining:%d %d %d",p.day,p.month,p.year);

printf(“Salary:",p.salary);

getch();

Q28. print a pattern like

1
12
123
123 4

Ans:

#include <stdio.h>

int main() {

int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

for (i = 1; i <= rows; ++i) {

for (j = 1; j <= i; ++j) {

printf("%d ", j);

printf("\n");

return 0;

pg. 59
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
Q29. print a pattern like

1
22
333
4444

Ans:

#include <stdio.h>

int main() {

int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

for (i = 1; i <= rows; ++i) {

for (j = 1; j <= i; ++j) {

printf("%d ", i);

printf("\n");

return 0;

Q30. Difference between Structure and Union?

Ans:

Structure

A structure is a user-defined data type available in C that allows to combining data items of
different kinds. Structures are used to represent a record.
Defining a structure: To define a structure, you must use the struct statement. The struct
statement defines a new data type, with more than one member. The format of the struct
statement is as follows:

pg. 60
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
struct [structure name]
{
member definition;
member definition;
...
member definition;
};

union
A union is a special data type available in C that allows storing different data types in the same
memory location. You can define a union with many members, but only one member can
contain a value at any given time. Unions provide an efficient way of using the same memory
location for multiple purposes.
Defining a Union: To define a union, you must use the union statement in the same way as
you did while defining a structure. The union statement defines a new data type with more than
one member for your program. The format of the union statement is as follows:

union [union name]


{
member definition;
member definition;
...
member definition;
};

Q31. Write a program to accept n number and calculate the sum of odd number and sum
of even number using loop?

Ans:

#include <stdio.h>

#include <stdlib.h>

int main()

pg. 61
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
{

int i, num; //declare variables i, num

int oddSum=0,evenSum=0;

//declare and initialize variables oddSum,evenSum

printf("Enter the value of num \n");

scanf("%d",&num);

for(i=1; i<=num; i++){// for loop use to iterate 1 to num

if(i%2==0) //Check even number for sum

evenSum=evenSum+i;

else

oddSum=oddSum+i;

printf("Sum of all odd numbers are: %d",oddSum);

printf("\nSum of all even numbers are: %d",evenSum);

getch();

return 0;

Q32. Write a program to accept n number and count the odd number and even number
in an array?

Ans:

#include<stdio.h>

int main()

//fill your code

int n;

pg. 62
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
scanf(“%d”,&n);

int arr[n];

for(int i = 0; i < n; i++)

scanf(“%d”,&arr[i]);

int count_odd =0, count_even = 0;

for(int i = 0; i < n; i++)

if(arr[i] % 2 == 1)

count_odd++;

else

count_even++;

printf(“Odd: %d”,count_odd);

printf(“\nEven: %d”,count_even);

return 0;

Q33. Write a program to find out the largest number in an array?

Ans:

#include<stdio.h>

int main()

pg. 63
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
int a[10], Size, i, Largest, Position;

printf("\nPlease Enter the size of an array \n");

scanf("%d",&Size);

printf("\nPlease Enter %d elements of an array: \n", Size);

for(i=0; i<Size; i++)

scanf("%d",&a[i]);

Largest = a[0];

for(i=1; i<Size; i++)

if(Largest<a[i])

Largest=a[i];

Position = i;

printf("\nLargest element in an Array = %d", Largest);

printf("\nIndex position of the Largest element = %d", Position);

return 0;

pg. 64
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
}

Q34. Write a program to accept a string and count Alphabets Digits and Special Characters
in a String?

Ans:

#include <stdio.h>

int main()

char str[100];

int i, alphabets, digits, special;

i = alphabets = digits = special = 0;

printf("\n Please Enter any String : ");

gets(str);

while (str[i] != '\0')

if( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') )

alphabets++;

else if (str[i] >= '0' && str[i] <= '9')

pg. 65
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
digits++;

else

special++;

i++;

printf("\n Number of Alphabets in this String = %d", alphabets);

printf("\n Number of Digits in this String = %d", digits);

printf("\n Number of Special Characters in this String = %d", special);

return 0;

Q35. Write a program to find transpose of a matrix?

Ans:

#include <stdio.h>

int main()

int m, n, c, d, matrix[10][10], transpose[10][10];

printf("Enter the number of rows and columns of a matrix\n");

scanf("%d%d", &m, &n);

printf("Enter elements of the matrix\n");

pg. 66
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
for (c = 0; c < m; c++)

for (d = 0; d < n; d++)

scanf("%d", &matrix[c][d]);

for (c = 0; c < m; c++)

for (d = 0; d < n; d++)

transpose[d][c] = matrix[c][d];

printf("Transpose of the matrix:\n");

for (c = 0; c < n; c++) {

for (d = 0; d < m; d++)

printf("%d\t", transpose[c][d]);

printf("\n");

return 0;

Q36. Write a program to create simple calculator using switch case and functions?

Ans:

#include <stdio.h>

// Function declarations for calculator

float add(float num1, float num2);

pg. 67
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
float sub(float num1, float num2);

float mult(float num1, float num2);

float div(float num1, float num2);

int main()

char op;

float num1, num2, result=0.0f;

/* Print welcome message */

printf("WELCOME TO SIMPLE CALCULATOR\n");

printf("----------------------------\n");

printf("Enter [number 1] [+ - * /] [number 2]\n");

/* Input two number and operator from user */

scanf("%f %c %f", &num1, &op, &num2);

switch(op)

case '+':

result = add(num1, num2);

break;

case '-':

result = sub(num1, num2);

pg. 68
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
break;

case '*':

result = mult(num1, num2);

break;

case '/':

result = div(num1, num2);

break;

default:

printf("Invalid operator");

/* Print the result */

printf("%.2f %c %.2f = %.2f", num1, op, num2, result);

return 0;

float add(float num1, float num2)

return num1 + num2;

float sub(float num1, float num2)

pg. 69
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
return num1 - num2;

float mult(float num1, float num2)

return num1 * num2;

float div(float num1, float num2)

return num1 / num2;

Q37. Write a program to display Fibonacci series in c within a range using a function?

Ans:

#include<stdio.h>

void fibonacciSeries(int range)

int a=0, b=1, c;

while (a<=range)

printf("%d\t", a);

c = a+b;

pg. 70
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
a = b;

b = c;

int main()

int range;

printf("Enter range: ");

scanf("%d", &range);

printf("The fibonacci series is: \n");

fibonacciSeries(range);

return 0;

Q38. Write a program to convert decimal to octal number?

Ans:

#include <stdio.h>

int main()

int octalNumber[10], number, i, j;

printf("\n Please Enter the Number You want to Convert : ");

pg. 71
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
scanf("%d", &number);

for(i = 0; number > 0; i++)

octalNumber[i] = number % 8;

number = number / 8;

printf("\n Equivalent Octal Number of a Given Number = ");

for(j = i - 1; j >= 0; j--)

printf("%d", octalNumber[j]);

return 0;

Q39. Write a program to convert decimal to Binary number?

Ans:

#include<stdio.h>

#include<stdlib.h>

int main(){

int a[10],n,i;

system ("cls");

printf("Enter the number to convert: ");

scanf("%d",&n);

for(i=0;n>0;i++)

pg. 72
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
{

a[i]=n%2;

n=n/2;

printf("\nBinary of Given Number is=");

for(i=i-1;i>=0;i--)

printf("%d",a[i]);

return 0;

Q40. Difference between while loop and do-while loop in c?

Ans:

while loop do-while loop


While the loop is an entry control loop The do-while loop is an exit control loop because
because firstly, the condition is checked, in this, first of all, the body of the loop is executed
then the loop's body is executed. then the condition is checked true or false.
The statement of while loop may not be The statement of the do-while loop must be
executed at all. executed at least once.
The while loop terminates when the As long as the condition is true, the compiler
condition becomes false. keeps executing the loop in the do-while loop.
In a while loop, the test condition In a do-while loop, the variable of test condition

pg. 73
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
variable must be initialized first to check Initialized in the loop also.
the test condition in the loop.
In a while loop, at the end of the In this, at the end of the condition, there is a
condition, there is no semicolon. semicolon.
Syntax: Syntax:
while (condition) while (condition);
While loop is not used for creating It is mostly used for creating menu-driven
menu-driven programs. programs because at least one time; the loop is
executed whether the condition is true or false.
In a while loop, the number of In a do-while loop, irrespective of the condition
executions depends on the condition mentioned, a minimum of 1 execution occurs.
defined in the while block.
Syntax of while loop: Syntax of do-while loop:
while (condition) do
{ {
Block of statements; statements;
} }
Statement-x; while (condition);
Statement-x;

41. a) Explain Structure of a C Program

ANS-. C programme is a high base programming language. C is a general-purpose, structured


programming language. Its instructionsconsist of terms that resemble algebraic expressions,
augmented by certain

C Basic Structure

C is characterized by the ability to write very concise source programs, due in part to the large
number of operators included within the language. Thus, the features and capabilities of the
language can easily be manipulated.

There are 7 sections

1 documentation section

2.link section

3. definition section

4. global diclation section

pg. 74
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
5.main() functions

6.subprogramme section

The documentation section consists of a set of comment (remarks) linesgiving the name of the
program, the author and other details which the programmer would like to use later.

B. Explain various constants used in C Programming with example.

ANS- Constants in C refer to fixed values that do not change during the execution

of a program. C supports several types of constants

Constantsdevided in to two types

i. Numeric constants ii. Character constants

Then numeric constant devided in to two types 1. Intiger constant

2. Real constant

Similarly character constatant devided into two types 1 . string constant 2. Single character
constant

Integer constants

An integer constant refers to a sequence of digits. There are three types ofintegers, namely
decimal, octal and hexadecimal.

Decimal integers consist of a set of digits, 0 through 9, preceded by an

optional – or +.

Examples: 12, -546, 0, 354647, +56

An octal integer constant consists of any combination of digits from the set 0through 7, with a
leading 0.

Examples: 045, 0, 0567

A sequence of digits preceded by 0x or 0X is considered as hexadecimal

integer. They may also include alphabets A through F or a through f. The letters A through F
represent numbers 10 through 15.

Examples: 0X6, 0x5B, 0Xbcd, 0X

pg. 75
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
The largest integer value that can be stored is machine-dependent. It is

32767 on 16-bit machines and 2,147,483,647 on 32-bit machines. It is alsopossible to store


larger integer constants on these machines by appendingqualifiers such as U, L and UL to the
constants.

Examples: 54637U or 54637u (unsigned integer)

Real constants

The numbers containing fractional parts like 67.45 are called real (or floating point) constants.

Examples: 0.0045, -8.5, +345.678

A real number may also be expressed in exponential (scientific) notation.The general form is:

mantissa e exponent

The mantissa is either a real number expressed in decimal notation or an integer. The exponent
is an integer number with an optional plus or minus sign. The letter e separating the mantissa
and the exponent can be written in either lowercase or uppercase.

Examples: 04e4, 12e-2, -1.3E-2

7500000000 may be written as 7.5E9 or 75E8.

Floating point constants are normally represented as double-precision quantities. However, the
suffixes f or F may be used to force single precision and l or L to extend double-precision
further.

Character constants

A single character constant (or simple character constant) contains a singlecharacter enclosed
within a pair of single quote marks.

Examples: ‘6’, ‘X’, ‘;’

Character constants have integer values known as ASCII values. Forexample, the statement

printf(“%d”, ‘a’);

would print the number 97, the ASCII value of the letter a. Similarly, thestatement

printf(“%c”, 97);

would print the letter a.

String constants

pg. 76
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
A string constant is a sequence of characters enclosed within double quotes.

The characters may be letters, numbers, special characters and blank

space.

Examples: “Hello!”, “1947”, “5+3”

42.(a) Explain bitwise operators with example

ANS- Bitwise Operators

ANS

The bitwise operators &, |, ^, and ~ operate on integers thought of as binarynumbers or strings
of bits. The & operator is bitwise AND, the | operator is bitwise OR, the ^ operator is bitwise
exclusive-OR (XOR), and the ~operator is a bitwise negation or complement. (&, |, and ^ are
“binary'' in thatthey take two operands; ~ is unary.) These operators let you work with the
individual bits of a variable; one common use is to treat an integer as a set of single-bit flags.
You might define the 3rd bit as the “verbose'' flag bit by

defining

#define VERBOSE 4

Then you can “turn the verbose bit on'' in an integer variable flags by executing

flags = flags | VERBOSE;

and turn it off with

flags = flags & ~VERBOSE;

and test whether it's set with

if(flags & VERBOSE)

The left-shift and right-shift operators << and >> let you shift an integer left

or right by some number of bit positions; for example, value << 2 shifts value

left by two bits.

The comma operator can be used to link the related expressions together.

The expressions are executed one after the other. The most common use

for comma operators is when you want multiple variables controlling a for

pg. 77
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
loop, for example:

for(i = 0, j = 10; i < j; i++, j--)

b. Operator precedence determines which operator is performed first in an expression with


more than one operators with different precedence. ... For example: '*' and '/' have
same precedence and their associativity is Left to Right, so the expression “100 / 10 * 10” is
treated as “(100 / 10) * 10”.

Precedence is the priority for grouping different types of operators with their


operands. Associativity is the left-to-right or right-to-left order for grouping operands
to operators that have the same precedence. ... Expressions with higher-precedence
operators are evaluated first.

Q2.(B) What do you understand by precedence and associativity of an operator. Explain with
example.

Precedence:-

The precedence of C operators dictates the order of evaluation within anexpression. The
precedence of the operators introduced here is summarised in the highest precedence
operators are given first.

Operators

Associativity

( ) -> .

left to right

! ~ + - ++ -- & *

right to left

pg. 78
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
*/%

left to right

+-

left to right

< <= > >=

left to right

== !=

left to right

&

left to right

left to right

&&

left to right

||

right to left

= *= /= %= += -=

pg. 79
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
right to left

Where the same operator appears twice (for example *) the first one is the unary version.

Example:

#include<stdio.h>

Int main()

/* Evaluation of expressions */

float a, b, c, x, y, z;

a=20;

b=2;

c=-23;

x = a + b / ( 3 + c * 4 - 1);

y = a – b / (3 + c) * ( 4 – 1);

z= a – ( b / ( 3 + c ) * 2 ) – 1;

printf( “x=%f\n”, x);

printf(“y=%f\n”, y);

printf(“z=%f\n”, z);

return 0;

ASSOCIATIVITY OF AN OPERATOR:-

pg. 80
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
C supports a rich set of operators. An operator is a symbol that tells thecomputer to perform
certain mathematical or logical manipulations.Operators are used in programs to manipulate
data and variables. A binaryoperator acts on two operands. A unary operator acts upon a single
operandto produce a new value. Multiplication, division, and modulus all have higher recedence
than addition and subtraction.

43. a) What do you understand by type casting. Explain with example.

TYPE CASTING

C performs type conversions automatically. However, there are instances when we want to
force a type conversion in a way that is different from the automatic conversion. Consider,

for example, the calculation of ratio of doctors to engineers in a town.

Ratio = doctor_number / engineer _number

Since doctor _number and engineer_number are declared as integers in the program, the
decimal part of the result of the division would be lost and Ratio would represent a wrong figure.
This problem can be solved by converting locally one of the variables to the floating point as
shown below:

Ratio = (float) doctor_number / engineer _number

(type-name) expression

where type-name is one of the standard C data types. The expression may be a constant,
variable or an expression.

Example

Action

X=(int) 8.5

8.5 is converted to integer by truncation.

pg. 81
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
A=(int) 21.3 / (int) 4.5

Evaluated as 21/4 and the result would be 5.

B=(double) sum/n

Division is done in floating point mode.

Y= (int) (a+b)

The result of a+b is converted to integer.

Z= (int) a+b

a is converted to integer and then added to b.

P=cos(( double)x)

Converts x to double before using it.

b) Explain unformatted and formatted input and output functions with example.

Formatted Input and Output

Input data can be entered into the computer from a standard input device by means of the
standard C library function scanf(). This function can be used to enter any combination of
numerical values, single character and strings.

pg. 82
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
The function returns the number of data items th at have been entered successfully.

The syntax of scanf function is as follows:

scanf(control string, arg1, arg2, …argn)

where control string refers to a string containing certain required formatting information, and
arg1, arg2,…, argn are arguments that represent the individual input data items. The arguments
represent pointers that indicate addresses of the data items within the computer’s memory.

The control string consists of control characters, whitespace characters, andnon-whitespace


characters. The control characters are preceded by a %

Control Character

Explanation

%c

a single character

%d

a decimal integer

%i

an integer

%e, %f, %g

a floating-point number

%o

an octal number

pg. 83
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
%s

a string

%x

a hexadecimal number

%p

a pointer

%n

an integer equal to the number of characters read so far

%u

an unsigned integer

%[]

a set of characters

%%

a percent sign

scanf() reads the input, matching the characters from format. When acontrol character is read, it
puts the value in the next variable. Whitespaces(tabs, spaces, etc) are skipped. Non-
whitespace characters are matched tothe input, then discarded. If a number comes between the
% sign and thecontrol character, then only that many characters will be entered into the

pg. 84
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
variable. If scanf() encounters a set of characters, denoted by the %[] control character, then
any characters found within the brackets are read into the variable. The return value of scanf()
is the number of variables that were successfully assigned values, or EOF if there is an error

Formatted Output

Output data can be written from the computer onto a standard output deviceusing the library
function printf(). This function can be used to output any combination of numerical values, single
characters and strings. It is similar

to the input function scanf(), except that its purpose is to display data rather than enter into the
computer.

The syntax of the printf function can be written as follows:

printf(control string, arg1, arg2, …, argn)

where control string refers to a string that contains formatting information,and arg1, arg2, …,
argn are arguments that represent the individual output data items. The arguments can be
written as constants, single variable or array names, or more complex expressions.

Examples:

printf("Hello, world!\n");

printf("i is %d\n", i);

printf(“%d”, 10);

printf(“%d”, i+j);

The first statement simply displays the string given as argument to the printf() function. In the
second statement, printf() function replaces the two characters %d with the value of the variable
i. In the third statement the argument to be printed is a constant and in the fourth, the argument
is an expression.

44 (a) Explain goto statement with example.

Ans:

The goto statement

pg. 85
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
C supports the goto statement to branch unconditionally from one point to another in the program. Although it
may not be essential to use the goto statement in a highly structured language like C, there may be occasions
when the use of goto might be desirable.

The goto requires a label in order to identify


the place where the branch is to be made. A
label is any valid variable name, and must be
followed by a colon. The label is placed
immediately before the statement where the
control is to be transferred. The general forms
of goto and label statements are shown below:

The label can be anywhere in the program either before the goto or after the goto label; statement. During
execution of the program when a statement like

goto first;

is met, the flow of control will jump to the statement immediately following the label first. This happens
unconditionally.

Note that a goto breaks the normal sequential execution of the program. If the label is before the statement goto
label; a loop will be formed and some statements will be executed repeatedly. Such a jump is known as a
backward jump. On the other hand, if the label is placed after the goto label; some statements will be skipped
and the jump is known as the forward jump.

A goto is often used at the end of a program to direct the control to go to the input statement, to read further
data. Consider the following example:

//goto statement example

#include<stdio.h>

main()

double a, b;

read:

pg. 86
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
printf(“enter the value of a\n”);

scanf(“%f”, &a);

if (a<0) goto read;

b=sqrt(a);

printf(“%f %f \n”,a, b);

goto read;

Q44(B)Explain nested if statement.

Ans:

Nesting of if statements
It's also possible to nest one if statement inside another. (For that matter, it's in general possible to nest any kind
of statement or control flow construct within another.) For example, here is a little piece of code which decides
roughly which quadrant of the compass you're walking into, based on an x value which is positive if you're walking
east, and a y value which is positive if you're walking north:

Example

//Program to print the largest of three numbers

#include<stdio.h>

main()

pg. 87
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
int a,b,c,big;

printf (“Enter three numbers”);

scanf (“%d %d %d”, &a, &b, &c);

if (a>b) // check whether a is greater than b if true then

if(a>c) // check whether a is greater than c

big = a ; // assign a to big

else big = c ; // assign c to big

else if (b>c) // if the condition (a>b) fails check whether b is greater than c

big = b ; // assign b to big

else big = c ; // assign C to big

printf (“Largest of %d,%d&%d = %d”, a,b,c,big);

Q45 (a) What is a function? How can you declare a function? Explain with example.

Ans:

Function
A function is a self-contained program segment that carries out some specific, well-defined task. Every C program
contains one or more functions. One of these functions must be called main. Program execution will always begin
by carrying out the instructions in main. Additional functions will be subordinate to main, and perhaps to one
another.

So what defines a function? It has a name that you call it by, and a list of zero or more arguments or parameters.
Parameters (also called formal parameters) or arguments are the special identifiers through which information
can be passed to the function. A function has a body containing the actual instructions (statements) for carrying
out the task the function is supposed to perform; and it may give you back a return value, of a particular type.

In general terms, the first line can be written as

data-type name(data-type parameter 1, data-type parameter 2, …, data-type parameter n)

Example : Here is a very simple function, which accepts one argument, multiplies it by 4, and hands that value
back.

int multbyfour(int x)

pg. 88
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
{

int retval;

retval = x * 4;

return retval;

On the first line we see the return type of the function (int), the name of the function (multbyfour), and a list of
the function's arguments, enclosed in parentheses. Each argument has both a name and a type; multbyfour
accepts one argument, of type int, named x. The name x is arbitrary, and is used only within the definition of
multbyfour. The caller of this function only needs to know that a single argument of type int is expected; the
caller does not need to know what name the function will use internally to refer to that argument.

Function Prototypes
it is considered good practice to use prototype declarations for all functions that you call. As we mentioned, these
prototypes help to ensure that the compiler can generate correct code for calling the functions, as well as
allowing the compiler to catch certain mistakes you might make.

In general terms, a function prototype can be written as

data-type function_name(type1, type2, …, type n)

Examples:

int sample(int, int) or int sample(int a, int b);

float fun(int, float) or float fun( int a, float b);

If you write the function definition after the definition of its caller function, then the prototype is required in the
caller, but the prototype is optional if you write the definition of the function before the definition of the caller
function. But it is good programming practice to include the function prototype wherever it is defined.

Q45 (b) What is recursion? Give an example of recursion.

Ans:

Recursion
Recursion is a process by which a function calls itself repeatedly, until some specified condition has been met. The
process is used for repetitive computations in which each action is stated in terms of a previous result. Many
repetitive problems can be written in this form.

pg. 89
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
In order to solve a problem recursively, two conditions must be satisfied. First, the problem must be written in a
recursive form, and the second, the problem statement must include a stopping condition.

Example :

Factorial of a number. Suppose we wish to calculate the factorial of a positive integer, n. We would normally
express this problem as n!=1 x 2 x 3 x … x n.

This can also be written as n!=n x (n-1)!. This is the recursive statement of the problem in which the desired
action(the calculation of n!) is expressed in terms of a previous result (the value of (n-1)! which is assumed to be
known). Also, we know that 0!=1 by definition. This expression provides stopping condition for the recursion.

Thus the recursive definition for finding factorial of positive integer n can be written as:

fact(n)={ 1 if n=0

n x fact(n-1) otherwise}

Example:

//Program to find factorial of a given positive integer

#include <stdio.h>

void main()

{ int n;

long int fact(int);

/* Read in the integer quantity*/

scanf(“%d”, &n);

/*calaculate and display the factorial*/

printf(“n!=%ld\n”, fact(n));

long int fact(int n)

if(n==0)

return(1);

else

pg. 90
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
return (n*fact(n-1));

Q46 (a) What do you understand by storage class?

Ans:

Storage Classes
There are two ways to categorize variables: by data type, and by storage class. Data type refers to the type of
information represented by a variable, for example, integer number, floating-point number, character etc.
Storage class refers to the persistence of a variable and its scope within the program, that is, the portion of the
program over which the variable is recognized.

The following types of storage-class specifications in C are discussed in this unit: global, automatic or local, static,
and extern. The exact procedure for establishing a storage class for a variable depends upon the particular
storage class, and the manner in which the program is organized, (i.e. single file vs. multiple file).

Why would you want to limit the visibility of a variable? For maximum flexibility, wouldn't it be handy if all
variables were potentially visible everywhere? As it happens, that arrangement would be too flexible: everywhere
in a program, you would have to keep track of the names of all the variables declared anywhere else in the
program, so that you didn't accidentally re-use one. Whenever a variable had the wrong value by mistake, you'd
have to search the entire program for the bug, because any statement in the entire program could potentially
have modified that variable. You would constantly be stepping all over yourself by using a common variable name
like i in two parts of your program, and having one snippet of code accidentally overwrite the values being used
by another part of the code.

Q46 (b) What is static storage class? Write a program to generate Fibonacci numbers using static variables.

Ans:

Static Storage Class


The static storage class instructs the compiler to keep a local variable in existence during the life-time of the
program instead of creating and destroying it each time it comes into and goes out of scope. Therefore, making
local variables static allows them to maintain their values between function calls.

The static modifier may also be applied to global variables. When this is done, it causes that variable's scope to be
restricted to the file in which it is declared.

pg. 91
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
In C programming, when static is used on a global variable, it causes only one copy of that member to be shared
by all the objects of its class. Static variables are defined within individual functions and therefore have the same
scope as automatic variables, i.e. they are local to the functions in which they are declared. Unlike automatic
variables, however, static variables retain their values throughout the life of the program. As a result, if a function
is exited and then reentered later, the static variables defined within that function will retain their previous
values. This feature allows functions to retain information permanently throughout the execution of a program.
Static variables can be utilized within the function in the same manner as other variables. They cannot be
accessed outside of their defining function. In order to declare a static variable the keyword static is used as
shown below:

static int count;

You can define automatic or static variables having the same name as global variables. In such situations the local
variables will take precedence over the global variables, though the values of global variables will be unaffected
by any manipulation of the local variables.

Initial values can be included in static variable declaration. The rules associated with the initialization remain
same as the initialization of automatic or global variables. They are:

1. The initial values must be constants, not expressions.

2. The initial values are assigned to their respective variables at the beginning of the program execution. The
variables retain these values throughout the life of the program, unless different values are assigned during the
course of computation.

3. Zeros will be assigned to all static variables whose declarations do not include explicit initial values.

Example:

// Program to generate Fibonacci numbers.

#include<stdio.h>

main()

int count, n;

long int fib(int);

printf(“\n How many Fibonacci numbers?”);

scanf(“%d\n”, &n);

for(count=1;count<=n;count++)

pg. 92
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com
{

printf(“\ni=%d F=%ld”, count, fib(count));

long int fib(int count)

/* calculate a Fibonacci number using the formula

if i=1, F=0; if i=2, F=1, and F=F1+F2 for i>=3 */

static long int f1=0, f2=1; /* declaration of static variables */

long int f;

if (count==1)

f=0;

else if (count==2)

f=1;

else

f=f1+f2;

f2=f1;

f1=f; /* f1 and f2 retain their values between different calls of the

function*/

return f;

pg. 93
Solve Assignment Mob No. 7290886986 Email Id - solveassignmentuniversity@gmail.com

You might also like