Skip to main content

C Sample: A Structured ARRAY Operation Over User define function


#include<stdio.h>
#include<conio.h>
int x[50],ic=0,fg=0;
main()
{
int c=0,f=0;
clrscr();
for(c=0;c<=49;c++)
{
if(x[c]!=0)
{
f++;
}
}
printf("\n\t\tEXAMPLE::1 DIMENTIONAL ARRAY- AS A DATA STRUCTURE\n\t\t\tAL/22/09-Dibyendu Swar (Sonu)\n\n");
printf("\n\t\tCHOICES\n");
printf("\n\t\t1.INSERT [%d]\n\t\t2.MODIFY\n\t\t3.DISPLAY\n\t\t4.QUIT\n\t\t5.DELETE\n\t\t6.ARRANGE DATA",f);
printf("\n\n\t\tYOUR CHOICE::");
   scanf("%d",&c);
   if(c==1)
   {
ins();
getch();
   }
   else if(c==3)
   {
dispc();
getch();
   }
   else if(c==2)
   {
modify();
getch();
   }
   else if(c==4)
   {
exit();
   }
   else if(c==5)
   {
dlete();
getch();
   }
   else if(c==6)
   {
  arng();
getch();
   }
   else
   {
main();
   }




   getch();
// return;
}


ins()
{
int i,c=0,cc=0;
printf("\n\t\tHOW MANY NO TO ADD (1-50)?");
scanf("\n%d",&c);
if(c+ic>50)
{
printf("\n\t\tINVALID INPUT");
main();
}
else
{


for(i=0;i<49;i++)
{
if(x[i]!=0)
{
fg=i;
}
}
if(fg==0)
{
cc=0;
}
else
{
cc=fg+1;
}


for(i=cc;i<cc+c;i++)
{
printf("\n\t\tENTER NO %d [AT ANY TIME ENTER 0-ZERO TO BREAK]:",i+1);
scanf("%d",&x[i]);
ic=i;
fg=1;
if(x[i]==0)
{
main();
}
}
}
main();
// return;
}


modify()
{
int c,i,flag;
printf("\n\t\tCHOICE:: \n\t\t1.PROGRESSIVE\n\t\t2.DIRECT MARGE");
scanf("%d",&c);
if(c==1)
{
printf("\n\t\tMODIFICATION\n");
printf("\n\t\tCHOICE:: \n\t\t1.AT SPECIFIC POSITION\n\t\t2.END OF POSITION");
scanf("\n%d",&c);
if(c==1)
{
printf("\n\t\tENTER POSITION (1-5)");
scanf("\n%d",&c);
if(c>50)
{
printf("\n\t\tINVALID POSITION");
main();
}


c=c-1;
if(x[49]==0)
{
for(i=49;i>c;i--)
{
flag=x[i-1];
x[i]=flag;
}
printf("\n\t\tEnter The No :: ");
scanf("%d",&flag);
x[c]=flag;
}
else
{
printf("\n\t\tENTER THE NO:: ");
scanf("%d",&flag);
x[c]=flag;
}
}
else if(c==2)
{
for(i=0;i<49;i++)
{
if(x[i]!=0)
{
flag=i+1;
}
}


if(flag>49)
{
printf("\n\t\tNOT POSSIBLE-ALL Filled!");
}
else
{
printf("\n\t\tENTER THE No:: ");
scanf("%d",&c);
x[flag]=c;
}
}
}
else
{
printf("\n\t\tENTER THE POSITION:: ");
scanf("%d",&c);
printf("\n\t\tENTER THE VALUE:: ");
scanf("%d",&x[c-1]);
}
main();
}


dispc()
{
int i,j;
printf("\n\t\tDISPLAY VALUES CHOICE::\n\t\t1.DISPLAY ALL\n\t\t2.SEARCH");
scanf("%d",&i);
if(i==1)
{
for(i=0;i<49;i++)
{
if(x[i]!=0)
{
printf(" |%d|-> %d ",i+1,x[i]);
}
}
}
else if(i==2)
{
printf("\n\t\tENTER THE VALUE TO SEARCH:: ");
scanf("%d",&j);
for(i=0;i<=49;i++)
{
if(x[i]==j)
{
printf("\n\t\t%d FOUND AT %d PONT",j,i+1);
}
}
}
else
{
printf("\n\t\tInvalid Choise!");
}
getch();
main();
// return;
}


