Erster Commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
int main(void) {
|
||||
/*
|
||||
float digit, temp1, temp2, temp3;
|
||||
int dig1st, dig2nd, dig3rd, digSum;
|
||||
|
||||
printf("Enter a tree digit number!\n");
|
||||
scanf("%f", &digit);
|
||||
|
||||
temp1 = (digit / 100.0);
|
||||
printf("temp1: %.3f\n", temp1);
|
||||
|
||||
dig1st = (int)temp1;
|
||||
printf("dig1st: %d\n",dig1st);
|
||||
|
||||
|
||||
temp2 = (temp1 - dig1st) * 10;
|
||||
printf("temp2: %.3f\n", temp2);
|
||||
|
||||
dig2nd = (int)temp2;
|
||||
printf("dig2nd: %d\n",dig2nd);
|
||||
|
||||
|
||||
temp3 = (temp2 - dig2nd) * 10;
|
||||
printf("temp3: %.3f\n", temp3);
|
||||
|
||||
dig3rd = (int)(temp3);
|
||||
printf("dig3rd: %d\n",dig3rd);
|
||||
|
||||
*/
|
||||
int num;
|
||||
int units, tens, hundreds;
|
||||
|
||||
printf("Enter a 3-digit number: ");
|
||||
scanf("%d", &num);
|
||||
|
||||
units = num % 10;
|
||||
tens = (num / 10) % 10;
|
||||
hundreds = num / 100;
|
||||
|
||||
printf("The total sum of digits in %d is %d\n", num, units+tens+hundreds);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user