-
Notifications
You must be signed in to change notification settings - Fork 32
/
FriendNumbers.c
53 lines (43 loc) · 1.02 KB
/
FriendNumbers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
*Name: Minhas Kamal
*Date:04.May.2013
**/
#include <stdio.h>
int main()
{
long int a, b, a1, b1;
printf("Enter two positive integers: "); //asking the user
scanf("%ld %ld", &a, &b);
a1=a; //to store the main value
b1=b; //to store the main value
if(a<1 || b<1) //input check
{
printf("Invalid input!");
exit(1);
}
for( ; ; ) //main operation for first integer
{
int af=0;
for( ; a>10; a=a/10)
{
af=af+(a%10);
}
af=af+a;
a=af;
if(a<10) break; //breaking the loop
}
for( ; ; ) //main operation for second integer
{
int bf=0;
for( ; b>10; b=b/10)
{
bf=bf+(b%10);
}
bf=bf+b;
b=bf;
if(b<10) break; //breaking the loop
}
if(a==b) printf("%ld and %ld are friends\n", a1, b1); //output
else printf("%ld and %ld are not friends\n", a1, b1);
return 0;
}