Sunday, 18 January 2026

Programming for Problem Solving-Control Structures

 1. Check Positive or Negative (if)

#include <stdio.h>

#include<conio.h>

int main() {

    int n = 5;

    if (n > 0)

        printf("Positive number");

    return 0;

   getch();

}


Output

Positive number


2. Check Even or Odd (if–else)

#include <stdio.h>

#include<conio.h>

int main() {

    int n = 4;

    if (n % 2 == 0)

        printf("Even number");

    else

        printf("Odd number");

    return 0;

    getch();

}


Output

Even number


3. Find Largest of Two Numbers (if–else)

#include <stdio.h>

#include<conio.h>

int main() {

    int a = 10, b = 20;

    if (a > b)

        printf("A is greater");

    else

        printf("B is greater");

    return 0;

    getch();

}

Output

B is greater


4. Check Voting Eligibility (if–else)

#include <stdio.h>

#include<conio.h>

int main() {

    int age = 18;

    if (age >= 18)

        printf("Eligible to vote");

    else

        printf("Not eligible");

    return 0;

    getch();

}


Output

Eligible to vote


5. Check Leap Year (if–else)

#include <stdio.h>

#include<conio.h>

int main() {

    int year = 2024;

    if (year % 4 == 0)

        printf("Leap year");

    else

        printf("Not a leap year");

    return 0;

    getch();

}


Output

Leap year


6. Largest of Three Numbers (else–if ladder)

#include <stdio.h>

#include<conio.h>

int main() {

    int a = 10, b = 30, c = 20;

    if (a > b && a > c)

        printf("A is largest");

    else if (b > c)

        printf("B is largest");

    else

        printf("C is largest");

    return 0;

    getch();

}


Output

B is largest


7. Grade System (else–if ladder)

#include <stdio.h>

#include<conio.h>

int main() {

    int marks = 85;

    if (marks >= 90)

        printf("Grade A");

    else if (marks >= 75)

        printf("Grade B");

    else if (marks >= 50)

        printf("Grade C");

    else

        printf("Fail");

    return 0;

    getch();

}


Output

Grade B


8. Simple Calculator (switch)

#include <stdio.h>

#include<conio.h>

int main() {

    int a = 10, b = 5;

    char op = '+';

    switch (op) {

        case '+': printf("Sum = %d", a + b); break;

        case '-': printf("Difference = %d", a - b); break;

        case '*': printf("Product = %d", a * b); break;

        case '/': printf("Quotient = %d", a / b); break;

    }

    return 0;

    getch();

}

Output

Sum = 15


9. Print Numbers 1 to 5 (for loop)

#include <stdio.h>

#include<conio.h>

int main() {

    int i;

    for (i = 1; i <= 5; i++)

        printf("%d ", i);

    return 0;

    getch();

}

Output

1 2 3 4 5


10. Sum of First 5 Numbers (for loop)

#include <stdio.h>

#include<conio.h>

int main() {

    int i, sum = 0;

    for (i = 1; i <= 5; i++)

        sum += i;

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

    return 0;

    getch();

}

Output

Sum = 15


11. Print Numbers Using while Loop

#include <stdio.h>

#include<conio.h>

int main() {

    int i = 1;

    while (i <= 5) {

        printf("%d ", i);

        i++;

    }

    return 0;

    getch();

}

Output

1 2 3 4 5


12. Reverse a Number (while loop)

#include <stdio.h>

#include<conio.h>

int main() {

    int n = 123, rev = 0;

    while (n != 0) {

        rev = rev * 10 + n % 10;

        n /= 10;

    }

    printf("Reverse = %d", rev);

    return 0;

    getch();

}

Output

Reverse = 321


13. Print Numbers Using do–while Loop

#include <stdio.h>

#include<conio.h>

int main() {

    int i = 1;

    do {

        printf("%d ", i);

        i++;

    } while (i <= 5);

    return 0;

}

Output

1 2 3 4 5


14. Use of break Statement

#include <stdio.h>

#include<conio.h>

int main() {

    int i;

    for (i = 1; i <= 5; i++) {

        if (i == 3)

            break;

        printf("%d ", i);

    }

    return 0;

    getch();

}

Output

1 2


15. Use of continue Statement

#include <stdio.h>

#include<conio.h>

int main() {

    int i;

    for (i = 1; i <= 5; i++) {

        if (i == 3)

            continue;

        printf("%d ", i);

    }

    return 0;

    getch();

}

Output

1 2 4 5

Saturday, 17 January 2026

Programming for Problem Solving-Basics of C Programming

Programming for Problem Solving-Basics of C Programming

 1. Simple C Program (Basic Structure)

#include <stdio.h>

#include<conio.h>

int main() 

