forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
special.c
47 lines (41 loc) · 826 Bytes
/
special.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
/*The program is to check whether a given number is a special number or not.
A special number is a number whose all digits are 1
Example-11
*/
#include <stdio.h>
void special(int);
int main() {
int num;
printf("Enter a number\n");
scanf("%d",&num);
/*Calling of function*/
special(num);
return 0;
}
void special(int n)
{
int b,s=0,c=0;
while(n!=0)
{
b=n%10;
/*Sum of digits*/
s=s+b;
/*Count of digits*/
c++;
n=n/10;
}
/*if sum and count are equal
then special number*/
if(s==c)
printf("The given number is special");
else
printf("The given number is not special");
}
/*
Time Complexity:O(n)
Space Complexity:O(1)
Input/Output:
Enter a number
123
The given number is not special
*/