Hello I'm currently working on C/++/# programming because I'm planning to attend college for Software Development in hopes of possibly working with some major and minor developers down the line and I was told by a mentor to come here. I'm currently working on a program that uses numbers divisible by 9 here's my code so far I can get it to go up to 8 numbers but one minor problem what if someone wants to just use 4-3 digits? is there anyway of possibly changing this around to suit that purpose without avoiding lowering numbers?
Code:
#include <stdio.h>
#include <stdlib.h>
/* Determines whether or not the users integer is divisible by 9 and displays all numbers withing integer*/
int main(void)
{
int num; /* Users inputed integer */
int d8; /* 8th digit of the number */
int d7; /* 7th digit of the number */
int d6; /* 6th digit of the number */
int d5; /* 5th digit of the number */
int d4; /* 4th digit of the number */
int d3; /* 3rd digit of the number */
int d2; /* 2nd digit of the number */
int d1; /* 1st digit of the number */
printf("please enter any digis to see if its divisable by 9. \n");
scanf("%d", &num);
if ( num % 9 >= 0)
{
/* Peels off the integer's digits and assigns them to a variable*/
d8 = num % 10;
d7 = (num /100) % 10;
d6 = (num / 1000) % 10;
d5 = (num / 10000) % 10;
d4 = (num / 100000) % 10;
d3 = (num / 1000000) % 10;
d2 = (num / 10000000) % 10;
d1 = (num / 10000000) % 10;
/*prints out the intger's digits starting with the rightmost digit */
printf("rightmost digit: %d\n", d8);
printf("%d\n", d7);
printf("%d\n", d6);
printf("%d\n", d5);
printf("%d\n", d4);
printf("%\n", d3);
printf("%d\n",d2);
printf("leftmost digit: %d\n", d1);
/* Tells the user the number is divisible by 9 */
printf("your number is divisible by 9\n");
}
else
{
/* Peels off the integer's digits and assigns them to a variable*/
d8 = num % 10;
d7 = (num /100) % 10;
d6 = (num / 1000) % 10;
d5 = (num / 1000) % 10;
d4 = (num / 10000) % 10;
d3 = (num / 10000) % 10;
d2 = (num / 10000) % 10;
d1 = (num / 100000) % 10;
/*prints out the intger's digits starting with the rightmost digit */
printf("rightmost digit: %d\n", d8);
printf("%d\n", d7);
printf("%d\n", d6);
printf("%d\n", d5);
printf("%d\n", d4);
printf("%\n", d3);
printf("%d\n", d2);
printf("leftmost digit: %d\n", d1);
/* Tells the user the number isnt divisible by 9 */
printf("your number is not divisible by 9\n");
}
system("pause");
return(0);
}