C Programs Using Multiple Concepts Practice Questions with Solutions

Introduction

In real C programming, you rarely use only one concept at a time. A single program may use variables, input/output, operators, conditions, loops, functions, arrays, strings, pointers, structures, or file handling together. This chapter combines concepts from previous chapters through practical programs. The examples start with simple combinations and gradually move toward larger programs so you can learn how individual C concepts work together. C Programs Using Multiple Concepts practice questions with solutions to help you understand the concepts.

Q1. Find the Largest of Three Numbers Using a Function

Problem Statement

Write a C program that accepts three numbers and uses a function to find the largest number.

C Program

#include <stdio.h>

int findLargest(int a, int b, int c)
{
    int largest;

    largest = a;

    if (b > largest)
    {
        largest = b;
    }

    if (c > largest)
    {
        largest = c;
    }

    return largest;
}

int main()
{
    int a, b, c;
    int largest;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    largest = findLargest(a, b, c);

    printf("Largest = %d", largest);

    return 0;
}

Sample Output

Enter three numbers: 25 48 32
Largest = 48

Explanation

This program combines:

  • Variables
  • scanf()
  • printf()
  • Function
  • Function arguments
  • if
  • Return value

The function:

int findLargest(int a, int b, int c)

receives three numbers and returns the largest one.

Concepts Covered

  • Functions
  • Function arguments
  • if
  • Input/output
  • Return values

Q2. Calculate the Sum and Average of Array Elements

Problem Statement

Write a C program that accepts five numbers into an array and calculates their sum and average.

C Program

#include <stdio.h>

int main()
{
    int numbers[5];
    int sum = 0;
    float average;
    int i;

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

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

    for (i = 0; i < 5; i++)
    {
        sum = sum + numbers[i];
    }

    average = sum / 5.0;

    printf("Sum = %d\n", sum);
    printf("Average = %.2f", average);

    return 0;
}

Sample Output

Enter 5 numbers:
10
20
30
40
50
Sum = 150
Average = 30.00

Explanation

The array stores five values:

int numbers[5];

The first for loop accepts the values.

The second loop calculates the sum:

sum = sum + numbers[i];

Finally:

average = sum / 5.0;

calculates the average.

Concepts Covered

  • Arrays
  • for loop
  • Variables
  • Input/output
  • Arithmetic operators

Q3. Count Even and Odd Numbers in an Array

Problem Statement

Write a C program that accepts 10 integers into an array and counts how many are even and how many are odd.

C Program

#include <stdio.h>

int main()
{
    int numbers[10];
    int even = 0;
    int odd = 0;
    int i;

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

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

    for (i = 0; i < 10; i++)
    {
        if (numbers[i] % 2 == 0)
        {
            even++;
        }
        else
        {
            odd++;
        }
    }

    printf("Even numbers = %d\n", even);
    printf("Odd numbers = %d", odd);

    return 0;
}

Sample Output

Enter 10 numbers:
12 7 8 15 20 3 14 9 6 11
Even numbers = 5
Odd numbers = 5

Explanation

The program uses the modulus operator:

numbers[i] % 2

If the remainder is 0, the number is even.

Otherwise, it is odd.

The counters:

even++;
odd++;

keep track of both groups.

Concepts Covered

  • Arrays
  • Loops
  • if-else
  • Modulus operator
  • Increment operator

Q4. Reverse a String Using a Function

Problem Statement

Write a C program that accepts a string and reverses it using a separate function.

C Program

#include <stdio.h>
#include <string.h>

void reverseString(char str[])
{
    int start = 0;
    int end;
    char temp;

    end = strlen(str) - 1;

    while (start < end)
    {
        temp = str[start];
        str[start] = str[end];
        str[end] = temp;

        start++;
        end--;
    }
}

int main()
{
    char text[100];

    printf("Enter a string: ");
    fgets(text, sizeof(text), stdin);

    text[strcspn(text, "\n")] = '\0';

    reverseString(text);

    printf("Reversed string = %s", text);

    return 0;
}

Sample Output

Enter a string: programming
Reversed string = gnimmargorp

Explanation

The program combines:

  • Character arrays
  • Strings
  • Functions
  • while loop
  • strlen()
  • fgets()

The function receives the string:

void reverseString(char str[])

Two positions are used:

start → beginning of string
end   → end of string

The characters are exchanged until the two positions meet.

Concepts Covered

  • Strings
  • Character arrays
  • Functions
  • while loop
  • String functions

Q5. Find the Largest Element Using a Function and Array

Problem Statement

Write a C program that accepts numbers into an array and uses a function to find the largest element.

C Program

#include <stdio.h>

int findLargest(int numbers[], int size)
{
    int largest = numbers[0];
    int i;

    for (i = 1; i < size; i++)
    {
        if (numbers[i] > largest)
        {
            largest = numbers[i];
        }
    }

    return largest;
}

int main()
{
    int numbers[5];
    int largest;
    int i;

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

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

    largest = findLargest(numbers, 5);

    printf("Largest = %d", largest);

    return 0;
}

