CS50_lecture1

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> #include <math.h> int judge(long a, int len); int main(void) { long num; printf("Number: "); scanf("%li", &num); // Claim a new variable "check" to see how length the num is long check = num; int count = 0; while (check) { check = round(check / 10); count++; } printf("Length: %d\n", count); int sum = judge(num, count); printf("sum = %d\n", sum); } int judge(long a, int len) { long even = 0, odd = 0, temp; for (int i = 1; i <= len; i++) { // odd terms if (i % 2 != 0) { odd += fmod(a, pow(10, i)) / pow(10, i - 1); printf("odd: %li\n", odd); } // even terms else { temp = fmod(a, pow(10, i)) / pow(10, i - 1) * 2; // temp *= 2; printf("temp: %li\n", temp); even += temp / 10 + temp % 10; printf("even: %li\n", even); } } return odd + even; }
Editor Settings
Theme
Key bindings
Full width
Lines