Getting Started with C Programming - Lab Session conducted on August 6, 2025
Download comprehensive guides for environment setup and GitHub integration:
Environment Setup Guide GitHub Integration GuideObjective: Write a C program to print "Hello World"
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}Expected Output:
Key Concepts:
#include <stdio.h> - Preprocessor directive for standard I/Oint main() - Main function where program execution beginsprintf() - Function to print formatted outputreturn 0; - Indicates successful program terminationObjective: Print an address in multiple lines using newline characters
#include <stdio.h>
int main() {
printf("John Doe\n");
printf("123 Main Street\n");
printf("Apartment 4B\n");
printf("New York, NY 10001\n");
printf("United States\n");
return 0;
}Expected Output:
John Doe 123 Main Street Apartment 4B New York, NY 10001 United States
Key Concepts:
\n - Newline escape sequenceprintf() statementsObjective: Prompt user to enter their name and age, then display the information
#include <stdio.h>
int main() {
char name[50];
int age;
printf("Enter your name: ");
scanf("%s", name);
printf("Enter your age: ");
scanf("%d", &age);
printf("\nHello %s!\n", name);
printf("You are %d years old.\n", age);
return 0;
}Sample Input/Output:
Enter your name: Alice Enter your age: 20 Hello Alice! You are 20 years old.
Key Concepts:
char name[50]; - Character array declarationint age; - Integer variable declarationscanf() - Function to read formatted input%s and %d - Format specifiers&age - Address-of operator for scanfObjective: Add two numbers entered by the user and display the result
#include <stdio.h>
int main() {
float num1, num2, sum;
printf("Enter first number: ");
scanf("%f", &num1);
printf("Enter second number: ");
scanf("%f", &num2);
sum = num1 + num2;
printf("\nSum of %.2f and %.2f is %.2f\n",
num1, num2, sum);
return 0;
}Sample Input/Output:
Enter first number: 15.5 Enter second number: 10.3 Sum of 15.50 and 10.30 is 25.80
Key Concepts:
float - Floating-point data type%f - Format specifier for float%.2f - Format specifier with precision# Compile a C program gcc program_name.c -o program_name # Run the compiled program (Windows) program_name.exe # Run the compiled program (Linux/Mac) ./program_name # Example: Compile and run hello_world.c gcc hello_world.c -o hello_world ./hello_world
#include <stdio.h>Upon completion of this lab, students will be able to: