a2b3 output aabbb c program and beautiful use of getchar() ,isdigit() ,atoi() functions and stdlib.h header file-asr

a2b3 output aabbb c program


Beautiful use of getchar() ,isdigit() ,atoi() functions and stdlib.h header file

i noted
in string comparison single quote used,while in initialization double quotes
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <stdlib.h>

int main()
{
  char s[10],n[10],c[10];
  int i=0,j,num=0;
  int p[10];
 while(1){
    s[i]=getchar(); //reads single characters until enter pressed
    if(isdigit(s[i]))    //checks the character is digit or not
     {
         n[0]=s[i];  //digit assigned in array
         c[num]=s[i-1]; //previous character of digit is stored for printing
         p[num]=atoi(n); //ascii to digit ,the character is converted to int in p[num] index
         num++;         //num incremented
     }


  if(s[i]=='\n'){             //enter press the come out of loop
                   break;
                            }
  i++;
 }


if(!isdigit(s[0])){
for(j=0;j<num;j++){
 
  for(i=0;i<p[j];i++)
  printf("%c",c[j]); //prints characters n times ,the values in p[j] array,and character in c[j] arry
 
 
}

}
else {
    printf("First Character must be a alphabet");
}
    return 0;
}




Comments

Popular posts from this blog

aaabb to32 ,aabbb to a2b3 convert in c-asr

C program to print square spiral number pattern - asr