Sample Output

Enter 5 numbers:
25 67 12 89 43
Largest = 89

Explanation

The array is passed to the function:

findLargest(numbers, 5);

Inside the function, the first element is initially considered the largest:

int largest = numbers[0];

The loop then compares the remaining elements with it.

If a larger value is found, largest is updated.

Concepts Covered

  • Arrays
  • Functions
  • Function arguments
  • Loops
  • Conditional statements

Q6. Student Result Using Structure, Array and Function

Problem Statement

Create a student result program using a structure. Store a student’s name and marks in three subjects. Calculate the total and percentage using a function.

C Program

#include <stdio.h>

struct Student
{
    char name[50];
    int marks[3];
};

int calculateTotal(struct Student student)
{
    int total = 0;
    int i;

    for (i = 0; i < 3; i++)
    {
        total = total + student.marks[i];
    }

    return total;
}

int main()
{
    struct Student student;
    int total;
    float percentage;

    printf("Enter student name: ");
    scanf(" %[^\n]", student.name);

    printf("Enter marks for 3 subjects:\n");

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

    total = calculateTotal(student);
    percentage = total / 3.0;

    printf("\nStudent Name = %s\n", student.name);
    printf("Total = %d\n", total);
    printf("Percentage = %.2f%%", percentage);

    return 0;
}

Sample Output

Enter student name: Rahul
Enter marks for 3 subjects:
80
75
90

Student Name = Rahul
Total = 245
Percentage = 81.67%

Explanation

The structure contains:

struct Student
{
    char name[50];
    int marks[3];
};

This combines a string and an array inside one structure.

The function:

calculateTotal(student);

calculates the total marks.

The percentage is then calculated using:

percentage = total / 3.0;

Concepts Covered

  • Structures
  • Arrays
  • Strings
  • Functions
  • Loops
  • Arithmetic operators

Q7. Search for a Number in an Array

Problem Statement

Write a C program that accepts numbers into an array and searches for a number entered by the user.

C Program

#include <stdio.h>

int searchNumber(int numbers[], int size, int target)
{
    int i;

    for (i = 0; i < size; i++)
    {
        if (numbers[i] == target)
        {
            return i;
        }
    }

    return -1;
}

int main()
{
    int numbers[5];
    int target;
    int position;
    int i;

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

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

    printf("Enter number to search: ");
    scanf("%d", &target);

    position = searchNumber(numbers, 5, target);

    if (position != -1)
    {
        printf("Number found at index %d", position);
    }
    else
    {
        printf("Number not found.");
    }

    return 0;
}

Sample Output

Enter 5 numbers:
10 25 40 55 70
Enter number to search: 40
Number found at index 2

Explanation

The function checks every element:

if (numbers[i] == target)

If the number is found, the function returns its index.

If the loop finishes without finding it:

return -1;

is returned.

The main function then checks the returned value.

Concepts Covered

  • Arrays
  • Functions
  • Searching
  • for loop
  • Return values
  • if-else

Q8. Count Vowels in a String Using a Function

Problem Statement

Write a C program that accepts a string and uses a function to count the number of vowels.

C Program

#include <stdio.h>
#include <ctype.h>

int countVowels(char str[])
{
    int count = 0;
    int i;

    for (i = 0; str[i] != '\0'; i++)
    {
        char ch = tolower((unsigned char)str[i]);

        if (ch == 'a' || ch == 'e' || ch == 'i' ||
            ch == 'o' || ch == 'u')
        {
            count++;
        }
    }

    return count;
}

int main()
{
    char text[100];
    int vowels;

    printf("Enter a string: ");
    fgets(text, sizeof(text), stdin);

    vowels = countVowels(text);

    printf("Number of vowels = %d", vowels);

    return 0;
}

Sample Output

Enter a string: Hello World
Number of vowels = 3

Explanation

The program reads each character:

for (i = 0; str[i] != '\0'; i++)

tolower() converts an uppercase letter to lowercase for comparison.

Then the program checks whether the character is:

a, e, i, o, u

If it is a vowel, count increases.

Concepts Covered

  • Strings
  • Character arrays
  • Functions
  • Loops
  • if
  • Character handling

Q9. Simple Bank Account Using Structure and Functions

Problem Statement

Create a simple bank account program using a structure. The program should allow the user to deposit and withdraw money.

C Program

#include <stdio.h>

struct Account
{
    char name[50];
    float balance;
};

void deposit(struct Account *account, float amount)
{
    if (amount > 0)
    {
        account->balance = account->balance + amount;
    }
}

void withdraw(struct Account *account, float amount)
{
    if (amount <= 0)
    {
        printf("Invalid withdrawal amount.\n");
    }
    else if (amount > account->balance)
    {
        printf("Insufficient balance.\n");
    }
    else
    {
        account->balance = account->balance - amount;
    }
}

