wap to input 35.6 and find the sum , product and average.
Answers
Sum :-
int main() {
int n, i, sum = 0;
printf("18.6:17.2 ");
scanf("%d", &n);
i = 1;
while (i <= n) {
sum += i;
++i;
}
printf("Sum = %d", sum);
return 0;
}
✒ 18.6 +17.4 = 35.8
__________________________________
Product :-
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input first number 17.9 : ");
int num1 = in.nextInt();
System.out.print("2: ");
int num2 = in.nextInt();
System.out.println(17.9 + " x " + 2 + " = " + num1 * num2);
}
- Input first number: 25
- Input second number: 5
- 25 x 5 = 125
__________________________________
Average :-
➝ 35.6 × 2 = 71.2
- number 1 = 35.1
- number 1 = 35.1number 2 = 36.1
int main()
{
int num1, num2;
float avg;
printf("35.1: ");
scanf("%d",&num1);
printf("36.1: ");
scanf("%d",&num2);
avg= (float)(35.1+36.1)/2;
//%.2f is used for displaying output upto two decimal places
printf("Average of %d and %d is: %.2f",35.1,36.1,avg);
return 0;
}
- First number: 35.1
- Second number: 36.1
- Average of 9 and 10 is: 35.6
__________________________________
Java code
import java.util.Scanner;
public class Exercise9 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Input 1st integer: ");
int firstInt = in.nextInt();
System.out.print("Input 2nd integer: ");
int secondInt = in.nextInt();
System.out.printf("Sum of two integers: %d%n", firstInt + secondInt);
System.out.printf("Difference of two integers: %d%n", firstInt - secondInt);
System.out.printf("Product of two integers: %d%n", firstInt * secondInt);
System.out.printf("Average of two integers: %.2f%n", (double) (firstInt + secondInt) / 2);
System.out.printf("Distance of two integers: %d%n", Math.abs(firstInt - secondInt));
System.out.printf("Max integer: %d%n", Math.max(firstInt, secondInt));
System.out.printf("Min integer: %d%n", Math.min(firstInt, secondInt));
}
Input the 10 numbers :
Number-1 :1
Number-2 :2
Number-3 :3
Number-4 :4
Number-5 :5
Number-6 :6
Number-7 :7
Number-8 :8
Number-9 :9
Number-10 :10
The sum of 10 no is : 55
The Average is : 5.500000
hope this will help you