First Upload
This commit is contained in:
50
1/ex1.c
Normal file
50
1/ex1.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define DIGITS 3
|
||||
#define TEN 10
|
||||
#define ZERO 0
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 1
|
||||
// ----------
|
||||
//
|
||||
// General : The program recognize if all digits are same.
|
||||
//
|
||||
// Input : Number with 3 digits.
|
||||
//
|
||||
// Process : The program summarizes all the digits and divie by last digit.
|
||||
//
|
||||
// Output : '0' if is it True, else is false.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 09.09.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
short num,
|
||||
temp,
|
||||
sum = ZERO;
|
||||
|
||||
printf("Enter number with 3 digits: ");
|
||||
scanf("%hd", &num);
|
||||
|
||||
// Take the first digit from right and add to sum
|
||||
temp = num / TEN;
|
||||
sum += num - (temp * TEN);
|
||||
num = temp;
|
||||
|
||||
temp = num / TEN;
|
||||
sum += num - (temp * TEN);
|
||||
num = temp;
|
||||
|
||||
sum += num;
|
||||
|
||||
// Divie the sum by last digit from right and check if (Rest == 0) and
|
||||
// (result == (count of digits))
|
||||
temp = sum / num;
|
||||
sum %= num;
|
||||
sum = sum + DIGITS - temp;
|
||||
|
||||
printf("If you got '0' then it is True, else is False: %hd\n", sum);
|
||||
}
|
||||
Reference in New Issue
Block a user