C++

  1. #include <stdio.h>
  2. main()
  3. {
  4.         int ans = 0, num1, num2, loop1, loop2, temp;
  5.         char redo ;
  6.         do
  7.    {
  8.                 printf(“Please enter the First number: “);
  9.                 scanf(“%d”,& num1);
  10.                 printf(“Please enter the Second number: “);
  11.                 scanf(“%d”,& num2);
  12.     if (num2 < num1){
  13.             temp = num1;
  14.              num1 = num2;
  15.             num2 = temp;
  16.     }
  17.                 for (loop1= num1; loop1 <= num2; loop1++)
  18.       {
  19.                         for (loop2 = 2; loop2 <= loop1; loop2++)
  20.          {
  21.                                 ans = loop1 % loop2;
  22.                                 if (ans == 0)
  23.                                 break;
  24.                         }
  25.                         if (loop1 == loop2)
  26.                         {
  27.                                 printf(“%d  “, loop1);
  28.                         }
  29.                 }
  30.                 printf(“.\n\nWould you like to calculate another set of prime numbers?   Y or N: “);
  31.                 scanf(” %c”, &redo);
  32.    }
  33.    while ((redo==’y’)||(redo==’Y’));
  34.         scanf(“”);
  35.         return 0;
  36. }
===================================================

#include <stdio.h>

main()
{

int ans = 0, num1, num2, loop1, loop2, temp;
char redo ;
do
{
printf(“Please enter the First number: “);
scanf(“%d”,& num1);

printf(“Please enter the Second number: “);
scanf(“%d”,& num2);

if (num2 < num1){
temp = num1;
num1 = num2;
num2 = temp;
}

for (loop1= num1; loop1 <= num2; loop1++)
{

for (loop2 = 2; loop2 <= loop1; loop2++)
{
ans = loop1 % loop2;
if (ans == 0)
break;
}

if (loop1 == loop2)
{
printf(“%d  “, loop1);

}
}

printf(“.\n\nWould you like to calculate another set of prime numbers?   Y or N: “);
scanf(” %c”, &redo);
}
while ((redo==’y’)||(redo==’Y’));

scanf(“”);
return 0;
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s