# Posted By

AlexanderRavikovich on 11/18/11

# Statistics

Viewed 819 times
Favorited by 0 user(s)

# The programm searches for the same digit in the same place in two different numbers

/ Published in: C
`#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)		{			printf("Enter 2 diferent decimal numbers between 100.00 to 999.00:\n");			/* set index to 1 to avoid showing			previous message if we get an error */			index = 1; 		} 		/* Put entered numbers in the float variables float */		scanf("%f %f", &num1, &num2); 		/* 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: 						   printf("The ones are equals\n");						break;						case 1:						   printf("The tens are equals\n");						break;						case 2:						   printf("The hundreds are equals\n");						break;					}				}				else				{					switch (i)					{						case 0: 						   printf("The ones are NO equals\n");						break;						case 1:						   printf("The tens are NO equals\n");						break;						case 2:						   printf("The hundreds are NO equals\n");						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 */			printf("Item 4 again ? (yes = 1 / no = 0)\n");			scanf("%d", &again);			/* Emulate first run of programm */			index=0; 		}		else		{			/* Error handler, if entered numbers is wrong */			printf("Wrong number, try again!!\n");		}	}}`