/ Published in: C
The program accepts two different real numbers between 100.00 to 999.00. The program checks to see if there is one number that appears in both numbers in the same place at complete part of number (before dot). If such a digit exists or not the program will print an appropriate message.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <stdio.h> void main() { /* Initializing variables again - program stops when it 0 num_f, num_s (first & second) variables used to convert float numbers to integer i - need it in FOR loop index - an index that show us that we run programm first time */ int again=1, num_f=0, num_s=0, i=0, index=0; /* Variables for float numbers entered by user */ float num1=0, num2=0; while(again) { /* If index is 0 - print this stroke */ if (!index) { /* set index to 1 to avoid showing previous message if we get an error */ index = 1; } /* Put entered numbers in the float variables float */ /* If entered numbers in our condition so we do next code */ if (999>num1 && 100<num1 && num1!=num2) { /* Convert float to integer (we need check digits only before dot) */ num_f = num1; num_s = num2; /* We have exactly condition, so we know that we need only 3 times to loop for checking ones/tens/hundreds */ for (i=0; i <3; i++) { /* Compare remainder from deviding by 10 each number */ if(num_f % 10 == num_s % 10) { switch (i) { case 0: break; case 1: break; case 2: break; } } else { switch (i) { case 0: break; case 1: break; case 2: break; } } /* Devide each number by 10 for the next using */ num_f = num_f/10; num_s = num_s/10; } /* Ask to run programm again */ /* Emulate first run of programm */ index=0; } else { /* Error handler, if entered numbers is wrong */ } } }