Multiple Variable Declaration in C Language

Multiple Variable Declaration and Input

Building on the understanding of basic variable manipulation and input/output operations, this assignment introduces the simultaneous declaration of multiple variables and user input using scanf in C. The objective is to enhance proficiency in managing diverse data types within a program.

See Also – What is Git?

The program expands beyond single-variable scenarios by declaring two integer variables (num1 and num2) and a float variable (salary). It then prompts the user to input two integers and their salary, engaging in a more complex interaction. The program utilizes scanf with multiple format specifiers to handle the simultaneous input of various data types. Following user input, the program performs basic arithmetic operations and displays the results, reinforcing the understanding of multiple variable declaration and basic arithmetic.

Multiple Variable Declaration

The simultaneous declaration of multiple variables is a crucial skill in programming, enabling efficient management of various data types. The scanf function, when equipped with multiple format specifiers, facilitates the simultaneous input of different data types. Additionally, the assignment introduces basic arithmetic operations, laying the foundation for more complex mathematical computations in programming.


#include <stdio.h>

int main() {
    int num1, num2;
    float salary;

    printf("Enter two integers: ");
    scanf("%d %d", &num1, &num2);

    printf("Enter your salary: ");
    scanf("%f", &salary);

    printf("Sum of  %d and %d is %d\n", num1, num2, num1 + num2);
    printf("Your salary is %.2f\n", salary);

    return 0;
Multiple Variable Declaration


Enter two integers: 10 20
Enter your salary: 50000.50
Sum of 10 and 20 is 30
Your salary is 50000.50
Multiple Variable Declaration
Mahesh Wabale
Latest posts by Mahesh Wabale (see all)

Leave a Comment