display all the twin prime no. within 2 to 200
Answers
Answered by
0
please specify the logic of twin prime no. i know prime no. be i dont know twin prime no.
Answered by
1
Hi there!
Here's the answer:
•°•°•°•°•°<><><<><>><><>°•°•°•°•°•°
¶¶ Twin Prime Numbers ¶¶
¶ Twin prime are the consecutive odd numbers which are both prime.
¶ Eg: (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), (59, 61), (71, 73) etc
•°•°•°•°•°<><><<><>><><>°•°•°•°•°•°
/* C- Program to display the twin prime numbers from 1 to given range. */
#include <stdio.h>
#include <stdlib.h>
int main()
{
…int i,j,count,num,add=0;
…int arr[10000];
…printf( "Enter the max value upto which you want to check the Twin Primes\n" );
…scanf( "%d" ,&num);
…for (i=3;i<num;i++)
……{
………count = 0;
………for (j=2;j<i;j++)
……………{
…………………if(i%j == 0)
………………………count++;
……………}
………if (count==0)
…………{
……………arr[add] = i;
……………add++;
…………}
……}
…printf( "\nTwin Primes are : \n" );
…for (i=1;i<add;i++)
……{
…………if (arr[i] == arr[i-1] +2)
……………………printf( "%d %d\n" ,arr[i-1],arr[i]);
……}
…return 0;
}
•°•°•°•°•°<><><<><>><><>°•°•°•°•°•°
// Output:
Enter the max value upto which you want to check the Twin Primes
200
Twin Primes are :
3 5
5 7
11 13
17 19
29 31
41 43
59 61
71 73
101 103
107 109
137 139
149 151
179 181
191 193
197 199
•°•°•°•°•°<><><<><>><><>°•°•°•°•°•°
©#£€®$
:)
Hope it helps
Here's the answer:
•°•°•°•°•°<><><<><>><><>°•°•°•°•°•°
¶¶ Twin Prime Numbers ¶¶
¶ Twin prime are the consecutive odd numbers which are both prime.
¶ Eg: (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), (59, 61), (71, 73) etc
•°•°•°•°•°<><><<><>><><>°•°•°•°•°•°
/* C- Program to display the twin prime numbers from 1 to given range. */
#include <stdio.h>
#include <stdlib.h>
int main()
{
…int i,j,count,num,add=0;
…int arr[10000];
…printf( "Enter the max value upto which you want to check the Twin Primes\n" );
…scanf( "%d" ,&num);
…for (i=3;i<num;i++)
……{
………count = 0;
………for (j=2;j<i;j++)
……………{
…………………if(i%j == 0)
………………………count++;
……………}
………if (count==0)
…………{
……………arr[add] = i;
……………add++;
…………}
……}
…printf( "\nTwin Primes are : \n" );
…for (i=1;i<add;i++)
……{
…………if (arr[i] == arr[i-1] +2)
……………………printf( "%d %d\n" ,arr[i-1],arr[i]);
……}
…return 0;
}
•°•°•°•°•°<><><<><>><><>°•°•°•°•°•°
// Output:
Enter the max value upto which you want to check the Twin Primes
200
Twin Primes are :
3 5
5 7
11 13
17 19
29 31
41 43
59 61
71 73
101 103
107 109
137 139
149 151
179 181
191 193
197 199
•°•°•°•°•°<><><<><>><><>°•°•°•°•°•°
©#£€®$
:)
Hope it helps
Similar questions