Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai all,
How are you ? wishing you fine.
Can you give some me examples of nested for loop in c ? It is urgent .plz help.
Thanks
Posted
Updated 5-Oct-21 17:56pm
Comments
Manoj Kumar Choubey 23-Jul-14 3:05am    
http://www.codeproject.com/Questions/447265/Logic-behind-nested-for-and-other-loops
[no name] 23-Jul-14 3:50am    
Hai Manoj,
Can you give me some another 10 examples ?
Thanks & regards
Raihan
Manoj Kumar Choubey 23-Jul-14 4:25am    
For the more example and practice you can check following books
programming in c schaum series
Let Us C By yashwant kanetkar
robert lafore c
http://www.cluster2.hostgator.co.in/files/writeable/uploads/hostgator99706/file/letusc-yashwantkanetkar.pdf

1 solution

You can search on google as
https://www.google.co.in/?gfe_rd=cr&ei=Zl3PU6ySOarV8gfjooGACQ#q=example+nested+for+loop+in+c[^]

Following is the examples
C++
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,lines;
char ch = '*';

clrscr();
printf("Enter number of lines : ");
scanf("%d",&lines);

    for(i=0;i <=lines;i++)
    {
    printf("n");
        for (j=0;j < i;j++)
           printf("%c",ch);
    }
getch();
}
</conio.h></stdio.h>


the output is
*
* *
* * *
* * * *
* * * * *
* * * * * *


C++
#include <stdio.h>
 
int main()
{
   int row, c, n, temp;
 
   printf("Enter the number of rows in pyramid of stars you wish to see ");
   scanf("%d",&n);
 
   temp = n;
 
   for ( row = 1 ; row <= n ; row++ )
   {
      for ( c = 1 ; c < temp ; c++ )
         printf(" ");
 
      temp--;
 
      for ( c = 1 ; c <= 2*row - 1 ; c++ )
         printf("*");
 
      printf("\n");
   }
 
   return 0;
}

</stdio.h>


Output
*
***
*****
*******
*********
 
Share this answer
 
Comments
merano99 6-Oct-21 19:17pm    
</stdio.h>

Are you serious?
Manoj Kumar Choubey 21-Oct-21 8:42am    
I didn't get it, could you please explain.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900