Header Ad

C program to evaluate an square expression and their sum

In this tutorial, we are going to write a C Program to write a program using a single subscribed variable to evaluate the square expressions given in the image below, and the values of x1, x2, ... are read from the terminal in C Programming with practical program code and step-by-step full complete explanation.


C Program to evaluate a square expression.

 
#include<stdio.h>
#include<conio.h>

void main()
{
    int i;
    float x[10],value,total;

    printf("ENTER 10 REAL NUMBERS");

    for(i=0;i<10;i++)
    {
        scanf("%f",&value);
        x[i]=value;
    }

    total=0.0;

    for(i=0;i<10;i++)
        total=total+x[i]*x[i];
    printf("\n");

    for(i=0;i<10;i++)
        printf("x[%2d]=%5.2f\n",i+1,x[i]);
    printf("total=%.2f",total);
}


Output

 
ENTER 10 REAL NUMBERS
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10
X[1]=1.10
X[2]=2.20
X[3]=3.30
X[4]=4.40
X[5]=5.50
X[6]=6.60
X[7]=7.70
X[8]=8.80
X[9]=9.90
X[10]=10.10

Total=446.86


Post a Comment

0 Comments