Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, April 25, 2013

Create a text file and enter “to write a good program is very time consuming job.” Create another text which contains reverse of above text.


#include<stdio.h>
#include<conio.h>
void main()
{
  FILE *fp,*f;
  char str[]= "To write a good program is very time consuming";
  int i;
  fp=fopen("old.txt","w");
  fputs(str,fp);
  f=fopen("new.txt","w");
  for(i=strlen(str);0<i;i--)
    fputc(str[i],f);
  fclose(fp);
  fclose(f);
}

Given a text file, create another text file deleting the following words “three”, “bad”, and “time”.


#include<stdio.h>
#include<conio.h>
void main()
{
   FILE *fp;
   char str;
   fp=fopen("old.txt","r+");
   clrscr();
   while(fscanf(fp,"%s",str)!=EOF)
   {
      if(strcmp(str,"three")==0||strcmp(str,"bad")==0||strcmp(str,"time")==0)
      {
         printf("");
      }
    else
        printf("%s ",str);

 }
fclose(fp);
getch();
}

Note: Create a text file old.txt in same folder and write some words including three, bad and time.

Program to enter two 3x3 matrices and calculate the product of given matrices.


#include<stdio.h>
#include<conio.h>

void main()
{
  int a[3][3],b[3][3],c[3][3];
  int i,j,k;
  clrscr();
  printf("Enter the matrix A\n");
     for(i=0;i<3;i++)
      {
          for(j=0;j<3;j++)
           {
            scanf("%d",&a[i][j]);
           }
     }
  printf("Enter the matrix B\n");

    for(i=0;i<3;i++)
      {
        for(j=0;j<3;j++)
        {
           scanf("%d",&b[i][j]);
        }
      }

    for(i=0;i<3;i++)
      {
        for(j=0;j<3;j++)
         {
           c[i][j] = 0;
           for(k=0;k<3;k++)
           {
             c[i][j] += a[i][k] * b[k][j];
           }
         }
      }
  printf("\n\nThe product of two matrix\n\n" );
    for(i=0;i<3;i++)
    {
       for(j=0;j<3;j++)
       {
         printf("%d\t",c[i][j]);
       }
       printf("\n");
    }
getch();

}

Sunday, July 22, 2012

Program which will read a line and delete from it all occurrences of the word “that”

#include<stdio.h>
#include<conio.h>
void main()
{
char str[]=”I that love c that programming.”;
int i;
clrscr();
for(i=0;str[i]!=’\0′;i++)
{
if(str[i]==116&&str[i+1]==104&&str[i+2]==97&&str[i+3]==116&&str[i+4]==32)
{
for(;str[i+5]!=’\0′;i++)
str[i]=str[i+5];
str[i]=’\0′;
i=0;
}
}
printf(“%s”,str);
getch();
}

 

© 2013 TechSansar. All rights resevered. Designed by Templateism

Back To Top