Program to encrypt the given string

Program to encrypt the given string

Question:

Write a program to print the encrypt string  given below.

Logic:

  •  Get the input string from the user.
  • Find the number in the string by checking from last.
  •  Then store the corresponding variable in reverse.
  • And prints the elements in array in reverse order.

Algorithm:

  1.  Get the input string from the user.
  2. Checks for the number using their ASCII value then made it as count.
  3.  Then store the corresponding variable into array using count.
  4.  Print the elements in array in reverse because they are stored in reverse order.

Program:

#include<stdio.h>
void main()
{
	char a[10],e[100];
	int n,i,j,b=0,c=0,d=0,k=0;
	clrscr();
	printf("enter the string:eg:a2b4->");
	gets(a);
	n=strlen(a);//stroes the length of string
	for(i=n-1;i>=0;i--)//checks from the last element
	{
		if(a[i]<58&&a[i]>47)//checks if the element is number using their ASCII value
		{
			b=a[i];//stroes the number into variable
			b=b-48;//to check the given number eg:a[i]=49 then b=1
			if(b!=0&&d>0)//enter into the if statement only the number is greater then one digit 
			{
				b=b*10;
			}
			c=c+b;//contains number value
			d++;//checks for number of digits
		}
		if((a[i]>65&&a[i]>91)||(a[i]>96&&a[i]<122))//checks if the element is varible using their ASCII value
		{
			for(j=0;j<c;j++)//variable stroes into the array in reverse order
			{
				e[k]=a[i];
				k++;
			}
		    c=0; d=0;//initializes the number after reaching the variable
		}
	}
	/*prints the elements in reverse order because variables in array are in reverse*/
	for(i=k-1;i>=0;i--)
	{
		printf("%c",e[i]);
	}
	getch();
}

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Vignesh

A Computer Science graduate who likes to make things simpler. When he’s not working, you can find him surfing the web, learning facts, tricks and life hacks. He also enjoys movies in his leisure time.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x