Search This Blog

Thursday, October 13, 2011

Write a program to read a line of text and to convert it into a coded text by changing its characters to integer and adding k to each character

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  void main()
   4:  {
   5:  char line[80];
   6:  int i,l,k;
   7:  clrscr();
   8:  printf("Enter the line\n");
   9:  for(i=0;i<80;i++)
  10:  {
  11:  scanf("%c",&line[i]);
  12:  if(line[i]=='\n')
  13:  break;
  14:  }
  15:  l=i;
  16:  printf("Enter the num for coding: ");
  17:  scanf("%d",&k);
  18:  printf("\nCoded text is:\n");
  19:  for(i=0;i<l;i++)
  20:  printf("%4d",line[i]+k);
  21:  getch();
  22:  }

No comments:

Post a Comment