Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to print the integers between 100 and 999 inclusive are divisible by three or four in C++

1 Answer

0 votes
#include <iostream>

int main(void)
{
    int total = 0;
    
    for (int num = 100; num <= 999; ++num) {
        if (num % 3 == 0 || num % 4 == 0) {
            std::cout << num << " ";
            total++;
            if (total % 20 == 0) {
                std::cout << "\n";
            }
        }
    }
    
    std::cout << "\n\ntotal: " << total << "\n";
}
 
 
 
/*
run:
 
100 102 104 105 108 111 112 114 116 117 120 123 124 126 128 129 132 135 136 138 
140 141 144 147 148 150 152 153 156 159 160 162 164 165 168 171 172 174 176 177 
180 183 184 186 188 189 192 195 196 198 200 201 204 207 208 210 212 213 216 219 
220 222 224 225 228 231 232 234 236 237 240 243 244 246 248 249 252 255 256 258 
260 261 264 267 268 270 272 273 276 279 280 282 284 285 288 291 292 294 296 297 
300 303 304 306 308 309 312 315 316 318 320 321 324 327 328 330 332 333 336 339 
340 342 344 345 348 351 352 354 356 357 360 363 364 366 368 369 372 375 376 378 
380 381 384 387 388 390 392 393 396 399 400 402 404 405 408 411 412 414 416 417 
420 423 424 426 428 429 432 435 436 438 440 441 444 447 448 450 452 453 456 459 
460 462 464 465 468 471 472 474 476 477 480 483 484 486 488 489 492 495 496 498 
500 501 504 507 508 510 512 513 516 519 520 522 524 525 528 531 532 534 536 537 
540 543 544 546 548 549 552 555 556 558 560 561 564 567 568 570 572 573 576 579 
580 582 584 585 588 591 592 594 596 597 600 603 604 606 608 609 612 615 616 618 
620 621 624 627 628 630 632 633 636 639 640 642 644 645 648 651 652 654 656 657 
660 663 664 666 668 669 672 675 676 678 680 681 684 687 688 690 692 693 696 699 
700 702 704 705 708 711 712 714 716 717 720 723 724 726 728 729 732 735 736 738 
740 741 744 747 748 750 752 753 756 759 760 762 764 765 768 771 772 774 776 777 
780 783 784 786 788 789 792 795 796 798 800 801 804 807 808 810 812 813 816 819 
820 822 824 825 828 831 832 834 836 837 840 843 844 846 848 849 852 855 856 858 
860 861 864 867 868 870 872 873 876 879 880 882 884 885 888 891 892 894 896 897 
900 903 904 906 908 909 912 915 916 918 920 921 924 927 928 930 932 933 936 939 
940 942 944 945 948 951 952 954 956 957 960 963 964 966 968 969 972 975 976 978 
980 981 984 987 988 990 992 993 996 999 

total: 450
 
*/

 



answered Aug 5, 2024 by avibootz

Related questions

...