University : SIGMA UNIVERSITY
Name : MAHESHKUMAR CHAUHAN
Mobile No : 97126 12568
Designation : Teaching Assistant
Name of Program : Bachelor of Technology (B. Tech)
Course Code : 2BC001
Course Title : Computer Programming
Course : : Bachelor of Technology in Civil Engineering/Mechanical Engineering/Chemical Engineering
Semester : : 2 - Batch-1
Batch-1 : Friday - Batch-1
Friday : 10:30 to 12:20
Download : 📄 Open Computer Programming PDF
📘 Practical C Programming Lab
02 hrs
1. Input & Output Operations

Learn printf(), scanf() and basic user interaction.

02 hrs
2. Operators & Expressions

Arithmetic, relational, logical operators.

02 hrs
3. Conditional Statements

if, else, switch decision making.

06 hrs
4. Loops

for, while, do-while loops practice.

04 hrs
5. Arrays

1D and 2D arrays handling.

04 hrs
6. Strings

String operations and functions.

04 hrs
7. Functions

User-defined functions and modular coding.

02 hrs
8. Structures & Unions

Complex data structures.

02 hrs
9. Dynamic Memory Allocation

malloc(), calloc(), free().

02 hrs
10. File Handling

Reading & writing files using C.

1. Input / Output

#include <stdio.h>
int main(){
 int a,b;
 printf("Enter two numbers: ");
 scanf("%d %d",&a,&b);
 printf("Sum = %d",a+b);
}
Input: 5 3
Output: Sum = 8

2. Operators


#include 

int main() {
    int a = 10, b = 3;

    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;
}
Addition = 13
Subtraction = 7
Multiplication = 30
Division = 3
Modulus = 1

3. Conditionals


#include 

int main() {
    int num;

    printf("Enter number: ");
    scanf("%d", &num);

    if (num % 2 == 0)
        printf("Even\n");
    else
        printf("Odd\n");

    return 0;
}


Enter number: 4
Output: Even

4. Loops

#include 

int main() {
    int i;

    printf("Numbers from 1 to 5:\n");

    for(i = 1; i <= 5; i++) {
        printf("%d ", i);
    }

    return 0;
}

Numbers from 1 to 5:
1 2 3 4 5

5. Arrays


#include 

int main() {
    int arr[5], i, sum = 0;

    printf("Enter 5 numbers:\n");

    for(i = 0; i < 5; i++) {
        scanf("%d", &arr[i]);
        sum += arr[i];
    }

    printf("Sum = %d\n", sum);

    return 0;
}

Enter 5 numbers:
1 2 3 4 5
Sum = 15

6. Strings



#include 
#include 

int main() {
    char str[50];

    printf("Enter string: ");
    scanf("%s", str);

    printf("Length = %lu\n", strlen(str));

    return 0;
}


Enter string: Hello
Length = 5

7. Functions


#include 

int add(int a, int b) {
    return a + b;
}

int main() {
    int result;

    result = add(4, 6);

    printf("Sum = %d\n", result);

    return 0;
}

Sum = 10

8. Structures


#include 

struct Student {
    int id;
    char name[20];
};

int main() {
    struct Student s;

    printf("Enter ID and Name: ");
    scanf("%d %s", &s.id, s.name);

    printf("ID: %d\nName: %s\n", s.id, s.name);

    return 0;
}

Enter ID and Name: 1 John
ID: 1
Name: John

9. Dynamic Memory


#include 
#include 

int main() {
    int *ptr, i;

    ptr = (int*) malloc(3 * sizeof(int));

    printf("Enter 3 numbers:\n");

    for(i = 0; i < 3; i++) {
        scanf("%d", &ptr[i]);
    }

    printf("Numbers are:\n");

    for(i = 0; i < 3; i++) {
        printf("%d ", ptr[i]);
    }

    free(ptr);

    return 0;
}

Enter 3 numbers:
5 6 7
Numbers are:
5 6 7

10. File Handling


#include 

int main() {
    FILE *fp;
    char data[50];

    fp = fopen("test.txt", "w");
    fprintf(fp, "Hello File");
    fclose(fp);

    fp = fopen("test.txt", "r");
    fscanf(fp, "%s", data);
    fclose(fp);

    printf("Data from file: %s\n", data);

    return 0;
}

Data from file: Hello