Skip to content

Instantly share code, notes, and snippets.

@RadchenkoRV
Created March 19, 2019 15:19
Show Gist options
  • Select an option

  • Save RadchenkoRV/d35c06b90effe02449d616d68160bcd1 to your computer and use it in GitHub Desktop.

Select an option

Save RadchenkoRV/d35c06b90effe02449d616d68160bcd1 to your computer and use it in GitHub Desktop.
#include<cs50.h>
#include<stdio.h>
int main(void)
{
long num = get_long("Number: ");
int rez = num % 10;
int nn = 1;
int sum = 0;
while ( num > 10)
{
num /= 10;
nn++;
rez = num % 10;
if (nn % 2 == 0)
{
if (rez*2 >= 10)
{
int f = (rez*2)/10;
int s = (rez*2)%10;
sum = sum + f + s;
}
sum = sum + rez*2;
}
printf("%ld %d %d % d\n", num, rez, nn, sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment