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

Write a program to read ONLY one integer number (your input must be one 3 digit

ID: 3551995 • Letter: W

Question

 Write a program to read ONLY one integer number (your input must be one    3 digit number from 100 to 999), and to think of a number as being ABC   (where A, B, and C are the 3 digits of a number). Now, form  the  number   to become ABC,BCA, and CAB, then find out the remainder of  these three   numbers when they are divided by 11. Assume remainders would  respectively   be X, Y, and Z  and  add  them  up  as  X+Y, Y+Z, and  Z+X. Now if any  of   these summations is odd number, increase it by 11 if the summation plus 11   is less than 20, otherwise  decrease the  summation  by 11 (this summation   operation must  be positive  number but  less than 20). Finally, divide   each of the sums in half. Now, print out all the resulting digits.  

Explanation / Answer

#include <stdio.h>

int main()

{

//Declare all variables

int OrigNumber;

int a, b, c;

int abc, bca, cab;

int x, y, z;

int xplusy , yplusz, xplusz;


printf(" A program to read ONLY one integer number. Input must be one 3 digit number from 100 to 999 : ");

scanf("%d", &OrigNumber); // Get input from console


if(OrigNumber > 999 || OrigNumber < 100) {

printf("Invalid number. Quiting program. This is error handling. Important while learning programming.");   

return 0;

}


c = OrigNumber %10; // digit at unit's place


b=((OrigNumber) % 100)/10; //digit at the ten's place


a = (OrigNumber)/100; //digit at the 100's place. Note: 734/100 = 7. NOT 7.34.


printf(" Three numbers say A,B, C : %d, %d , %d ", a, b, c);


abc = a*100 + 10*b + c;

bca = 100*b + 10*c + a;

cab = c*100 + a*10 + b;


printf(" Three numbers say ABC, BCA, CAB : %d, %d , %d ", abc, bca, cab);


x = abc % 11; // Reminder when divided by 11.

y = bca % 11;

z = cab % 11;


printf(" Three numbers say X, Y, Z : %d, %d , %d ", x, y, z);


xplusy = x + y; // Adding reminders two at a time.

yplusz = y + z;

xplusz = x + z;


printf(" Three numbers X+Y, Y+Z, X+Z : %d, %d , %d ", xplusy, yplusz, xplusz);


if((xplusy % 2) == 1) {

if(xplusy + 11 < 20)

xplusy += 11;

else

xplusy -= 11;

}


if((yplusz % 2) == 1) {

if(yplusz + 11 < 20)

yplusz += 11;

else

yplusz -= 11;

}


if((xplusz % 2) == 1) {

if(xplusz + 11 < 20)

xplusz += 11;

else

xplusz -= 11;

}


xplusy /= 2; // Finally, divide each of the sum in half.

yplusz /= 2;

xplusz /= 2;


printf(" Now print out all the resulting digits : %d, %d , %d ", xplusy, yplusz, xplusz);


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