Sum of two numbers

program to find sum of two numbers

C Programming

#include<stdio.h>
int main() {
int a,b,sum;
printf("Enter any two numbers: ");
scanf("%d%d",&a,&b);
sum = a + b;
printf("Total = %d",sum);
return 0;
}

C++ Programming

#include<iostream>
using namespace std;
int main() {
int a,b;
cout << "Enter any two numbers: ";
cin >> a >> b;
int sum = a + b;
cout<<"Total = "<<sum;
return 0;
}

Java

import java.util.Scanner;
class Sum {
public static void main(String args[]) {
int a,b;
Scanner sc = new Scanner(System.in);
System.out.print("Enter any two numbers: ");
a = sc.nextInt();
b = sc.nextInt();
int sum = a + b;
System.out.print("Total = "+sum);
}
}

Go Lang

package main
import "fmt"
func main() {
var a,b int32
fmt.Print("Enter any two numbers: ")
fmt.Scan(&a,&b)
sum := a + b
fmt.Print("Total = ",sum)
}

php

index.php

<!doctype html>
<html>
<head>
<title>Sum of two numbers</title>
</head>
<body>
<form method="post" action="doSum.php">
<p>Number-1: <input type="number" name="num1"></p>
<p>Number-2: <input type="number" name="num2"></p>
<p><input type="submit" name="sub" value="Sum"></p>
</form>
</body>
</html>

doSum.php

<?php
if(isset($_POST['sub'])) {
$a = $_POST['num1'];
$b = $_POST['num2'];
$sum = $a + $b;
echo "Total = ".$sum;
}
?> 

Comments

Popular posts from this blog

Program to calculate telephone bill

Sum of two numbers in go lang

Program to check a year is leap year or not.

String in golang

Identifiers

Arrays in C Language

Reserved Words in Java

Data types in Java

Pointers in C Language

Literals in Java