Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 5 June 2016

PROBLEM 28:

Write a program that reads full names, one per line, and then prints them in
the standard telephone directory format. For example,
Sample Input1: George Frederic Handel
Sample Output1: Handel, George F.
Sample Input2: Joseph Haydn
Sample Ouput2: Haydn, Joseph
Sample Input3: Johann Christian Bach
Sample Output3: Bach, Johann C.
Your program should ask user name and print output repeatedly till user press any sentinel value

(you may select any sentinel here)

CODE:

#include<stdio.h>
main()
{
// Variable declaration//
char a[25];
char b[25];
int i=0,j,k=0,count=0,count1=0,space=0,c,m=0;
 /*Input*/
 printf("if you want to exit enter #\n");
 do{
for(j=0;j<25;j++)// here i intail all array index with 0
{
    b[j]=0;
}
printf("\n");
printf("Enter String to add in telephone dictionary:");
gets(a);
/* actual Working */
if(a[0]=='#') //if input equal to # so loop will break
{
    break;
}
for(i=0;a[i]!='\0';i++)//this loop will count total character
{
    count=count+1;
    if(a[i]==' ') //if space is find in array so this condition will run
    {
        b[k]=count;
        k++;
        m++;
    }
}
for(j=0;b[j]!='\0';j++)//this loop will save b[j] value in c varaible
{
c=b[j];
}
for(j=c;a[j]!='\0';j++)
{
    printf("%c",a[j]);
}
printf(",");
printf(" ");
if(a[j]=='\0' && m>1)
{
    for(j=0;j<=b[0];j++)
    {
        printf("%c",a[j]);
    }
    printf(".");
}
else
{
   for(j=0;j<b[0];j++)
    {
        printf("%c",a[j]);
    }
}
//here I again intail every varaible with zero because loop will start from begaining
i=0;
j=0;
k=0;
count=0;
count1=0;
space=0;
c=0;
m=0;
}while(a[0]!='#');
return 0;

}

Program Output:














For more problems click here

No comments:

Post a Comment