0 votes
3 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 (5.4k points)
reopened by | 3 views

1 Answer

0 votes
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 (5.4k points)
500 questions
477 answers
8 comments
12 users