Computer Science, asked by lallawmpuiabunghai, 1 day ago

write a program to add and find average of two numbers​

Answers

Answered by XxDollfacexX
7

/* c program find sum and average of two numbers*/

#include <stdio.h>

int main()

{

int a,b,sum;

float avg;

printf("Enter first number :");

scanf("%d",&a);

printf("Enter second number :");

scanf("%d",&b);

sum=a+b;

avg= (float)(a+b)/2;

printf("\nSum of %d and %d is = %d",a,b,sum);

printf("\nAverage of %d and %d is = %f",a,b,avg);

return 0;

}

Answered by Shivu516
0

This program is in Java.  

import java.util.*;

public class AverageCalculator {

   public static void main (String [] args) {

       //Taking input from the user

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter the first number: ");

       double num1 = sc.nextDouble();

       System.out.print("Enter the second number: ");

       double num2 = sc.nextDouble();

       //Main part comes here

       double Average = (num1 + num2) / 2;

       System.out.println("The average of the given numbers is " + Average);

   }

}

Output:

Enter the first number: 30

Enter the second number: 32

The average of the given numbers is 31

Similar questions