0% found this document useful (0 votes)
15 views9 pages

QBS

The document contains various C programming concepts including examples of programs to print even numbers, check for vowels, and find the largest of three numbers. It also explains operators such as relational, bitwise, arithmetic, and logical operators, along with variable declaration rules and formatted input/output. Additionally, it defines tokens and identifiers, and provides algorithms and flowcharts for problem-solving.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views9 pages

QBS

The document contains various C programming concepts including examples of programs to print even numbers, check for vowels, and find the largest of three numbers. It also explains operators such as relational, bitwise, arithmetic, and logical operators, along with variable declaration rules and formatted input/output. Additionally, it defines tokens and identifiers, and provides algorithms and flowcharts for problem-solving.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Q write a program to print even no between 1 to 100

#include <stdio.h>

int main()

printf("Even numbers between 1 and 100:\n");

for (int i =2; i <= 100; i += 2)

printf("%d ", i); // Print the current even number

return 0;

Q list relational operator

Operator Operator Name


== Equal to
!= Not Equal to
< Less than
> Greater than
<= Less than Equal to
=> Greater Than Equal to

Q List bitwise Operator

 Bitwise AND (&)

 Bitwise OR (|)

 Bitwise XOR (^).

 Bitwise NOT (~)

 Left Shift (<<)

 Right Shift (>>)


Q write a program to check whether a character entered is a vowel or not

#include <stdio.h>

int main()

char ch;

printf("Enter a character: ");

scanf("%c", &ch);

if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||

ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')

printf("%c is a vowel.\n", ch);

else

printf("%c is not a vowel.\n", ch);

return 0;

Q Write a programme to find largest Of Three no using nested if else

#include <stdio.h>

