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

Write a C program the asks the user to input the integer N that is not less than

ID: 3558612 • Letter: W

Question

Write a C program the asks the user to input the integer N that is not less than 10 from the keyboard. If the number entered is negative or less than 10, the program should print the warning "Your input is too small" and exit the program. Your program should compute the quantity N(N+1)(2N+1)/6 and save the answer in the variable My_square. The program should also calculate the sum of squares of all the numbers from 1 to the integer N and call the result Sum_squares. Now compare My-square and Sum_squares; if they are equal, your program should display "My program works!" otherwise, your program should display "My program does not work!"

Explanation / Answer

#include<stdio.h>

int main(void)
{
   int N; //declare N
   scanf("%d",&N); //input N
   if(N<10 || N<0) //check N if it is smallar than 10 or negetive
   {
       printf("Your input is too small");
       return 0;
   }
   int My_square; // declare
   My_square = N*(N+1)*(2*N+1)/6; // computation using the formula
   int i; // iterator for FOR loop
   int Sum_squares=0;//declare add make initial value to zero as we use += operator in the for loop
   for(i=1;i<=N;i++)
       Sum_squares += i*i; //adds 1^2+2^2+3^2.... in the for loop
   if(Sum_squares==My_square) // final check statement
       printf("My program works!");
   else
       printf("My program does not work!");
  
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote