Skip to content

#hacktoberfest | C #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions contribution/jowinjohnchemban/checkifsumofprime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h> //WINDOWS


int checkPrime(int n);

int main()
{
int n, i, flag = 0;

system("CLS");
printf("\n\n\n");
printf("\n\t ######################################");
printf("\n\t # #");
printf("\n\t # CHECK A NUMBER #");
printf("\n\t # REPRESENTED AS #");
printf("\n\t # SUM OF TWO PRIME NUMBERS #");
printf("\n\t # #");
printf("\n\t ######################################\n");

Sleep(2000);
system("CLS");

printf("\n Enter a positive integer : ");
scanf("%d", &n);
printf("\n");


for(i = 2; i <= n/2 && !kbhit() ; ++i)
// iterate till i=n/2 and there is no key pressed - interupt
{
// condition for i to be a prime number
if (checkPrime(i) == 1)
{
// condition for n-i to be a prime number
if (checkPrime(n-i) == 1)
{
// n = primeNumber1 + primeNumber2
printf(" %d = %d + %d\n", n, i, n - i);
flag = 1;
}

}
}

printf("\a");
if (flag == 0)
printf(" %d cannot be expressed as the sum of two prime numbers.\a", n);
// cannot expressed as sum of two prime numbers


getch();
system("CLS");
return 0;
// EXIT
}

// Function to check prime number
int checkPrime(int n)
{
int i, isPrime = 1;

for(i = 2; i <= n/2; ++i)
{
if(n % i == 0)
{
isPrime = 0;
break;
}
}

return isPrime;
}


24 changes: 24 additions & 0 deletions contribution/jowinjohnchemban/prime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>

int main(){

int num,i,count,n;
printf("Enter max range: ");
scanf("%d",&n);

for(num = 1;num<=n;num++){

count = 0;

for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
}

if(count==0 && num!= 1)
printf("%d,",num);
}
return 0;
}