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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started