Skip to content

Instantly share code, notes, and snippets.

@nandanhere
Created June 23, 2020 12:52
Show Gist options
  • Save nandanhere/8dc308d8038713e2a92676926f2293db to your computer and use it in GitHub Desktop.
Save nandanhere/8dc308d8038713e2a92676926f2293db to your computer and use it in GitHub Desktop.
Some C ideas
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
// function to check if the number entered is prime or not
int prime(int b)
{int i,truth = 1;
for(i = 2;i<(b/2);i++)
{
if(b%i == 0)
{ truth = 0;
break;
}
}
if (truth)
return 1;
else
return 0;
}
// function to print an array
void printArray(int A[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", A[i]);
printf("\n");
}
// function to print a 2d array
void print2d(int arr[100][100],int l,int h)
{
int i, j;
for (int i = 0; i < l; i++) {
for (int j = 0; j < h; j++) {
printf("%d ",arr[i][j]);
}
printf("\n");
}
}
int main(void) {
int f;
scanf("%d",&f);
f = prime(f);
if(f)
printf("Prime");
else
printf("Not");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment