C Programming Basics for Beginners - Part II

 

7. Operators in C

#include <stdio.h>

int main() {
    int a = 5, b = 10;
    printf("Sum: %d\n", a + b);
    printf("Is a > b? %d\n", a > b);  // 0 (false)
    return 0;
}

8. Conditional Statements (if-else, switch)

 if (condition) {
    // Code to execute if condition is true
} else {
    // Code to execute if condition is false
}

#include <stdio.h>

int main() {
    int num;
    printf("Enter a number: ");
    scanf("%d", &num);

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

    return 0;
}

9. Loops in C (for, while, do-while)

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

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

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


10. Functions in C

Functions are used to organize code into reusable blocks.

 return_type function_name(parameters) {
    // Code
    return value;
}

#include <stdio.h>

void greet() {
    printf("Hello, Welcome to C Programming!\n");
}

int main() {
    greet();  // Function Call
    return 0;
}

11. Arrays in C

 Array is a collection of elements of the same data type.

 #include <stdio.h>

int main() {
    int numbers[] = {10, 20, 30, 40, 50};

    for (int i = 0; i < 5; i++) {
        printf("%d ", numbers[i]);
    }

    return 0;
}


C Programming Basics for Beginners - Part II C Programming Basics for Beginners - Part II Reviewed by Skill Training on February 25, 2025 Rating: 5
Powered by Blogger.