Home > Back-end >  C language subject
C language subject

Time:03-21

Each digital sum:
Int m_sum (int x)
{int t=0;
int n=0;
While (x & gt; 0)
{n=x % 10;
X=x/10;
T +=n; }
Return t; }
Int main ()
{int x=123;
Printf (" % d \ n ", m_sum (x));
return 0; }
In 100 several 9:
Int m_fi (int x)
{int I;
Int t=0;
For (I=0; I & lt; x ; I++)
{if (I % 10==9)
{t++; }
If (I/10==9)
{t++; }
}
Return t;
}
Int main ()
{int x=100;
Printf (" % d ", m_fi (x));
}
Daffodil number: (153=1 * 1 * 1 + 5 + 5 * 5 * 3 * 3 * 3)
#include
Int m_pow (int x)
={x x x x x x
Return the x;
}
Int m_narcissistic (int y)
{int b=y, t=0, n=0;
While (y & gt; 0)
{n=y % 10;
Y=y/10;
T +=m_pow (n);
}
If (t==b)
{printf (" % d \ n ", b);
return 1;
} the else
{return 0; }
}
Int main ()
{int I; For (I=100; I & lt; 1000; I++)
{if (m_narcissistic (I)==1)
{printf (" % d \ n ", I); }
}
return 0;

CodePudding user response:

The building code is no problem, simplified, for reference:
 # include 

Int m_sum (int x)
{
Int t=0;
While (x) {
T +=x % 10;
X/=10;
}
Return t;
}


Int m_cnt_9 (int x)
{
Int CNT=0;
While (x) {
If (10) (x %==9) cnt++;
X/=10;
}
Return CNT.
}

Int m_fi (int x)//there are several 9:
{
int i;
Int t=0;
For (I=1; I & lt; x ; I++) {
T +=m_cnt_9 (I);
}
Return t;
}


Int m_pow (int x)
{
X=x x x x x
Return the x;
}

Int m_narcissistic (int y)//daffodil number: (153=1 * 1 * 1 + 5 + 5 * 5 * 3 * 3 * 3)
{
Int b=y, t=0;
While (y) {
T +=m_pow (y % 10);
Y/=10;
}
{if (t==b)
return 1;
} else {
return 0;
}
}

Int main ()
{
Int I, x=1000, y=123;

Printf (" % d \ n ", m_sum (y));//digits and

Printf (" % d \ n ", m_fi (x));//the number of 1-1000 between 9

For (I=100; I & lt; 1000; I++) {//daffodil number
If (m_narcissistic (I)==1) {
Printf (" % d ", I);
}
}
printf("\n");

return 0;
}
  • Related