Skip to content
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
45 changes: 45 additions & 0 deletions Loops/CNT_PRM.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include<stdio.h>
#include<conio.h>
#include<math.h>

int prime(int a)
{
int i;
if(a==1 || a==0)
return 0;

for(i=2; i<=sqrt(a); i++)
{

if(a%i==0)
return 0;
}
return 1;
}

int count(int a, int b)
{
int c = 0,i;
for(i=a; i<=b; i++)
{
if(prime(i))
c++;
}
return c;
}

void main()
{
int a,b;
clrscr();

printf("Enter the lower number :: ");
scanf("%d",&a);

printf("Enter the higher number :: ");
scanf("%d",&b);

printf("Number of prime numbers :: %d",count(a,b));
getch();
}

68 changes: 68 additions & 0 deletions TREETRAV.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include<stdio.h>
#include<conio.h>
struct node
{ struct node* left; int data; struct node* right; };

struct node* create(int data)
{
struct node* newNode=(struct node*)malloc(sizeof(struct node));
newNode->data = data;
newNode->left='\0';
newNode->right = '\0';
return newNode;
}

struct node* insert(struct node* t, int data)
{
if(t=='\0') return create(data);
if(data < t->data)
t->left = insert(t->left, data);
else if(data > t->data)
t->right = insert(t->right, data);
return t;
}

void inorder(struct node* t)
{
if(t=='\0') return;
inorder(t->left);
printf("%d ",t->data);
inorder(t->right);
}

void preorder(struct node* t)
{
if(t=='\0') return;
printf("%d ",t->data);
preorder(t->left);
preorder(t->right);
}

void postorder(struct node* t)
{
if(t=='\0') return;
postorder(t->left);
postorder(t->right);
printf("%d ",t->data);
}

void main()
{
struct node *root='\0';
clrscr();
root = insert(root,8);
insert(root,3);
insert(root,1);
insert(root,6);
insert(root,7);
insert(root,10);
insert(root,14);
insert(root,4);
printf("Inorder\n");
inorder(root);
printf("\nPreorder\n");
preorder(root);
printf("\nPostorder\n");
postorder(root);
getch();
}