+ 1
How to remove whitespace at the end of each line using c language?
Title: Numbered Triangle Problem: You need to print this pattern upto N. For N = 4, 1 1 2 1 2 3 1 2 3 4 Input: A single positive integer N. Output: Numbered Triangle upto N. Do not leave trailing whitespaces at the end of each line. Constraints: 1 ≤ N ≤ 9 Sample Input: 3 Sample Output: 1 1 2 1 2 3
8 Respostas
0
For evading the last space in a row, you could use this pattern:
for(int j=0; j<4; ++j)
printf("%d%s", j, j<3? " ": "");
+ 1
/*i got the answer thanks for sharing ideas love you*/
#include<stdio.h>
int main()
{
int n,i,j;
char sp=' ';
scanf("%d",&n);
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf("%d",j);
if(i!=j)
{
printf("%c",sp);
}
}
printf("\n");
}
return 0;
}
0
How did you get that newline? printf function in C should not put newlines automatically.
0
But how can i solve? Help me
0
I have no idea. Can you link the code where you met this problem?
0
Title: Numbered Triangle
Problem: You need to print this pattern upto N.
For N = 4,
1
1 2
1 2 3
1 2 3 4
Input: A single positive integer N.
Output: Numbered Triangle upto N.
Do not leave trailing whitespaces at the end of each line.
Constraints: 1 ≤ N ≤ 9
Sample Input: 3
Sample Output:
1
1 2
1 2 3
Link: https://code.dcoder.tech/question/5b55730fab46cd2f99d3bf80
0
Expected:
1
1 2
1 2 3
1 2 3 4
Output:
1
1 2
1 2 3
1 2 3 4
Miika i try to code Space before" %d" But it's 1st space after that number.