Presentation is loading. Please wait.

Presentation is loading. Please wait.

Divisibility Find out if a number, Numb, is divisible by another number, Div. Is 432 divisible by 3? Is 432 divisible by 4? 432 / 3 = ? 432 / 4 = ? 432.

Similar presentations


Presentation on theme: "Divisibility Find out if a number, Numb, is divisible by another number, Div. Is 432 divisible by 3? Is 432 divisible by 4? 432 / 3 = ? 432 / 4 = ? 432."— Presentation transcript:

1 Divisibility Find out if a number, Numb, is divisible by another number, Div. Is 432 divisible by 3? Is 432 divisible by 4? 432 / 3 = ? 432 / 4 = ? 432 % 3 = ? 432 % 4 = ?

2 Divisibility #include int main(void) { int num, div; printf("Please enter a number and a divider: "); scanf("%d%d", &num, &div); if(num%div == 0) printf("%d is divisible by %d\n", num, div); else printf("%d is not divisible by %d\n", num, div); } return(0);

3 Pick a number between 1 and 5 >3>454>23>121 4,51,2,3 1,2

4 Pick a number between 1 and 5 #include int main(void) { int answ; int num; printf("Please pick a number between 1-5\n"); printf("Is the number greater than 3 (1/0): "); scanf("%d", &answ); if(answ == 1) { printf("Is the number greater than 4 (1/0): "); scanf("%d", &answ); if(answ == 1) num=5; elsenum=4; } else { printf("Is the number greater than 2 (1/0): "); scanf("%d", &answ); if(answ == 1) num=3; else { printf("Is the number greater than 1 (1/0): "); scanf("%d", &answ); if(answ == 1) num=2; else num=1; } printf("The number you picked is %d\n", num); return(0); }

5 Find smallest of 3 numbers a<ba<cacb<cbc a,cb,c

6 Find smallest of 3 numbers #include int main(void) { inta, b, c, min; printf("Please enter three numbers: "); scanf("%d%d%d", &a, &b, &c); if(a<b) { if(a<c) { min = a; } else { min = c; } } else { if(b < c) { min = b; } else { min = c; } printf("The smallest of the numbers entered is %d\n", min); return(0); }

7 Find smallest of 3 numbers - redone #include int main(void) { inta, b, c, min; printf("Please enter three numbers: "); scanf("%d%d%d", &a, &b, &c); if(a<b) { if(a < c) min = a; else min = c; } else { if(b < c) min = b; else min = c; } printf("The smallest of the numbers entered is %d\n", min); return(0); }

8 Find smallest of 3 numbers - simpler #include int main(void) { inta, b, c, min; printf("Please enter three numbers: "); scanf("%d%d%d", &a, &b, &c); if(a<b) if(a < c)min = a; elsemin = c; else if(b < c)min = b; elsemin = c; printf("The smallest of the numbers entered is %d\n", min); return(0); }

9 Find smallest of 3 numbers – even simpler #include int main(void) { int a, b, c, min; printf("Please enter three numbers: "); scanf("%d%d%d", &a, &b, &c); min = c; if(a<b && a<c) min = a; else if (b<a && b<c) min = b; printf("The smallest of the numbers entered is %d\n", min); return(0); }


Download ppt "Divisibility Find out if a number, Numb, is divisible by another number, Div. Is 432 divisible by 3? Is 432 divisible by 4? 432 / 3 = ? 432 / 4 = ? 432."

Similar presentations


Ads by Google