C Program to Check if All Digits of Number Are Same or Not

C Program to Check if All Digits of Number Are Same or Not

Write C Program to Check if All Digits of Number Are Same or Not

//Write C Program to Check if All Digits of Number Are Same or Not

#include <stdio.h>
#include <string.h>

int check_digits(int n)
{
	int last_digit = n % 10;
	while(n != 0)
	{
        int digit = n % 10;

        if(last_digit != digit)
        {
            return "All Digits are not same";
        }
        n = n / 10;
	}
	return "All digits are same";
}

int main()
{
	int n;
	printf("Enter the number :--> ");
	scanf("%d", &n);

	printf("%s ",check_digits(n));
	return 0;
}

Output:

Run 1:
Enter the number :--> 111
Numbers are same

Run 2:
Enter the number :--> 121
Numbers are not same