Skip to content

Instantly share code, notes, and snippets.

@ZNickq
Created June 11, 2012 10:24
Show Gist options
  • Save ZNickq/2909469 to your computer and use it in GitHub Desktop.
Save ZNickq/2909469 to your computer and use it in GitHub Desktop.
Cifra de control a unui numar
#include<stdio.h>
using namespace std;
int cate_cifre(int check) {
int rasp = 0;
while(check>0) {
check/=10;
rasp++;
}
return rasp;
}
int reduce(int orig) {
int rasp = 0;
while(orig!=0) {
rasp+=orig%10;
orig/=10;
}
return rasp;
}
int main() {
int numar;
printf("Introduceti numar: ");
scanf("%d",&numar);
while(cate_cifre(numar) > 1)
numar = reduce(numar);
printf("Cifra de control a numarului este %d\n",numar);
return 0;
}
@edymanoloiu
Copy link

Programul pare ok.

@taygun
Copy link

taygun commented Jun 11, 2012

You should leave a blank line between the programm's functions.Beside this,your code looks good.

@ZNickq
Copy link
Author

ZNickq commented Jun 11, 2012

@taygun Yeah, completely forgot about that! Fixing now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment