0% found this document useful (0 votes)
5 views4 pages

Solved 10 Marks Exam Questions

Uploaded by

keshavjhapranshu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Solved 10 Marks Exam Questions

Uploaded by

keshavjhapranshu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Theory (Detailed Solutions - 10 Marks Each):

1. Define getchar() and write its syntax.

getchar() is a standard library function in C used to read a single character from the standard input

(stdin).

It waits until the user presses a key and then reads that character.

Syntax: int getchar(void);

Example:

```c

#include<stdio.h>

int main() {

char c;

printf("Enter a character: ");

c = getchar();

printf("You entered: %c", c);

return 0;

```

2. Explain the difference between formatted and unformatted input/output functions.

Formatted I/O functions:

- Examples: printf(), scanf()

- Use format specifiers to handle different data types.

- Provide flexibility in displaying or taking input.

Unformatted I/O functions:


- Examples: getchar(), putchar()

- Deal with raw data and do not require format specifiers.

- Suitable for character-level I/O.

3. What is a control string in C programming?

A control string is part of the syntax of functions like printf and scanf that defines the format for

input/output.

Example:

In printf("Hello %d", 5); the control string is "Hello %d" where %d specifies an integer placeholder.

4. Define the if-else ladder control structure.

The if-else ladder is used when multiple conditions need to be checked sequentially.

Syntax:

```c

if (condition1) {

// Code block 1

} else if (condition2) {

// Code block 2

} else {

// Default code block

```

5. What is the purpose of the flags field in control strings?

Flags modify the behavior of formatted output in printf. Common flags:

- '-' : Left-align the output.

- '+' : Display a plus sign for positive numbers.


- '0' : Pad with zeros.

Example: printf("%05d", 42); // Output: 00042

6. Write a flowchart and syntax of the if-else statement.

Flowchart: (Cannot be included in text-only PDF. Please refer to diagrams.)

Syntax:

```c

if (condition) {

// Code for true condition

} else {

// Code for false condition

```

Programming (Detailed Solutions - 10 Marks Each):

1. Write a program to check whether a character is a vowel or consonant.

(Program is already detailed in the previous 7-mark solutions.)

2. Write a program to check triangle validity and type.

Detailed example with comments:

```c

#include<stdio.h>

int main() {

int a, b, c;

printf("Enter three sides of a triangle: ");

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


// Check validity

if (a+b>c && b+c>a && a+c>b) {

printf("Valid Triangle\n");

// Determine type

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

printf("Equilateral\n");

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

printf("Isosceles\n");

else

printf("Scalene\n");

} else {

printf("Invalid Triangle\n");

return 0;

```

[...additional programming answers continue here...]

You might also like