# find average of numbers between 0-50.(enter by user). logical error.anyone help me to find it out.

// File name: Main.java ;
import java.util.Scanner;
public class Main
{
public static void main (String[]args)
{
Scanner d = new Scanner (System.in);
int n;
int sum =0;
double avg = 1.0;
int i;
int max;
int min;
max=Integer.MIN_VALUE;
min=Integer.MAX_VALUE;
while(true)
{
//an infinite loop, use Ctrl-C to quit
System.out.println ("Enter an integer:");
n = d.nextInt ();
if(n < -0 || n>50)break;
sum = sum+n;

for(i=2;i<n;i++)
avg = sum/i;

if(n<min)
{
min=n;
}
if(n>max)
{
max=n;
}

}    //end of while

System.out.println("the avg is" +avg );
System.out.println("maximum num is :" +max);
System.out.println("minimum num is:" +min);
}

}    //end of main

answered Aug 11, 2019 by (180 points)
import java.util.Scanner;
public class Main
{
void average(int n)
{
int i,a=0,b;
for(i=1;i<=n;i++)
{
a+=i;
}
b=a/n;
System.out.print(b);
}
public static void main(String[] args) {
int n;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
Main k=new Main();
k.average(n);
}
}
answered Aug 11, 2019 by anonymous
answered Aug 12, 2019 by anonymous
#include<stdio.h>
main()
{
float n, I, avg, sum=0;
printf("enter n value:");
Scanf("%f",&n);
For(i=0;i<=n; i++);
Sum=sum+i;
Avg=sum/n;
Printf("avg is %f",avg);
}
answered Aug 12, 2019 by (140 points)
#include <iostream>

using namespace std()

int main()

{    int n,i,x,avg;

cin>>n;

for(i=1;i<=n;i++)

{    x=x+i;

}

avg=x/n;

cout<<avg;

}