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 Programming in C programming programming-in-c + – sumit kumar asked Nov 10, 2014 sumit kumar 909 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Bhagirathi commented Nov 11, 2014 reply Follow Share can i use recursion????? 0 votes 0 votes sumit kumar commented Nov 14, 2014 reply Follow Share yes you can. 0 votes 0 votes Please log in or register to add a comment.
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; } } Arjun answered Nov 10, 2014 • selected Nov 11, 2014 by sumit kumar Arjun comment Share Follow See all 3 Comments See all 3 3 Comments reply sumit kumar commented Nov 10, 2014 reply Follow Share it says segmentation fault. probably you are trying to access out of your way. 0 votes 0 votes Arjun commented Nov 11, 2014 reply Follow Share n=atoi(argv[1]) So, you must pass command line argument for the number of lines to be printed. Else replace this line with a scanf or n = 5. 0 votes 0 votes sumit kumar commented Nov 11, 2014 reply Follow Share yes brother it's working.thanks a lot. 1 votes 1 votes Please log in or register to add a comment.
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; } Palash Nandi 1 answered Nov 13, 2014 Palash Nandi 1 comment Share Follow See 1 comment See all 1 1 comment reply Arjun commented Nov 13, 2014 reply Follow Share Your logic is pretty good, just replace if(i*j<=i*i) with if( j <= i) Also, try using a better compiler. http://gatecse.in/wiki/Why_I_should_not_use_Turbo_C%3F 0 votes 0 votes Please log in or register to add a comment.
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); } } Bhagirathi answered Nov 15, 2014 • edited Nov 15, 2014 by Bhagirathi Bhagirathi comment Share Follow See all 4 Comments See all 4 4 Comments reply Bhagirathi commented Nov 16, 2014 reply Follow Share I can try to print this pattern without any loop 0 votes 0 votes sumit kumar commented Nov 17, 2014 reply Follow Share how @bhagirathi please can you give an example. 0 votes 0 votes Bhagirathi commented Nov 18, 2014 reply Follow Share Instead of the for loop ,call a recursive function again 1 votes 1 votes sumit kumar commented Nov 18, 2014 reply Follow Share ya that is one more way to do the same ... 1 votes 1 votes Please log in or register to add a comment.