CAT | Data structure

void main()
{
FILE *fp1,*fp2;
char ch; clrscr();
fp1=fopen("d:\\sy42\\303\\aaa.txt","r");
fp2=fopen("d:\\sy42\\303\\bbb.txt","w");
if(fp1==NULL)
{ printf("\nnot read");
exit();
}
if(fp2==NULL)
{ printf("\nnot read");
fclose(fp1);
exit();
}
   ch=fgetc(fp1);
   while(ch!=EOF)
  {
  fputc(ch,fp2);
  ch=fgetc(fp1);
  }

  fclose(fp1);
  fclose(fp2);
    printf("\n copied successfully");

    getch();
   }

No tags Hide

void main()
{
 FILE *fp;
 char ch;
 int nol=0,not=0,nob=0,noc=0;
 clrscr();
  fp=fopen("f1.txt","r");
  while(1)
   {
    ch=fgetc(fp);
     if(ch==EOF)
       break;
     noc++;
     if(ch==' ')
      nob++;
     if(ch=='\n')
      nol++;
     if(ch=='\t')
      not++;
   }
    fclose(fp);
  printf("no.of char=%d",noc);
  printf("no.of blanks=%d",nob);
  printf("no.of tabs=%d",not);
  printf("no.of lines=%d",nol);
 getch();
}

No tags Hide

void main()
{
int ch,h[10],n,p,i,t,j;
printf("\n ENTER ARRAY= ");
for(i=0;i<10;i++)
        {
            scanf("\n %d",&h[i]);
        }

do

    {
    clrscr();
    flushall();
    printf("\n1.traversing");
    printf("\n2.insertion");
    printf("\n3.deletion");
    printf("\n4.sorting");
    printf("\n5.searching");
    printf("\n6. exit");
    printf("\nenter choice");
    scanf("%d",&ch);
    switch(ch)
    {
    case 1:  printf("\n display array");
        for(i=0;i<10;i++)
        {
            printf("\n %d",h[i]);
        }     getch();
    break;

    case 2:printf("\n enter no & position ");
        scanf("%d%d",&n,&p);
        for(i=0;i<10;i++)
        {
            if(i==p)
            {
                h[i]=n;
            }
            else
            {
                printf("\n position not found");
            }
        }
        break;
case 3: printf("\n enter position for delete no");
    scanf("%d",&n);
    for(i=0;i<10;i++)
    {
        if(i==n)
        {
            h[i]=0;
        }
        else
        {
            printf("\n position not found");
        }
    }
break;
    case 4:printf("\n sorting is==");
        for(i=0;i<9;i++)
        {
            for(j=i+1;j<=9;j++)
            {
                if(h[i]<=h[j])
                {
                    t=h[i];
                    h[i]=h[j];
                    h[j]=t;
                }
            }
        }
        for(i=0;i<10;i++)
        {
            printf("\n%d\n",h[i]);
        }  getch();
    break;
case 5: printf("\n enter no for searching ");
    scanf("%d",&n);
    for(i=0;i<10;i++)
    {
        if(h[i]==n)
        printf("\n%d",h[i]);

    }   getch();
break;
case 6:exit();
}
}while(ch!=6);
getch();
}

No tags Hide

void main()
{
int a[10];int i;clrscr();
printf("\nenter values for array");
for(i=0;i<10;i++)
{scanf("%d",&a[i]);
}
count(&a[0]);
getch();
}
void count(int *x)
{
int i,m=0,n=0;
for(i=0;i<10;i++)
{
  if(x[i]< 0)
  { m++;}
  else
  {n++;
  }     }
printf("\n total positive value=%d",n);
printf("\n total negative value=%d",m);      }

/*

No tags Hide

« Previous

Next »

Managed by

MNP INFOTECH