Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Thursday, October 2, 2014

Finding nth prime number (large number) (Optimization)

This was something handy I learned. Actually the problem is pretty easy, but when finding the nth prime where n>1000000 it takes way to long in the conventional way youre thinking. Here is an optimized solution to it, that reduces the time complexity. If you have any doubts, ask!

I think you can even optimize it further by doing p=p+2 and num=num+2. Try it out and see

def prime(chk):
if(chk%2==0):
return False
else:
p=3
while(p<chk**0.5+1):
if(chk%p==0):
return False
p=p+1
return True



def is_prime(x):
count=2
num=4
while(count<x):
if prime(num):
count+=1
num1=num
num=num+1
return num1

result=is_prime("Enter the nth term here")
print result

Saturday, September 27, 2014

Largest Palindrome of 3 Numbers

If you have any doubts, let me know
#include <stdio.h>
#include <string.h>
#include<limits.h>

main()
{
    int i=999,j=999,sum=0,r=0,y,x,sum1=0,a[3000],k=0,temp;
    for(i=999;i>100;i--)
    {
        for(j=999;j>100;j--)
        {
            sum=i*j;
            x=sum;
            while(sum>0)
            {
             sum1=sum1*10;
             sum1=sum1+sum%10;
             sum=sum/10;
            }
            if(sum1==x)
         {
             a[k]=x;
             k++;
         }
            sum1=0;
        }
    }
   
    for(i=0;i<k;i++)
    for(j=0;j<k;j++)
    {
        if(a[i]<a[j])
        {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
printf("%d",a[k-1]);

}

Tuesday, September 23, 2014

String reversal without string.h

This is a program to reverse a string without the string.h header. If you have any doubts, please do ask.

#include<stdio.h>
main()
{
int i,count=0,j=0;
char string[10],final[10];
scanf("%s",string);
for(i=0;string[i]!='\0';i++)
count++;
count--;
for(i=count;i>=0;i--)
{
final[j]=string[i];
j++;
}
final[j]='\0';
printf("%s",final);
}

Monday, September 15, 2014

Decrypting a message program

Feel free to use it, modify it or anything.
Try using the input

y!sr@xo#dt$pa%or^ko*vb(da&ql

You'll get the output laboratory
I've wrote in the comments what each function does. According to that, modify it to make a suitable input


#include <stdio.h>
#include <string.h>
char string[50],t;
int l,k;
main()
{
int i,j;
  
  gets(string);
   printf(" string is %s\n",string);
    l=strlen(string);
    k=l;
    letsreverse();
}
letsreverse() //function reverses a string
{
    
int i=0,j,q;
char *ptr;
ptr=string; 
q=l;
q--;
for(i=0;i<=(l/2)-1;i++)
  {
 t=*(ptr+i);
 *(ptr+i)= *(ptr+q);
 *(ptr+q)=t;
 q--;
 }
 printf("Reverse string is %s\n",string);
 wedontlikejunk();

}
wedontlikejunk()     // kills off junk
 {
    int i=0,z,c=0,x;
    char clean[20];
    for(x=0;x<k;x++)
    {
         if(string[c] >= 'a' && string[c] <= 'z')
         {
         clean[i]=string[c];
         i++;
         }
         c++;
         
    }
    clean[i]='\0';
    printf("semi string is %s\n",clean);
    for(i=0;clean[i]!='\0';i++)
    string[i]=clean[i];
    string[++i]='\0';
    letskillsomeletters();
}
letskillsomeletters()     //kills alternate letters
{
    int i=0,z;
    char final[20];
    for(z=(10%10);z<k;z++)
    {
        final[i]=string[z];
        i++;
        z++;
        
    
    }
    printf("Final string is %s\n",final);
}

Thursday, August 14, 2014

IP address program

Really short C program to print out your ip address. Run it as an .exe. 


#include<stdlib.h>
main()
{
system("C:\\Windows\\System32\\ipconfig");
}

Wednesday, August 13, 2014

Decimal to Binary Program

Simple program to Convert a decimal number to binary. If you have doubts, let me know
#include <stdio.h>
main()
{
int num,count,temp;
printf("Enter the number");
scanf("%d",&num);
for(count=31;count>= 0;count--)
{
temp=num>>count;
if(temp&1)
printf("1");
else
printf("0");
}
}

Tuesday, August 12, 2014

Program to read from file

Program to read from a file. If you have any doubts, let me know

#include <stdlib.h>
#include <stdio.h>
main()
{
char x, name[100];
FILE *pf;
    printf("Name of file?");
    gets(name);
    pf = fopen(name,"r");
    printf("Contents are :");
         while((x=fgetc(pf))!= EOF)
         printf("%c",x);
    }

Saturday, August 9, 2014

Program to find twin prime numbers.

Program to find twin prime numbers. Please comment if you need help.

#include<stdio.h>
void main( )
{
int  i,n,k,r,a[50],p;
printf("nEnter the range:  ");
scanf("%d", &r);
i=1;
p=0;
while(i<=r)
{
k=0;
n=1;
while(n<=i)
{
if( i%n==0 )
k++;
n++;
}
if(k==2)
{
a[p]=i;
p++;
}
i++;
}
for(n=0;n<p;n++)
{
if(a[n+1] - a[n]==2)
printf("\n%d and %d are twin primes", a[n], a[n+1]);
}
}

Program to implement Fibonacci series

Program to implement Fibonacci series. Comment if you need any help.

#include<stdio.h>
int fibo(int x);
main()
{
int n,i,ar[50];
printf("\n  enter the number of terms:");
scanf("%d",&n);
ar[0]=0;
for(i=1;i<n;i++)
{
ar[i]=fibo(i);
}
printf("\n");
for(i=0;i<n;i++)
printf("%d ",ar[i]);
printf("\n");
}
int fibo(int c)
{
int fib=0;
if((c==1)||(c==2))
return 1;
else
{
fib=fibo(c-1)+fibo(c-2);
return fib;
}
}





Program to write to a file and display the vowel which occurred the most

Program to write to a file and display the vowel which occurred the most often. If you need help comment below

#include<stdio.h>
main()
{
  FILE *f1;
  char c;
  int a,e,i,o,u;
  a=0;
  e=0;
  i=0;
  u=0;
  o=0;
  printf("\nEnter the letters to the file:\n");
  f1=fopen("TEXT.txt","w");
  while((c=getchar())!='\n')
    putc(c,f1);
  fclose(f1);
  f1=fopen("TEXT.txt","r");
  while((c=getc(f1))!=EOF)
   {
     if(c=='a')
       a++;
     else if(c=='e')
       e++;
     else if(c=='i')
       i++;
     else if(c=='o')
       o++;
     else if(c=='u')
       u++;
   }
  fclose(f1);
  if((a>=e)&&(a>=i)&&(a>=o)&&(a>=u))
   printf("\n\n'a'is the vowel which occured the most.\n%d times",a);
  if((e>=a)&&(e>=i)&&(e>=u)&&(e>=o))
   printf("\n\n'e' is the vowel which occured the most.\n%d times",e);
  if((i>=a)&&(i>=e)&&(i>=o)&&(i>=u))
   printf("\n\n'i' is the vowel which occured the most.\n%d times",i);
  if((o>=a)&&(o>=e)&&(o>=i)&&(o>=u))
   printf("\n\n'o'is the vowel which occured the most.\n%d times",o);
  if((u>=a)&&(u>=e)&&(u>=i)&&(u>=o))
   printf("\n\n'u' is the vowel which occured the most.\n%d times",u);
  printf("\n\n");
}

Program for various operations with doubly link list

Program for the various operations with a doubly link list. Comment below if you need help

#include<stdio.h>

#include<stdlib.h>

struct node

{

 int data;

 struct node *next,*prev;

}*start=NULL,*newn,*temp,*ptr;

int num,pos,ele;

void insert_beg();

void insert_beg();

void insert_end();

void insert_aftr();

void insert_pos();

void delete_beg();

void delete_end();

void delete_ele();

void display();

main()

{

 int ch,c,ch1,p,ch2,q;

 do

 {

 printf("\n DLL MENU\n1.Ins\n2.Del\n3.Disp");

 printf("\nEnter the number corresponding to your operation:");

 scanf("%d",&ch);

 switch(ch)

 {

 case 1:do

 {

 printf("\nINSERT MENU\n1.beginning\n2.End\n3.After a node\n4.at a

position\n5.Display");

 printf("\nEnter your choice:");

 scanf("%d",&ch1);

 switch(ch1)

 {

 case 1:insert_beg();

 break;

 case 2:insert_end();

 break;

 case 3:insert_aftr();

 break;

 case 4:insert_pos();

 break;

 case 5:display();

 break;

 default:printf("\nWrong Choice\n");

 break;

 }

 printf("\nDo you want to continue-Insert Menu?(1.Yes;2.No)");

 scanf("%d",&p);

 }while(p!=2);

 break;

 case 2:do

 {

 printf("\nDELETE MENU\n1.Front\n2.End\n3.A specific node\n4.Display");

 printf("\nEnter your choice:");

 scanf("%d",&ch2);

 switch(ch2)

 {

 case 1:delete_beg();

 break;

 case 2:delete_end();

 break;

 case 3:delete_ele();

 break;

 case 4:display();

 break;

 default:printf("\nWrong Choice\n");

 break;

 }

 printf("\nDo you want to continue-Delete Menu?(1.Yes;2.No):");

 scanf("%d",&q);

 }while(q!=2);

 break;

 case 3:display();

 break;

 default:printf("\nWrong Choice\n");

 break;

 }

 printf("\nDo you want to continue-Main Menu?(1.Yes;2.No):");

 scanf("%d",&c);

 }while(c!=2);

}

void display()

{

 if(start==NULL)

 printf("\nLink List is empty\n");

 else

 {

 temp=start;

 while(temp->next!=NULL)

 {

 printf("%d<->",temp->data);

 temp=temp->next;

}

printf("%d",temp->data);

 }

}

void insert_beg()

{

 printf("\nEnter the element to be inserted:");

 scanf("%d",&num);

 newn=(struct node*)malloc(sizeof(struct node));

 newn->data=num;

 if(start==NULL)

 {

 newn->next=NULL;

 newn->prev=NULL;

 }

 else

 {

 newn->prev=NULL;

 newn->next=start;

 start->prev=newn;

 }

 start=newn;

}

void insert_end()

{

 printf("\nEnter the element to be inserted:");

 scanf("%d",&num);

 newn=(struct node*)malloc(sizeof(struct node));

 newn->data=num;

 if(start==NULL)

 {

 newn->next=NULL;

 newn->prev=NULL;

 start=newn;

 }

 else

 {

 temp=start;

 while(temp->next!=NULL)

 {

 temp=temp->next;

 }

 temp->next=newn;

 newn->prev=temp;

 newn->next=NULL;

 }

}

void insert_aftr()

{

 int flag=0;

 if(start==NULL)

 printf("\nLink List is empty\n");

 else

 {

 printf("\nEnter the element after which insertion must be done:");

 scanf("%d",&ele);

 printf("\nEnter the element to be inserted:");

 scanf("%d",&num);

 newn=(struct node*)malloc(sizeof(struct node));

 newn->data=num;

 temp=start;

 while(temp!=NULL)

 {

 if(temp->data==ele)

 {

 if(temp->next==NULL)

 insert_end();

 else

{ newn->next=temp->next;

 newn->prev=temp;

 temp->next->prev=newn;

 temp->next=newn;

 }

 flag=1;

 break;

 }

 temp=temp->next;

 }

 if(flag==0)

 printf("\nElement not found\n");

 }

}

void insert_pos()

{

 int k=1,flag=0;

 printf("\nEnter the position for insertion:");

 scanf("%d",&pos);

 if(pos==1)

 insert_beg();

 else

 {

 printf("\nEnter the element to be inserted:");

 scanf("%d",&num);

 newn=(struct node*)malloc(sizeof(struct node));

 newn->data=num;

 temp=start->next;

 while(temp!=NULL)

 {

 k++;

 if(k==pos)

 {

 newn->next=temp;

 temp->prev->next=newn;

 newn->prev=temp->prev;

 temp->prev=newn;

 flag=1;

 break;

 }

 temp=temp->next;

 }

 if(flag==0)

 printf("\nPosition not found\n");

 }

}

void delete_beg()

{

 if(start==NULL)

 printf("\nLL is empty\n");

 else

{

 if(start->next==NULL)

{

free(start);

start=NULL;

}

else

 {

 temp=start;

 start=start->next;

 start->prev=NULL;

 free(temp);

 }

}

}

void delete_end()

{

 if(start==NULL)

 printf("\nLL is empty\n");

 else if(start->next==NULL)

 delete_beg();

 else

 {ptr =temp;

 temp=start;

 while(temp->next!=NULL)

 {

 temp=temp->next;

 }

 temp->prev->next=NULL;

 free(temp);

 }

}

void delete_ele()

{

 int flag=0;

 if(start==NULL)

 printf("\nLL is empty\n");

 else

 {

 printf("\nEnter the element to be deleted:");

 scanf("%d",&num);

 temp=start;

 while(temp!=NULL)

 {

 if(start->data==num)

 {

 delete_beg();

 flag=1;

 temp=start;

 break;

 }

 else if(temp->data==num)

 {

 if(temp->next==NULL)

 {

 delete_end();

 flag=1;

 break;

 }

 else

 {

 ptr=temp;

 temp->prev->next=temp->next;

 temp->next->prev=temp->prev;

 free(ptr);

 flag=1;

 break;

 }

 }

 temp=temp->next;

 }

 if(flag==0)

 printf("\nElement not found\n");

 }

}

Program for various operations of Binary Search Tree

Programs for the various operations of a binary search tree. Really lengthy program, but its not so bad if you know the logic. Comment below if you need help

#include<stdio.h> #include<stdlib.h> #define max(A,B) (((A)>(B))?(A):(B)) struct node { int data; struct node *rc,*lc; }*newn,*ptr=NULL,*pre=NULL,*root=NULL,*succ=NULL; void ins(); void del(int); void inorder(struct node *temp); void preorder(struct node *temp); void postorder(struct node *temp); void display(struct node*); void trav(); int height(struct node*); int depth(struct node*); int level(struct node*); main() { int ch,r,x,h,l,d; do { printf("\nMenu for BST:\n1.Ins\n2.Del\n3.Traverse\n4.Lvl\n5.Hght\n6.Disp\n"); printf("\nChoice?:"); scanf("%d",&ch); switch(ch) { case 1: ins(); break; case 2: printf("Enter element the element you wish to insert:"); scanf("%d",&x); del(x); break; case 3: display(root); break; case 4:l=level(root); printf("\nthe maximum level of the ttree is:%d",l); break; case 5:h=height(root); printf("\nheight of the tree is:%d",h); break; case 6:display(root); break; case 7:break; default: printf("\nWrong choice\n"); break; } }while(ch!=7); } void ins() { int d,flag=0; ptr=root; printf("\nEnter the element:"); scanf("%d",&d); newn=(struct node*)malloc(sizeof(struct node)); newn->data=d; newn->lc=NULL; newn->rc=NULL; while((ptr!=NULL)&&(flag==0)) { if(d<ptr->data) { pre=ptr; ptr=ptr->lc; } else if(d>ptr->data) { pre=ptr; ptr=ptr->rc; } else { flag=1; printf("Element already exists!"); } } if(ptr==NULL) { if(root==NULL) { root=newn; ptr=root; } else if(pre->data<d) { pre->rc=newn; ptr=pre->rc; } else { pre->lc=newn; ptr=pre->lc; } } } void del(int x) { ptr=root; while(ptr!=NULL) { if(x<ptr->data) { pre=ptr; ptr=ptr->lc; } else if(x>ptr->data) { pre=ptr; ptr=ptr->rc; } else if(ptr->data==x) { if(ptr->lc==NULL&&ptr->rc==NULL) { if(ptr==root) { free(root); root=NULL; break; } else if(pre->lc==ptr) pre->lc=NULL; else if(pre->rc==ptr) pre->rc=NULL; free(ptr); break; } else if(ptr->lc!=NULL&&ptr->rc==NULL) { if(pre->lc==ptr) pre->lc=ptr->lc; else if(pre->rc==ptr) pre->rc=ptr->lc; free(ptr); break; } else if(ptr->lc==NULL&&ptr->rc!=NULL) { if(pre->lc==ptr) pre->lc=ptr->rc; else if(pre->rc==ptr) pre->rc=ptr->rc; free(ptr); break; } else if(ptr->lc!=NULL&&ptr->rc!=NULL) { succ=ptr->rc; if(succ->lc==NULL) { if(pre->lc==ptr) { pre->lc=succ; succ->lc=ptr->lc; } else if(pre->rc==ptr) { pre->rc=succ; succ->rc=ptr->rc; } free(ptr); break; } else { while(succ->lc!=NULL) { pre=succ; succ=succ->lc; } } ptr->data=succ->data; pre->lc=succ->rc; free(ptr); break; } } } if(ptr==NULL) { printf("\nElement absent\n"); } } void postorder(struct node *temp) { if(temp!=NULL) { postorder(temp->lc); postorder(temp->rc); printf(" %d",temp->data); } } void preorder(struct node *temp) { if(temp!=NULL) { printf(" %d",temp->data); preorder(temp->lc); preorder(temp->rc); } } void display(struct node *root1) { int i; if(root1==NULL) printf("Empty tree!"); printf("\nEnter the order\n1:inorder\n2:preorder\n3:postorder\n"); scanf("%d",&i); if(i==1) { printf("\nINORDER:\n"); inorder(root1); } else if(i==2) { printf("\nPREORDER:\n"); preorder(root1); } else { printf("\nPOSTORDER:\n"); postorder(root1); } } void inorder(struct node *temp) { if(temp!=NULL) { inorder(temp->lc); printf(" %d",temp->data); inorder(temp->rc); } } int height(struct node *root) { if(root==NULL) return 0; else return(max(height(root->lc),height(root->rc))+1); } int level(struct node *root) { if(root==NULL) return 0; else return max(height(root->lc),height(root->rc));

Program for merge sort.

Program for merge sort. If you need help, feel free to ask.

#include<stdio.h> void mergesort(int x[20],int n) { int temp[20],i,j,k,l1,l2,size,u1,u2,a; size=1; while(size<n) { l1=0; k=0; while(l1+size<n) { l2=l1+size; u1=l2-1; u2=((l2+size-1<n)?l2+size-1:n-1); for(i=l1,j=l2;i<=u1&&j<=u2;k++) { if(x[i]<=x[j]) { temp[k]=x[i]; i++; } else { temp[k]=x[j]; j++; } } for(;i<=u1;k++) { temp[k]=x[i]; i++; } for(;j<=u2;k++) { temp[k]=x[j]; j++; } l1=u2+1; } for(i=l1;k<n;k++) temp[k++]=x[i]; for(i=0;i<n;i++) x[i]=temp[i]; size=size*2; printf("\n"); for(a=0;a<n;a++) printf("%d ",x[a]); printf("\n"); } } main() { int x[20],n,i; printf("\nEnter the value of the number of elements you wish to enter\n"); scanf("%d",&n); printf("\nEnter values of the elements you wish to sort"); for(i=0;i<n;i++) scanf("%d",&x[i]); printf("\nBefore Sorting this is how it looks\n:"); for(i=0;i<n;i++) printf(" %d",x[i]); mergesort(x,n); }

DFS and BFS of a tree

Program for DFS and BFS of a tree. Comment below if you need help

#include<stdio.h> int adj[50][50]; int visited[50]; void adjcreate(); void dfs(int); void bfs(int); int n; main() { int i, v, ch; adjcreate(); do { printf("\nMENU:\n1.DFS\n2.BFS\n3.Exit\n"); printf("Enter your choice:"); scanf("%d",&ch); switch (ch) { case 1: printf("\nEnter starting node for Depth First Search:"); scanf("%d",&v); for (i=1;i<=n;i++) visited[i]=0; dfs(v); break; case 2: printf("\nEnter starting node for Breadth First Search:"); scanf("%d",&v); for (i=1;i<=n;i++) visited[i]=0; bfs(v); break; case 3: break; default: printf("Wrong choice!\n"); break; } }while(ch!=3); } void adjcreate() { int i,j,ch; printf("Enter number of nodes :"); scanf("%d", &n); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf("\n Press 1 if %d connected to %d",i,j); scanf("%d",&ch); if(ch==1) { adj[i][j]=1; } else { adj[i][j]=0; } } } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) printf(" %d ",adj[i][j]); printf("\n"); } } void dfs(int v) { int i,stack[50],top=-1,pop; top++; stack[top]=v; while(top>=0) { pop=stack[top]; top--; if(visited[pop]==0) { printf("%d ",pop); visited[pop]=1; } else continue; for(i=n;i>=1;i--) { if(adj[pop][i]==1&&visited[i]==0) { top++; stack[top]=i; } } } } void bfs(int v) { int i,front,rear; int que[50]; front=rear=-1; printf("%d ",v); visited[v]=1; rear++; front++; que[rear]=v; while(front<=rear) { v=que[front]; front++; for (i=1;i<=n;i++) { if (adj[v][i]==1&&visited[i]==0) { printf("%d ",i); visited[i]=1; rear++; que[rear]=i; } } } }

Library details of a book program

Program to enter library details of a book, then listing the book details on search. Simple and straightforward.
#include<stdio.h>
#include<string.h>
main()
{
 int i,j,n,flag=0;
 char title[20];
 printf("Enter the value of n\n");
 scanf("%d",&n);
 struct book
 {
  char authorname[20];
  char bookname[20];
  int price;
 } b[n];
 for(i=0;i<n;i++)
 {
  printf("Enter the name of the author:\n");
  scanf("%s",&b[i].authorname);
  printf("Enter the name of the book:\n");
  scanf("%s",&b[i].bookname);
  printf("Enter the price:\n");
  scanf("%d",&b[i].price);
 }
  printf("Enter the title of the book you want to search\n");
  scanf("%s",title);
  for(i=0;i<n;i++)
  {
   if(strcmp(b[i].bookname,title)==0)
   {
    flag=1;
    printf("\n\n\n");
    printf("The author of the book is:");
    printf("%s",b[i].authorname);
    printf("\n");
    printf("The price of the book is:");
    printf("%d",b[i].price);
}
}
    if(flag==0)
    printf("The book is not found\n");

}

Program to swap two numbers

Program to swap two numbers with address and pointers. Again, a necessary program for all amateur CSE students.

#include<stdio.h>
void swap(int *x,int *y)
{
 int temp;
 temp=*x;
 *x=*y;
 *y=temp;
}
void main()
{
  int a,b;
  printf("Enter the number a:");
  scanf("%d",&a);
  printf("\n Enter the number b:");
  scanf("%d",&b);
  swap(&a,&b);
  printf("\n a contain %d",a);
  printf("\n b contain %d",b);
}

Program to reverse a string

Program to reverse a string. You'll need to work with pointers in this program. If you need help, comment below

#include<stdio.h> #include<string.h> main() { char *ptr; char string[50],t; int i,j,l; ptr=string; printf("\nEnter the string"); gets(string); l=strlen(string); for(i=0,j=l-1;i<=(l-1)/2;i++,j--) { t= *(ptr+i); *(ptr+i)= *(ptr+j); *(ptr+j)=t; } printf("Reverse string is %s\n",string); }

Factorial program of a number

Simple C program to find factorial of a number. If you need help please feel free to ask

#include <stdio.h> main() {int fact,n; printf("enter a number\n"); scanf("%d",&n); for(fact=1;n>0;n--) fact=fact*n; printf("factorial of the number is %d\n",fact); }

Program to convert Celsius to Fahrenheit and vice versa

Simple C program to convert Celsius to Fahrenheit and vice versa. If you have any doubts, please comment below.
#include<stdio.h> void main() { int a; float c,f; printf("choose 1 for c and 2 for f"); scanf("%d",&a); if (a==1) { printf("enter in c"); scanf("%f",&c); f=(9.0/5.0)*(c+32); printf("temo in f is %f",f); } if(a==2) { printf("enter in f"); scanf("%f",&f); c=(5.0/9.0)*(f-32); printf("temp in c is %f",c); } }

Program to count number of occurrences of a word in a sentence.

Simple C program to count the number of occurrences of a word in a sentence. If you need help, feel free to ask.


#include<stdio.h>
#include<string.h>
main()
{
  int len,c=0,i=0,j=0,ans=0;
  char str1[50],str2[20],new[20];
  printf("\n enter the text: ");
  gets(str1);
  printf("\n enter the word: ");
  gets(str2);
  len=strlen(str1);
  for(i=0;i<=len;i++)
   {
     if(str1[i]!=' ')
      {
       new[j]=str1[i];
       j++;
      }
     if(str1[i]==' '||str1[i]=='\0')
       {
           new[j]='\0';
           j=0;
           ans=strcmp(new,str2);
           if(ans==0)
             c++;
        }
    }
   printf("\n the number of occurence is %d\n",c);
}