Q.1
14 MarksAlgorithm to Find Factorial of a Number
- Step 1: Start.
- Step 2: Declare variables
n,i, and initializefact = 1. - Step 3: Read the integer value
nfrom the user. - Step 4: If , display "Factorial of negative numbers does not exist" and go to Step 8.
- Step 5: Set .
- Step 6: Repeat while :
- Step 7: Display the calculated
fact. - Step 8: Stop.
Flowchart to Check for a Prime Number
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
([ START ])
|
v
[/ Input N /]
|
v
< Is N <= 1? > ----- YES ----> [/ Print "Not Prime" /] ---> ([ STOP ])
|
NO
v
[ i = 2 ]
|
+------------> v
| < Is i * i <= N? > --- NO ----> [/ Print "Prime" /] -------> ([ STOP ])
| |
| YES
| v
| < Does i divide N? >
| < (N % i == 0) >
| |
| YES --------------------> [/ Print "Not Prime" /] ---> ([ STOP ])
| |
| NO
| v
+--------- [ i = i + 1 ]- Optimization: Testing up to () reduces time complexity from to .
Data Types in C
Data types specify the type, size, and operations associated with variables. C provides four major categories:
DATA TYPES IN C
|
+-----------------------+-----------------------+
| | |
PRIMARY / BASIC DERIVED USER-DEFINED
(int, char, float, void) (Arrays, Pointers) (struct, union, enum)1. Primary (Fundamental) Data Types:
| Data Type | Description | Size (32/64-bit) | Format Specifier | Typical Range |
|---|---|---|---|---|
char | Single ASCII character | 1 byte | %c | to |
unsigned char | Unsigned character | 1 byte | %c / %u | to |
short int | Short integer | 2 bytes | %hd | to |
int | Standard integer | 4 bytes | %d | to |
unsigned int | Unsigned integer | 4 bytes | %u | to |
float | Single-precision floating point | 4 bytes | %f | to ( decimals) |
double | Double-precision floating point | 8 bytes | %lf | to ( decimals) |
void | Empty data type (no value) | 0 bytes | — | Function returns, generic pointers (void*) |
2. Derived Data Types:
- Arrays: Homogeneous collection of consecutive memory elements (e.g.,
int arr[10];). - Pointers: Variables storing memory addresses of other variables (e.g.,
int *ptr;). - Functions: Modular blocks executing reusable operations.
3. User-Defined Data Types:
struct: Heterogeneous grouping of distinct variables under one name.union: Grouping sharing the same memory location.enum: User-defined list of named integer constants.typedef: Alias creator for existing types.