1 / 9

Divisibility

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 = ?. Divisibility. #include < stdio.h > int main(void) { int num, div;

cedric
Download Presentation

Divisibility

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 <stdio.h> • 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 4,5 1,2,3 1,2

  4. Pick a number between 1 and 5 #include <stdio.h> int main(void) { intansw; 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; else num=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,c b,c

  6. Find smallest of 3 numbers #include <stdio.h> int main(void) { int a, 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 <stdio.h> int main(void) { int a, 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 <stdio.h> int main(void) { int a, 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); }

  9. Find smallest of 3 numbers – even simpler #include <stdio.h> 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); }

More Related