Answers C
Answers C
3.Define operators.
These statements are used to execute particular set of instruction for based on certain
condition.
Looping statement are used to execute a group of instruction repeatedly at till some
condition is satisfied.
This condition is used to transfer the control to other statement without checking any
condition. Example : goto, break
7. What is Ternary operators or Conditional operators?
Ternary operators is a conditional operator with symbols ? and :
Syntax: variable = exp1 ? exp2 : exp3
If the exp1 is true variable takes value of exp2. If the exp2 is false, variable takes the value of exp3.
In the while loop the condition is first executed. If the condition is true then it executes the body of
the loop. When the condition is false it comes of the loop. In the do…while loop first the statement is
executed and then the condition is checked. The do…while loop will execute at least one time even
though the condition is false at the very first time.
9. Write the limitations of getchar( ) and sacnf( ) functions for reading strings
getchar( )
To read a single character from stdin, then getchar() is the appropriate.
scanf( )
scanf( ) allows to read more than just a single character at a time.
Part – B(1*15=15)
6.(i)Describe the structure of a C program with an example (8)
The structure of a C program can be mainly divided into six parts, each having its purpose. It
makes the program easy to read, easy to modify, easy to document, and makes it consistent in
format.
All header files are included in this section which contains different functions
from the libraries. A copy of these header files is inserted into your code before
Link
compilation.
Includes all user-defined functions (functions the user provides). They can contain
Subprograms the inbuilt functions and the function definitions declared in the Global
Declaration section. These are called in the main() function.
Example: Write a program to calculate our age.
Algorithm
You've to subtract the current year from your birth year and get your age.
Code:
/** //Documentation
* file: age.c
* author: you
return 0;
}
(ii)Write a c program to find the given number is odd or even using switch statement.
/**
* C program to check Even or Odd number using switch case
*/
#include <stdio.h>
int main()
{
int num;
switch(num % 2)
{
/* If n%2 == 0 */
case 0:
printf("Number is Even");
break;
/* Else if n%2 == 1 */
case 1:
printf("Number is Odd");
break;
}
return 0;
}
Output: