Write a program to print the initials of a given name.

Source Code

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main (int argc, char *argv[])
{
  clrscr();
  char name[100];
  int i=1,j=0,p=0,l=0;
  printf("\nEnter a name: ");
  gets(name);
  printf("\nInitials:");
  printf("\n%c.",name[0]);
  l=strlen(name);
  for(i=1;i<l;i++)
  {
    if(name[i] == 32)
    {
      j=i+1;
      while(j<l)
      {
        if(name[j]==32)
        {
          printf("%c.",name[i+1]);
          break;
        }
        else if(name[j]=='\0')
          break;
        else
          j++;
      }
    }
  }
  p=l;
  while(name[p]!=32)
  {
    p--;
  }
  for(int k=p;k<l;k++)
  {
    printf("%c",name[k]);
  }
  getch();
}

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code