Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
C Programming Assignment (1)
Q1 – Variable Declaration & Display
Objective:
Practice declaring and displaying variables of different data
types.
Concepts Covered:
Variables, Data Types, printf(), Escape Sequences.
Description:
This program defines variables of types int, float, double, and
char. It assigns sample values and prints them using formatted
output. Each variable is printed on a new line using \n for
better readability.
Expected Output:
Integer = 10
Float = 3.14
Double = 12.345600
Character = A
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q2 – Memory Address and Value
Objective:
Understand how variables are stored in memory and how to
access their addresses.
Concepts Covered:
& operator, %p format specifier, sizeof().
Description:
The program declares variables of different types (int, float,
and char) and prints both their values and memory addresses.
It also prints their sizes in bytes to show memory allocation
differences.
Expected Output:
Value of x = 10
Address of x = 0x7ffee2a4b1ac
Size of int = 4 bytes
(Note: Addresses may vary each time you run the
program.)
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q3 – Constants and Geometry
Objective:
Apply the use of constants in mathematical calculations.
Concepts Covered:
Constants (const), Arithmetic Operators, scanf(), Escape
Sequences.
Description:
This program defines a constant PI and asks the user for
a circle’s radius. It then calculates and displays the area
and circumference using the formulas: Area = πr² and
Circumference = 2πr.
Expected Output:
=== Circle Calculation ===
Enter radius: 5
Area = 78.50
Circumference = 31.40
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q4 – Type Casting and Arithmetic
Objective:
Understand type conversion between integer and
floating-point values.
Concepts Covered:
Type Casting, Arithmetic Operators, Input/Output.
Description:
This program reads one integer and one float. It
demonstrates explicit casting by converting the float to
an integer before addition, and performs multiplication
without conversion.
Expected Output:
Enter integer: 4
Enter float: 2.5
Sum (int + (int)float) = 6
Product (int * float) = 10.00
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q5 – Variable Swap Without Temp
Objective:
Swap two variables using arithmetic operators only.
Concepts Covered:
Arithmetic Operators, Variable Manipulation.
Description:
This program reads two integer values, swaps them
without using a third variable, and prints the result
before and after swapping.
Expected Output:
Before swap: a = 5, b = 10
After swap: a = 10, b = 5
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q6 – Operators Practice
Objective:
Reinforce arithmetic, increment/decrement, and
modulus concepts.
Concepts Covered:
Arithmetic Operators, Increment/Decrement, Operator
Precedence.
Description:
The program reads two integers x and y, performs
various operations, and prints the results with
descriptive messages.
Expected Output:
Enter x and y: 6 3
(x + y) * (x - y) = 27
x++ + ++y = 10
(x % y) + (x / y) = 3
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q7 – Escape Sequence Table
Objective:
Use escape sequences to format tabular output.
Concepts Covered:
\t, \n, Table Formatting.
Description:
This program displays a simple table of names, ages, and
grades using escape sequences for alignment.
Expected Output:
Name Age Grade
--------------------------
Ali 20 A
Mona 21 B
Omar 19 A+
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q8 – Data Type Size Table
Objective:
Show how much memory each data type consumes.
Concepts Covered:
sizeof() operator, Data Types, Formatting.
Description:
This program prints the memory size (in bytes) of various data
types in a clean, tabular format.
Expected Output:
=== Data Type Sizes ===
int -> 4 bytes
float -> 4 bytes
double -> 8 bytes
char -> 1 byte
long -> 8 bytes
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q9 – Address Difference Challenge
Objective:
Observe memory address spacing between consecutive
variables.
Concepts Covered:
Pointers, Memory Addressing, Address Arithmetic.
Description:
The program declares three int variables in sequence,
prints their memory addresses, and computes the
difference between them to show spacing in memory.
Expected Output:
Address of a = 0x7ffee2a4b190
Address of b = 0x7ffee2a4b194
Address of c = 0x7ffee2a4b198
Difference between a and b = 4 bytes
Difference between b and c = 4 bytes
Faculty of Engineering, Alamein International University
Structured Programming Using C
Dr. Ali Gaber
Q10 – Mixed Concepts (Final Challenge )
Objective:
Combine all learned concepts into one complete program.
Concepts Covered:
Variables, Type Casting, Arithmetic, Constants, Escape
Sequences.
Description:
This integrated program defines several variables of different
data types, performs arithmetic and assignment operations,
and prints formatted results demonstrating all covered topics.
Expected Output:
=== Mixed Concepts Program ===
Variable Values:
a = 15
b = 3.50
c = 12.345
ch = Z
Results:
Sum (a + (int)b) = 13
Product (a * b) = 52.50
Average = 10.62