Question: C --- code Everything on C code import java.util.Scanner; class checksum{ public static void main(String args[]){ final int max_int = 255; // the maxium size

C --- code

Everything on C code

import java.util.Scanner; class checksum{ public static void main(String args[]){ final int max_int = 255; // the maxium size for the input int count = 10; // the number of integers to read from stdin int sum = 0; // Note that the "sum" might exceed max_int int checksum = 0; // The value of the 6th input integer int quotient; // The result of evaluating the assignment: quotient = sum / (max_int + 1); int remainder; // The result og evaluating the assignment: remainder = sum % (max_int + 1); int complement; // The result of evaluating the assignment: complement = max_int - sum; System.out.println("Enter 10 numbers from 0-255"); Scanner stdin = new Scanner(System.in);

for(int i =0; i < count; i++){ int value = stdin.nextInt(); if(value >= 0 && value <= max_int){ if(i == 5){ checksum = value; value = 0; } sum += value;

} } quotient = sum / (max_int + 1); remainder = sum % (max_int + 1); sum = quotient + remainder; complement = max_int - sum; System.out.printf("Stored Checksum: %d, Computed Checksum: %d ", checksum, complement); if (checksum != complement){ System.err.printf("Error Detected! "); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!