+1 vote
75 views
Write a C++ program that right justifies text. It should read and echo a sequence of left justified lines and print them in right justified format.

[March 2003, March 2006, Oct. 2006, Oct. 2003, March 2005, March 2007] Computer science program maharashtra board
from Computer science maharashtra board
in Programming by Expert (10.7k points)
reopened by | 75 views

1 Answer

+1 vote
Best answer

#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{
char line[5][100];
int i, j, len, maxlen=0;
for(i=0; i<=4; i++)
{
cin.getline(line[i], 99, '\n');
len=strlen(line[i]);
if(len>maxlen)
maxlen=len;
}
for(i=0; i<=4; i++)
{
len=strlen(line[i]);
for(j=1; j<=maxlen-len; j++)
{
cout<<" ";
}
cout<<line[i]<<endl;
}
}

 

Only works in Turbo c++ for maharashtra board syllabus

by Expert (10.7k points)
714 questions
695 answers
11 comments
24 users