18SepPython's Posts
Nairaland Forum › 18SepPython's Profile › 18SepPython's Posts
1 (of 1 pages)
FamDamSam:i just started my programming journey and i'm learning C language. |
FamDamSam:start with me ![]() |
please i need help with this(C programming) Question: Write a program to calculate the sum of the first and the second last digit of a 5 digit number entered from the keyboard. solution.. #include <stdio.h> main(){ int n, first, second, third, forth, fifth, sum; printf("Enter a 5-digit number\n" ;scanf("%d", &n); /*Now we will take out each digit of this number and then finally add the first and the second last digits*/ first = n/10000; //first digit n = n%10000; second = n/1000; //second digit n = n%1000; third = n/100; //third digit n = n%100; forth = n/10; //forth digit fifth = n%10; //fifth digit sum = first + forth; printf("sum : %d\n", sum); } i understand the flow but want to know why 1. n/10000; 2. n = n%1000; Please help i have been stack with this for days.Thanks |
1 (of 1 pages)

;