American Film Academy

Equipping filmmakers of tomorrow, today

AFA IT 101

Modules

Courses

Programming with C

Table of Contents

Lecture 4 June

Lecture 28 May

Notes

Introduction to C Programming – Class Notes

Lesson Overview:

In this session, we covered the fundamentals of C programming, focusing on writing basic programs using:

  • Variables
  • Input/output functions (printfscanf)
  • Format specifiers like %d
  • Conditional statements (ifelseelse if)

1. Variables in C

  • variable is a container for storing data values.
  • In C, you must declare the variable type before using it.
int age;       // Declaration
age = 25;      // Assignment
int score = 90; // Declaration + Assignment

2. Output with printf()

  • Used to display text or values on the screen.

Syntax:

printf("Text to display");

int age = 18;
printf("Age: %d", age);  // %d is replaced by the value of age

3. Input with scanf()

  • Used to take user input from the console.
scanf("%d", &age);  // Reads an integer into variable 'age'

4. Conditional Statements (ifelse ifelse)

Used to perform different actions based on different conditions.

if (condition) {
   // code if true
} else if (another condition) {
   // code if first is false but this is true
} else {
   // code if all conditions are false
}

Assignment

Instructions:

You are required to write a C program that performs the following tasks:

  1. Prompt the user to enter the number of students.
  2. For each student, ask for their scores (you may assume one score per student or modify to include multiple subjects as per your preference).
  3. Calculate the total and average score.
  4. Assign a grade based on the average using if-else statements.
  5. Display the results for each student:
    • Student number or name (if applicable)
    • Score
    • Average
    • Grade

Submit your code in the ‘submit code’ block below.

Submit Assignment