dlete()
{
int i,c,d;
printf("\n\t\tCHOICE::\n\t\t1.DELETE SPECIFIED ENTRY\n\t\t2.DELETE A RANGE OF ENTRIES\n\t\t3.SEARCH AND DELETE");
scanf("%d",&c);


if(c==1)
{
printf("\n\t\tDELETE:\n\t\tENTER THE ENTRY NO TO DELETE::");
scanf("%d",&c);
x[c-1]=0;
}
else if(c==2)
{
printf("\n\t\tDELETE RANGE:: \n\t\tENTER START POINT::");
scanf("%d",&c);
printf("\n\t\tENTER STOP POINT::");
scanf("%d",&d);
for(i=c-1;i<d;i++)
{
x[i]=0;
}
}
else if(c==3)
{
printf("\n\t\tSEARCH & DELETE:: \n\t\tENTER VALUE TO SEARCH:: ");
scanf("%d",&c);
for(i=0;i<=49;i++)
{
if(c==x[i])
{
printf("\n\t\t%d FOUND AT %d POINT",c,i+1);
printf("\n\t\t1.DELETE CURRENT OCCOURANCE?\n\t\t2.SKIP");
scanf("%d",&d);
if(d==1)
{
x[i]=0;
}
}
}
}




main();
}


//Arranging Data
 arng()
 {
 int i,min,j,buf[49];
 printf("\n\t\tCHOICR:\n\t\t1.ASCENDING ORDER\n\t\t2.DESCENDING ORDER\n\t\t3.BOTH");
for(i=0;i<=49;i++)
{
if(x[i]!=0)
{
buf[i]=x[i];
}
else
{
buf[i]=0;
}
}
printf("\n\n\t\tSOURCE ELEMENTS ARE\n\n");


for(i=0;i<=49;i++)
{
for(j=0;j<=49;j++)
{
if(buf[i]>buf[j])
{
min=buf[i];
buf[i]=buf[j];
buf[j]=min;
}
}
}
for(i=0;i<=49;i++)
{
if(x[i]!=0)
{
printf("%d\t",x[i]);
}
}
printf("\n\n\t\tYOUR CHOICE:: ");
scanf("%d",&i);


if(i==1)
{
printf("\n\n\t\tASCENDING ORDER\n\n");


for(i=49;i>=0;i--)
{
if(buf[i]!=0)
{
printf("%d\t",buf[i]);
}
}


getch();
main();
}
else if(i==2)
{
printf("\n\t\tDESCENDING ORDER\n\n");


for(i=0;i<=49;i++)
{
if(buf[i]!=0)
{
printf("%d\t",buf[i]);
}
}


getch();
main();
}
else if(i==3)
{


printf("\n\t\tASCENDING ORDER\n\n");
for(i=49;i>=0;i--)
{
if(buf[i]!=0)
{
printf("%d\t",buf[i]);
}
}


printf("\n\t\tDESCENDING ORDER\n\n");


for(i=0;i<=49;i++)
{
if(buf[i]!=0)
{
printf("%d\t",buf[i]);
}
}
getch();
main();
}
else
{
printf("\n\t\tInvalid Choice");
getch();
main();
}
}

Comments

Popular posts from this blog

Sample : String Reverse In Java

import java.io.*; class test {     public static void main(String args[])     {         DataInputStream in=new DataInputStream(System.in);         try         {             String text;             System.out.println("\nEnter The Text");             text=in.readLine();             System.out.println("\nIn Reverse Order::\n");             for(int i=text.length()-1;i>=0;i--)             {                 System.out.print(text.charAt(i));             }          ...

Using GREP in UNIX

How To Use grep Command In Linux / UNIX by  VIVEK GITE  on  AUGUST 2, 2007  ·  147 COMMENTS H ow do I use grep command in Linux? grep command searches the given file for lines containing a match to the given strings or words. By default, grep prints the matching lines. Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines. The name, "grep", derives from the command used to perform a similar operation, using the Unix/Linux text editor ed: g/re/p grep command syntax grep 'word' filename grep 'string1 string2' filename cat otherfile | grep 'something' command | grep 'something' Use grep to search file Search /etc/passwd for boo user: $ grep boo /etc/passwd You can force grep to ignore word case i.e match boo, Boo, BOO and all other combination with -i option: $ grep -i "boo" /etc/passwd Use grep recursively You can search recursively i.e. read all files under each ...