SHARE
TWEET

Untitled

a guest May 26th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Проверяет, есть ли в числе повторяющиеся цифры */
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. int main(){
  5.  int digit_seen[10] = {0};
  6.  int digit;
  7.  long num;
  8.  bool identity;
  9.  printf("Input number: ");
  10.  scanf("%ld", &num);
  11.  //!!!Нужно определить, когда вводятся не цифры, и вывести "Ошибка ввода"
  12.  while (num > 0) {
  13.     digit = num % 10;
  14.     digit_seen[digit]+=1;
  15.     if (digit_seen[digit]>1){
  16.         identity=1;}
  17.     num /= 10;}
  18.  if (identity==1){
  19.     printf("There are duplicate digits.\n");
  20.     for(int i=0;i<10;i++){
  21.         if(digit_seen[i]>1){printf("Digit %d is repeated by %d times\n", i, digit_seen[i]);}}}
  22.  else{
  23.     printf("There are NOT duplicate digits.\n");}
  24.  return 0;}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top