{

    printf("Welcome to Information Technology Dept.);

    return 0;

    getch();

}

Output

Welcome to Information Technology Dept.


2. Program Using return 0

#include <stdio.h>

#include<conio.h>

int main() 

{

    printf("Program ends with return");

    return 0;

    getch();

}


Output

Program ends with return


3. Print Name

#include <stdio.h>

#include<conio.h>

int main()

{

    printf("My name is James");

    return 0;

    getch();

}

Output

My name is James


4. Print Multiple Lines

#include <stdio.h>

#include<conio.h>

int main() {

    printf("C Programming\nBasics");

    return 0;

    getch();

}

Output

C Programming

Basics


5. Program with Comments

#include <stdio.h>

#include<conio.h>

int main() {

    // This is a comment

    printf("Comments example");

    return 0;

    getch();

}

Output

Comments example


6. Integer Variable

#include <stdio.h>

#include<conio.h>

int main() {

    int a = 10;

    printf("%d", a);

    return 0;

    getch();

}

Output

10


7. Float Variable

#include <stdio.h>

#include<conio.h>

int main() {

    float x = 3.5;

    printf("%f", x);

    return 0;

    getch();

}

Output

3.500000


8. Character Variable

#include <stdio.h>

#include<conio.h>

int main() {

    char ch = 'A';

    printf("%c", ch);

    return 0;

    getch();

}

Output

A


9. Multiple Variables

#include <stdio.h>

#include<conio.h>

int main() {

    int a = 5, b = 10;

    printf("%d %d", a, b);

    return 0;

    getch();

}

Output

5 10


10. User Input Integer

#include <stdio.h>

#include<conio.h>

int main()

{

    int n;

    scanf("%d", &n);

    printf("%d", n);

    return 0;

    getch();

}

Output

5


11. User Input Float

#include <stdio.h>

#include<conio.h>

int main() 

{

    float f;

    scanf("%f", &f);

    printf("%f", f);

    return 0;

    getch();

}


Output

2.500000


12. Size of Data Types

#include <stdio.h>

#include<conio.h>

int main()

{

    printf("%d", sizeof(int));

    return 0;

    getch();

}

Output

4


13. Constant Variable

#include <stdio.h>

#include<conio.h>

int main() 

{

    const int a = 10;

    printf("%d", a);

    return 0;

    getch();

}

Output

10


14. Sum Using Variables

#include <stdio.h>

#include<conio.h>

int main() 

{

    int a = 3, b = 7;

    printf("%d", a + b);

    return 0;

    getch();

}

Output

10


15. Swap Using Temporary Variable

#include <stdio.h>

#include<conio.h>

int main() 

{

    int a = 5, b = 10, t;

    t = a;

    a = b;

    b = t;

    printf("%d %d", a, b);

    return 0;

    getch();

}

Output

10 5


16. Arithmetic Operators

#include <stdio.h>

#include<conio.h>

int main()

{

    int a = 10, b = 5;

    printf("%d", a + b);

    return 0;

    getch();

}

Output

15


17. Subtraction Operator

#include <stdio.h>

#include<conio.h>

int main()

{

    int a = 10, b = 4;

    printf("%d", a - b);

    return 0;

    getch();

}

Output

6


18. Multiplication Operator

#include <stdio.h>

#include<conio.h>

int main() {

    int a = 3, b = 4;

    printf("%d", a * b);

    return 0;

    getch();

}

Output

12


19. Division Operator

#include <stdio.h>

#include<conio.h>

int main()

{

    int a = 10, b = 2;

    printf("%d", a / b);

    return 0;

    getch();

}

Output

5


20. Modulus Operator

#include <stdio.h>

#include<conio.h>

int main()

{

    int a = 10, b = 3;

    printf("%d", a % b);

    return 0;

    getch();

}

Output

1


21. Relational Operator

#include <stdio.h>

#include<conio.h>

int main() 

{

    int a = 5, b = 5;

    printf("%d", a == b);

    return 0;

    getch();

}

Output

1


22. Logical AND

#include <stdio.h>

#include<conio.h>

int main() 

{

    int a = 1, b = 1;

    printf("%d", a && b);

    return 0;

    getch();

}

Output

1


23. Logical OR

#include <stdio.h>

#include<conio.h>

int main() 

{

    int a = 0, b = 1;

    printf("%d", a || b);

    return 0;

    getch();

}

Output

1


24. Increment Operator

#include <stdio.h>

#include<conio.h>

int main()

{

    int a = 5;

    a++;

    printf("%d", a);

    return 0;

    getch();

}

Output

6


25. Assignment Operator

#include <stdio.h>

#include<conio.h>

int main() 

{

    int a = 10;

    a += 5;

    printf("%d", a);

    return 0;

    getch();

}

Output

15