int main()
{
    struct Account account;
    float depositAmount;
    float withdrawalAmount;

    printf("Enter account holder name: ");
    scanf(" %[^\n]", account.name);

    account.balance = 1000;

    printf("Enter deposit amount: ");
    scanf("%f", &depositAmount);

    deposit(&account, depositAmount);

    printf("Enter withdrawal amount: ");
    scanf("%f", &withdrawalAmount);

    withdraw(&account, withdrawalAmount);

    printf("\nAccount Holder = %s\n", account.name);
    printf("Final Balance = %.2f", account.balance);

    return 0;
}

Sample Output

Enter account holder name: Rahul
Enter deposit amount: 500
Enter withdrawal amount: 300

Account Holder = Rahul
Final Balance = 1200.00

Explanation

This program combines several concepts.

The structure stores account information:

struct Account

The functions receive a pointer:

struct Account *account

This allows the functions to modify the original structure.

The arrow operator:

account->balance

is used to access a structure member through a pointer.

The withdrawal function also checks whether enough balance is available.

Concepts Covered

  • Structures
  • Structure pointers
  • Functions
  • Pointers
  • if-else
  • Input/output

Q10. Mini Student Management Program

Problem Statement

Create a small student management program that stores information for three students and displays their details and average marks.

C Program

#include <stdio.h>

struct Student
{
    int rollNumber;
    char name[50];
    float marks;
};

float calculateAverage(struct Student students[], int size)
{
    float total = 0;
    int i;

    for (i = 0; i < size; i++)
    {
        total = total + students[i].marks;
    }

    return total / size;
}

void displayStudents(struct Student students[], int size)
{
    int i;

    printf("\nStudent Details\n");
    printf("-------------------------\n");

    for (i = 0; i < size; i++)
    {
        printf("Roll Number: %d\n", students[i].rollNumber);
        printf("Name: %s\n", students[i].name);
        printf("Marks: %.2f\n", students[i].marks);
        printf("-------------------------\n");
    }
}

int main()
{
    struct Student students[3];
    float average;
    int i;

    for (i = 0; i < 3; i++)
    {
        printf("Enter details for student %d\n", i + 1);

        printf("Roll Number: ");
        scanf("%d", &students[i].rollNumber);

        printf("Name: ");
        scanf(" %[^\n]", students[i].name);

        printf("Marks: ");
        scanf("%f", &students[i].marks);

        printf("\n");
    }

    displayStudents(students, 3);

    average = calculateAverage(students, 3);

    printf("Class Average = %.2f", average);

    return 0;
}

Sample Output

Enter details for student 1
Roll Number: 101
Name: Rahul
Marks: 85

Enter details for student 2
Roll Number: 102
Name: Priya
Marks: 90

Enter details for student 3
Roll Number: 103
Name: Amit
Marks: 75


Student Details
-------------------------
Roll Number: 101
Name: Rahul
Marks: 85.00
-------------------------
Roll Number: 102
Name: Priya
Marks: 90.00
-------------------------
Roll Number: 103
Name: Amit
Marks: 75.00
-------------------------
Class Average = 83.33

Explanation

This program brings together many concepts from previous chapters.

The array:

struct Student students[3];

stores three structures.

Each structure contains:

Roll Number
Name
Marks

The displayStudents() function displays all records.

The calculateAverage() function calculates the class average.

The for loops are used to enter and process multiple students.

This is much closer to the type of structure you will see in larger C programs.

Concepts Covered

  • Structures
  • Array of structures
  • Strings
  • Functions
  • Function arguments
  • Loops
  • Input/output
  • Arithmetic operations

Key Takeaways

  • Real C programs usually combine multiple concepts.
  • Variables store individual values.
  • Arrays store multiple values of the same type.
  • Structures combine related pieces of data.
  • Functions divide a large program into smaller tasks.
  • Loops are useful for processing arrays and repeated data.
  • Conditions help programs make decisions.
  • Strings are character arrays ending with '\0'.
  • Structure pointers allow functions to modify structure data.
  • Returning values from functions helps separate calculations from program control.
  • Large programs become easier to understand when each function has a clear responsibility.
  • The best way to become comfortable with C is to repeatedly combine previously learned concepts.

FAQs

1. Why should I practice C programs using multiple concepts?

Because real programs rarely use only one C concept. Combining concepts helps you learn how variables, arrays, functions, structures, loops, and conditions work together.

2. Which C concepts should I know before solving multi-concept programs?

You should have a basic understanding of variables, operators, conditions, loops, functions, arrays, strings, pointers, and structures.

3. How do I solve a large C program as a beginner?

Break it into smaller tasks. Identify the required data, create functions for separate operations, write one section at a time, and test each part.

4. Why are functions important in larger C programs?

Functions divide a large program into smaller reusable sections. This makes the code easier to understand, test, debug, and maintain.

5. Can arrays and structures be used together in C?

Yes. An array of structures can store multiple records of the same type, such as multiple students or employees.

6. Can a function receive an array in C?

Yes. An array can be passed to a function, allowing the function to process its elements.

7. What should I practice after learning these multi-concept programs?

You should move toward larger projects such as student management systems, employee management systems, billing programs, inventory programs, and file-based applications.

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top