Write an algorithm to calculate the average of marks obtained in 4 subjects out of 80, taking the input from the user.
Answers
Java programme :-
{\\class
/AverageMarks
{utl.source
public static void main(String args[])}}\
{
int n;
int p =args.length;
double avg=0;
for( i=0;i<n;i++)
{
avg=avg+Integer.parseInt(args[i]);
}
System.out.println("4")
System.out.print("Average marks of (" 40,50,55,60);
The AverageCalculation c= (a);
for(i=0;i<n-1;i++)
{
System.out.print(args[i]+",");
}
System.out.print(a[i]+",");
}
System.out.println(a[i]+") ="+c.avg/n);\\
}
}
Output :-
The number of subjects = 4
Marks
40
50
55
60
Average of (40+50+55+60) =205/4 = 51.25 .
import.java.util.*;
class s1upv
{public static void main ()
{double s,a,p,u ;
scanner sc = new Scanner ( system.in); system .out.println ("enter marks of 4 subjects");
s = sc.nextDouble(); a = sc.nextDouble(); u = sc.nextDouble(); p= sc.nextDouble();
if ( s < 80 && a< 80 && p< 80 && u< 80 )
{double t = s+a+p+u ;
double k = t / 4 ;
}
else
{ system .out.println ( "full mks is 80 so mks obtained must be <80 ") ; }
system.out.println (" average : " + k ) ;
}}