Return to Snippet

Revision: 53303
at November 18, 2011 11:49 by AlexanderRavikovich


Updated Code
#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");
		}
	}
}

Revision: 53302
at November 18, 2011 11:42 by AlexanderRavikovich


Initial Code
#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 0, so if we get error in next "if",
			we dont show previous printf */
			index = 1; 
		}

		/* Put entered numbers in 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 */
			num_f = num1;
			num_s = num2;

			/* We have exactly condition, so we now that we need
			only 3 times to loop 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");
		}
	}
}

Initial URL

                                

Initial Description
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.

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

Initial Tags

                                

Initial Language
C