2-Chapter 6 advanced C language
2-Chapter 6 advanced C language
b. Flowchart d. Functions
2. || represents .
a. printf c. scanf
a. True b. False
2. main() in C language serves as a starting point of the program and calls all
other functions.
4. Consider X=3 and Y=2, the operator <= for the expression x<=y will yield the result
Fasle(0) .
6. Consider int x=32 and int y=14 the statement if(x>y) will yield the result
True .
Chapter # 6 (Advance C Language)
Arithmetic operators:
these operators help to perform arithmetic operations. The various arithmetic
operators are given below:
Operators Description
+ Adds two operands
ii. Relational operator: these test the relationship between two entities. They are given below:
Operators Description
== Checks if the value of both entities is same or not. Returns true if it is
!= Not equal to checks if both entities are same or not. If the values are not equal it
returns true
> Checks if the value of left operand is greater than the right operand
< Checks if the value of left operand is lesser than the right operand
>= Checks if the value of left operand is greater than or equal to the value
iii. Logical operators: these are used to check the conditions. They are described below
Operators Description
&& AND operator, returns true if both the operands are non-zero
The functions in programming provide a way of writing a piece of code once and reusing
it again and again by simply calling it wherever needed in the program, without having
the need to rewrite the code again. Using functions make programs robust and efficient.
Answer:
Control statements: these statements help to control or define the flow of the program.
With sequential statements, the programs run in the order it is written, whereas, control
statements test some conditions and then decide the flow of the program. The control
statements are:
1- Looping statements: they allow a block of code to be executed multiple times based
on some conditions. For loop, do-while loop, while loop and nested loop are
examples of looping statements.
2- Conditional statements: they test a certain condition and direct the flow of program
on basis of that. These include IF and IF-ELSE statements.
Answer:
The files are needed because:
1- When the program is terminated, all the data is lost. The files help preserve the data
even when the program is terminated.
2- If all the data is in the file, it can easily be accessed only by writing a few commands
in C
a. Code 1
int main ( )
int number;
printf(“welcome to C”);
return 0;
Answer:
b. Code 2:
int main (
int x=20
int y=22
if(x<z):
return 0;
}
Chapter # 6 (Advance C Language)
{ // Incorrect
placement of '{'
(should be after
'main()' properly)
{ // No errors
here, but must be
corrected after fixing
'if' syntax
printf(“variable x is
less than z”) //
Incorrect double
quotes “”, missing
semicolon ';'
return 0;
} // Extra closing
brace '}' (not needed
here)
Chapter # 6 (Advance C Language)
a. function
int add(int a, int b) {
b. printf
printf("Hello, World!\n");
c. scanf
scanf("%d", &a);
b. Improved Reliability: Since built-in functions are part of the standard library
and have been thoroughly tested, they are generally more reliable than custom
code. This reduces the likelihood of bugs and errors in your program.
c. Code Clarity and Maintainability: Built-in functions provide clear and easy-
to-understand abstractions, making your code more readable and maintainable.
They reduce the need for complex logic and make your code more concise.
Arithmetic Operators:
Relational Operators:
Logical Operators:
Answer:
Answer:
A for loop in C is a control statement that allows you to repeat a block of code a specific
number of times. It is commonly used when the number of iterations is known
beforehand.
10. Write a
program to print
the sum of two
numbers.
Sum = a + b
Code:
#include <stdio.h>
int main()
{ float a, b, sum;
printf("Enter the first number: ");
scanf("%f", &a);
printf("Enter the second number: ");
scanf("%f", &b);
sum = a + b;
printf("The sum of %.2f and %.2f is: %.2f\n", a, b, sum);
return 0; }
11. Write a
program to
calculate the
area of
rectangle.
Area = I * b
#include <stdio.h>
int main()
{ float length, breadth, area;
return 0;