Skip to main content

C Program to determine the Range and Average of the values entered by the user(to terminate enter -1).

C Program to determine the Range and Average of the values entered by the user(to terminate enter -1).

    This is a program to calculate the range and average of the values entered by the user and to terminate it by entering -1 and it will determine the highest-value, lowest-value, range, average and also it will count the number of values entered by the user.


PROGRAM:

#include<stdio.h>
#include<math.h>
int main()
{
    int count=0;
    float value,high,low,average,range,sum=0;
    printf("Enter the values (to terminate enter -1) :\n");
    while(1)
    {
        scanf("%f",&value);
        if(value!=-1)
        {
            count++;
            sum=sum+value;
            if(count==1)
            {
                low=high=value;
            }
            else if(value>high)
            {
                high=value;
            }
            else if(value<low)
            {
                low=value;
            }
        }
        else
        {
            break;
        }
    }
    average=sum/count;
    range=high-low;
    printf("Total values : %d",count);
    printf("Highest-value : %f",high);
    printf("Lowest Value : %f",low);
    printf("Range : %f",range);
    printf("Avergae : %f",average);
    return 0;
}


OUTPUT:



NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together. 


MOTTO: 

You Learn, I Learn together We Learn.



Comments

Popular posts from this blog

C Program to Check a Whether a Number is Divisible by 5 or Not

 C Program to Check a Whether a Number is Divisible by 5 or Not            In this program we will check a number entered by the user will be divisible by 5 or Not. We have solved this problem using if-else statement. Program: #include <stdio.h> #include <conio.h> int  main() {      int  x;     printf( "Enter a number" );     scanf( "%d" ,&x);      if (x% 5 == 0 )         printf( "The number %d is divisible by 5" ,x);      else         printf( "The number %d is not divisible by 5" ,x);      return   0 ; } Output: NOTE:   You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together.  MOTTO:  You Learn, I Learn together We Learn.  

C Program to print the values of the diagonal elements of a square matrix and also find the sum of the values of the diagonal elements

C Program to print the values of the diagonal elements of a square matrix and also find the sum of the values of the diagonal elements.     In this example, we will accept the values of a square matrix and will print the diagonal elements of the of the square matrix, also the sum of the values of the diagonal elements will be printed.     Here, in the output we have taken a 3x3 square matrix.     PROGRAM #include <stdio.h> #include <conio.h> void   main () {      int   a [ 50 ][ 50 ], row , column , i , j , sum = 0 ;      printf ( "Enter the row size of the square matrix : " );      scanf ( " %d " ,& row );      column = row ;      printf ( "As this is a square matrix the row size and column size are equal." );      printf ( " \n Enter the elements of the matrix : " );      for ( i = 0 ; i < row ; i ++)     {          for ( j = 0 ; j < column ; j ++)         {              scanf ( " %d " ,& a [ i ][ j ]);

C++ program to define a class circle to represent circles. Add a data member radius to store the radius of a circle. Write member functions area() and perimeter() to compute the area and perimeter of a circle.

  C++ program to define a class circle to represent circles. Add a data member radius to store the radius of a   circle. Write member functions area() and perimeter() to compute the area and perimeter of a circle.     To define a Circle class in C++, we start by declaring the class with the class keyword, followed by the name of the class. In this case, we'll call it Circle . We'll then define a private data member to store the radius of the circle. Here's the code to do that:    class Circle {      private:      double radius;    };          Next, we need to define public member functions that can set and get the value of the radius, as well as calculate the area and perimeter of the circle. Here's the full code for the Circle class: class Circle { private: double radius; public: void setRadius(double r) { radius = r; } double getRadius() { return radius; } double area() { return 3.14159 * r

C Program to check if a given square matrix is symmetric or not using function

 C Program to check if a given square matrix is symmetric or not using function.     In this example, we will check if a given square matrix entered by the user is symmetric or not. Here in the output we have taken a square matrix of 3x3. PROGRAM TO CHECK IF A GIVEN SQUARE MATRIX IS SYMMETRIC OR NOT USING FUNCTION #include <stdio.h> #include <conio.h> void  symmetric( int , int , int  [50][50]); void  main() {      int  row,column,i,j,a[50][50];     printf( "Enter the size of the matrices: " );     scanf( "%d" ,&row);     column=row;     printf( "Enter the matrix : " );      for (i=0;i<row;i++)     {          for (j=0;j<column;j++)         {             scanf( "%d" ,&a[i][j]);         }     }     symmetric(row,column,a);     getch(); } void  symmetric( int   r , int   c , int   f [50][50]) {      int  flag=1,i,j,t[50][50];      for (j=0;j< c ;j++)     {          for (i=0;i< r ;i++)         {             t[i][j]=

C Program to find out the roots of a Quadratic Equation and also test for Real and Complex roots

 C Program to find out the roots of a Quadratic Equation  and also test for Real and Complex roots.       In this example, we will calculate the roots of the quadratic equation by testing for real and complex roots. We can test real and complex roots by checking these conditions : If b 2  −4 ac  < 0, then there are no real roots. If b 2  −4 ac  = 0, then both the roots are equal. If b 2  −4 ac  > 0, then roots are real and distinct.   PROGRAM TO FIND OUT THE ROOTS OF A QUADRATIC EQUATION. #include <stdio.h> #include <conio.h> #include <math.h> int   main () {      int   a , b , c , d ;      float   x , y ;      printf ( "Enter coefficient of x^2,x and constant : " );      scanf ( " %d   %d   %d " ,& a ,& b ,& c );      d = b * b - 4 * a * c ;      if ( d < 0 )     {          printf ( "Roots are Complex and Imaginary." );     }      if ( d == 0 )     {          printf ( "Both roots are equal" );