909 views
0 votes
0 votes
try to print this in one loop itself.i have already done this in two loops(one nested into another).so please try to do in one loop itself.

1
2   4
3   6   9
4   8   12  16
5   10  15  20  25

3 Answers

Best answer
2 votes
2 votes
#include <stdio.h>
int main(int argc, char * argv[])
{
        int i, j=1, k=1, n=atoi(argv[1]);
        for(i = 1; j <= n; k++)
        {
                printf("%d ",i);
                if(k == j)
                {
                        k = 0; i = ++j;
                        printf("\n");
                }
                else i += j;
        }
}
selected by
2 votes
2 votes
#include<stdio.h>
#include<conio.h>
int main()
{
    int j=1;
for(int i =1; i<=5;i++)
{
    if(i*j<=i*i)
    {
       printf("%d \t",i*j);
        i--;
        j=j+1;
    }
  else
    {
        printf("\n");
        j=1;
    }
}
   getch();
return 0;
}
2 votes
2 votes
pattern(1,row*row); pattern(i,n)
{
 if(i*i>n)
    return;
 else
 {
  for(k=i;k<=i*i;k=k+i)
    print("%d",k);
  print("/n");
  pattern(i+1,n);
 }
}
edited by

Related questions

0 votes
0 votes
0 answers
1
iarnav asked Jul 30, 2018
390 views
for every j != i in {0,....,n-1} is it like for j=0 to n-1; j !=i ; ++j