Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed how to declare two integer variables? accepts two numbers from the user. calculates their sum

+14 votes
asked Oct 17, 2025 by anonymous
closed Oct 27, 2025 by Admin
how to declare two integer variables?
closed with the note: answered

6 Answers

+4 votes
answered Oct 17, 2025 by Noni Amr (220 points)
#include <iostream>
using namespace std;

int main(){
    int x,y,z;
    cout<<"please enter the first number: ";
    cin>>x;
    cout<<"please enter the second number";
    cin>>y;
    z=x+y;
    cout<<"the sum of the two numbers is : "<<z;
    return 0;
}
+7 votes
answered Oct 18, 2025 by Komendra Sahu (280 points)
// For C
#include <stdio.h>

int main( ){
int a, b, sum;

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

sum = a+b;

printf("%d", sum);

return 0;

}
+1 vote
answered Oct 18, 2025 by Dafne Hansfrida . D (160 points)
a=int(input(Enter any number:"))

b=int(input(Enter any number:"))

c=a+b

print("The sum = ",c)
+2 votes
answered Oct 18, 2025 by Richa yadav (180 points)
#include<iostream>

using namespace std;

int sum(int a,int b){

return a+b;

}

int main(){

cout<<"Enter number a:";

cin>>a;

cout<<"Enter number b:";

cin>>b;

cout<<sum(a,b);

return 0;

}
+1 vote
answered Oct 19, 2025 by hi (160 points)

#include <stdio.h>

int main( ){
int num1, num2, sum;

printf("Enter 2 numbers");
scanf("%d%d", &num1, &num2);

sum = num1+num2;

printf("%d", sum);

return 0;

}

+1 vote
answered Oct 24, 2025 by #Yuvraj G. (160 points)

This is in C programming language: 


#include <stdio.h>

int main()

{

    // To declare integer variables:

    int a, b;

    // To take input and store it in specified variables:

    printf("Enter the first number: ");  
    scanf("%d", &a);
    
    printf("Enter the second number: ");  
    scanf("%d", &b);

    // To add numbers and print it:

    printf("Sum of the two numbers is %d",a+b);

    return 0;

}


You can declare another variable 'c', and do c=a+b; and then print c there.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...