Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program is to be compiled on C Write a program that determines whether sum o

ID: 3533756 • Letter: T

Question

The program is to be compiled on C

Write a program that determines whether sum of two numbers equals the third number. Your program should read three numbers from the user and display one of the below messages. Sum of two numbers equals the third number Sum of two numbers does not equal the third number Read the three numbers a, b, c from the user and display the corresponding output. Test your program for the following values of a, b and c 1 2 3 Sum of two numbers equals the third number 5 2 3 Sum of two numbers equals the third number 1 6 5 Sum of two numbers equals the third number 2 3 6 Sum of two numbers does not equal the third number 2 2 2 Sum of the numbers does not equal the third number

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int i, n;
    double total = 0, formula;
   
    printf("Enter n: ");
    scanf("%d", &n);
   
    //for loop
    for(i=1; i <= n; i++){
             total += i*(i+1);
    }
    formula = ( n*(n+1)*(n+2) ) / 3;
    printf("For Loop Loop Result = %.0f Forumla = %.0f ", total, formula);
   
    //while loop
    total = 0;
    i = 1;
    while(i <= n){
        total += 1.0 / (i*(i+1));
        i++;
    }
    formula = 1 - ( 1.0 / (n + 1) );
    printf("While Loop Loop Result = %f Forumla = %f ", total, formula);
   
    //do while loop
    total = 0;
    i = 1;
    do{
        total += 1.0/ pow(2,i);
        i++;
    }while(i <= n);
    formula = 1 - ( 1.0 / pow(2,n) );
    printf("Do While Loop Loop Result = %f Forumla = %f ", total, formula);

    return 0;
}