int main() {

int a, b, c;

printf("Enter three numbers: ");

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

if (a >= b) {

if (a >= c) {

printf("%d is the largest number.\n", a);

} else {

printf("%d is the largest number.\n", c);

} else {
if (b >= c) {

printf("%d is the largest number.\n", b);

} else {

printf("%d is the largest number.\n", c);

return 0;

Q Diff if and Switch Statement

Q Write and Algorithm for largest amount 3 numbers

 Start

 Input three numbers: a, b, and c.

 If a is greater than or equal to b and a is greater than or equal to c, then a is the largest.

 Else if b is greater than or equal to a and b is greater than or equal to c, then b is the largest.

 Else, c is the largest.

 print the largest number.

 End
FLOW CHART

Q Define token and Identifiers

Token

Token is a The smallest unit of a programming language.in c token Includes Keyword, identifiers,
constants , operators , string

Identifiers

An identifier is a name used to identify a variable, function, array, or any other user-defined item in a
program. Identifiers are used to represent memory locations where data is stored or to call specific
functions.
Q keyword in c

Int, char, float, double, if , long, break , continue

Q what is variable enleast rule of variable declaration

Variable

Variable ia a container that holds the value

A variable is a way to store information that you can use and change later in your program.

Rules OF Variable Declaration

 A variable name must only contain alphabets, digits, and underscore.

 A variable name must start with an alphabet or an underscore only. It cannot start with a digit.

 No white space is allowed within the variable name.

 A variable name must not be any reserved word or keyword.

Q Explain Increment Decrement Operator with example

INCREMENNT operator

- Increment Operator is used to increase the value one by one


- It works on integer or floating-point variables.
- It is a unary operator, meaning it operates on a single operand
- It is commonly used in loops (e.g., for or while) to iterate.
- The increment operator can be used with variables, expressions, or arrays.
- It increases the value by exactly 1.
- The prefix increment (++a) increments the value first and then uses it in an expression.
- The postfix increment (a++) uses the current value first, then increments the variable.
- Increment Operator represent (++) symbol
- For example
#include <stdio.h>
int main() {
int a = 5;
printf("Postfix Increment: %d\n", a++);
return 0;
}

DECREMENT operator

- The decrement operator is used to subtract 1 from a variable's value.


- It can be applied to integer, floating-point, or pointer variables.
- It is a unary operator, operating on only one operand.
- It is frequently used in loops for counting backward or reverse iteration.
- The prefix decrement (--a) decreases the value first and then uses it in the expression.
- The postfix decrement (a--) uses the current value first, then decreases the value by 1.
- it can be used on types such as char, int, float, and double.
- Decrement operator represent(--) symbol
- For example
#include <stdio.h>
int main() {
int a = 5;
// Prefix decrement
printf("Prefix Decrement: %d\n", --a);
// Postfix decrement
printf("Postfix Decrement: %d\n", a--);
return 0;
}

Q Explain Formatted input and Formatted Output In c

Formatted Input in C

Formatted input in C refers to reading data from the user in a specific format using the scanf()
function. This allows you to control the type, number, and format of the input you want to receive.

scanf() Function:

 The scanf() function is used to read input from the user.

 It takes a format specifier to define the type and structure of the input.

Format Specifiers in scanf():

 %d: Reads an integer.

 %f: Reads a floating-point number.

 %c: Reads a character.

 %s: Reads a string

Example

#include <stdio.h>

int main() {

int age;

printf("Enter your age: ");

scanf("%d", &age);

printf("Age: %d, age);

return 0;

}
Formatted Output in C

Formatted output in C refers to displaying data in a specific format using the printf() function. This
allows you to control how the output is displayed.

printf() Function:

 The printf() function is used to display formatted output on the screen.

 It also uses format specifiers to control how the data should be printed.

Format Specifiers in printf():

 %d: Prints an integer.

 %f: Prints a floating-point number.

 %c: Prints a character.

 %s: Prints a string

Example

#include <stdio.h>

int main() {

int age = 25;

float salary = 12345.6789;

char grade = 'A';

printf("Age: %d\n", age);

printf("Salary: %.2f\n", salary);

printf("Grade: %c\n", grade);

return 0;

Q Explain Arithmetic and Logical Operator

Arithmetic Operators in C

Arithmetic operators are used to perform mathematical calculations in C, such as addition,


subtraction, multiplication, and division. These operators work on numerical data types like int, float,
and double

Arithmetic Operators Are :

1. Addition (+):

o Adds two operands.

o Example: a + b adds a and b.


2. Subtraction (-):

o Subtracts the right operand from the left operand.

o Example: a - b subtracts b from a.

3. Multiplication (*):

o Multiplies two operands.

o Example: a * b multiplies a and b.

4. Division (/):

o Divides the left operand by the right operand.

o Example: a / b divides a by b.

o Note: In integer division, the result is truncated (i.e., the decimal part is discarded).

5. Modulus (%):

o Returns the remainder of the division of the left operand by the right operand.

o Example: a % b gives the remainder when a is divided by b.

Example of Arithmetic Operators:

#include <stdio.h>

int main() {

int a = 10, b = 5;

printf("Addition: %d\n", a + b);

printf("Subtraction: %d\n", a - b);

printf("Multiplication: %d\n", a * b);

printf("Division: %d\n", a / b);

printf("Modulus: %d\n", a % b);

return 0;

Logical Operators in C

Logical operators are used to perform logical operations on expressions that evaluate to true or false.
They are typically used to combine multiple conditions in control flow statements (like if, while, etc.).

Logical Operators are:

1. Logical AND (&&):

o Returns true (1) if both operands are true.

o Example: a && b returns true only if both a and b are true.


2. Logical OR (||):

o Returns true (1) if at least one of the operands is true.

o Example: a || b returns true if either a or b is true.

3. Logical NOT (!):

o Reverses the logical state of its operand.

o If the operand is true, it returns false; if the operand is false, it returns true.

o Example: !a returns true if a is false, and false if a is true.

Example of Logical Operators:

#include <stdio.h>

int main() {

int a = 1, b = 0;

printf("Logical AND: %d\n", a && b);

printf("Logical OR: %d\n", a || b);

printf("Logical NOT: %d\n", !a);

return 0;

You might also like