Computer Scientists are Pretty Pessimistic

Sunday 4 October 2015

WAP to add space before an Uppercase letter in a string, ignore the first alphabet.

Input :
ILoveMyCountry
ImtiyazHossainHira

Output :
I Love My Country
Imtiyaz Hossain Hira

CODE ::

#include <stdio.h>
#include <string.h>
int main ()
{
    char a[1000],b[1000];
    int i,j;
    gets(a);
    b[0]=a[0];
    for(i=1,j=1;i<a[i];j++,i++)
    {
        if(a[i]>='A'&&a[i]<='Z')
        {
            b[j]=' ';
            b[j+1]=a[i];
            j++;
        }
        else
            b[j]=a[i];
    }
    b[j]='\0';
    puts(b);
    return 0;

}

No comments:

Post a Comment