WAP to display sum and average of three numbers.
Answers
Answered by
2
heya!
Program:-
public class display
{
public static void main (String at[])
{
int a= Integer.parseInt(ar[0]);
int b= Integer.parseInt(ar[1]);
int c= Integer.parseInt(ar[2]);
int s= a+b+c;
int avg= s/3 ;
System.out.println("sum of three numbers="+s);
System.out.println("average of three numbers="+avg);
}
}
suppose the numbers are 2,4and 6
therefore,
Output:-
sum of three numbers= 12
average of three numbers= 4
hope this helps.
Program:-
public class display
{
public static void main (String at[])
{
int a= Integer.parseInt(ar[0]);
int b= Integer.parseInt(ar[1]);
int c= Integer.parseInt(ar[2]);
int s= a+b+c;
int avg= s/3 ;
System.out.println("sum of three numbers="+s);
System.out.println("average of three numbers="+avg);
}
}
suppose the numbers are 2,4and 6
therefore,
Output:-
sum of three numbers= 12
average of three numbers= 4
hope this helps.
MansiGarg1111:
welcome ^^
Answered by
3
#include<stdio.h>
int main()
{
int a,b,c,sum;
float avg;
printf("Enter 1st number : ");
scanf("%d",&a);
printf("Enter 2nd number : ");
scanf("%d",&b);
printf("Enter 3rd number : ");
scanf("%d",&c);
sum = (a + b + c);
avg = sum / 3;
printf("Sum of three numbers is : %d\n", sum);
printf("Average of three numbers is : %d", avg);
return 0;
}
Hope this helps!
int main()
{
int a,b,c,sum;
float avg;
printf("Enter 1st number : ");
scanf("%d",&a);
printf("Enter 2nd number : ");
scanf("%d",&b);
printf("Enter 3rd number : ");
scanf("%d",&c);
sum = (a + b + c);
avg = sum / 3;
printf("Sum of three numbers is : %d\n", sum);
printf("Average of three numbers is : %d", avg);
return 0;
}
Hope this helps!
Similar questions