the logic i have used is nCr => n!/(r!*(n-r)!) for example the outer loop counter is 'n' and the inner loop counter is 'r' , then the corresponding element of the pascal's triangle will be nCr. keep in mind that both the loops will have to start from zero. #include<stdio.h> main()
{
int num,i,j,k,space;
int difffact=1,diff,n,r,x,y,comb=0,nfact=1,rfact=1;
printf("please enter the number of lines\n");
scanf("%d",&num); k=num-1;
space=num-1;
for(i=0;i<num;i++)
{
k=space--;
for(;k>0;k--)
{
printf(" ");
}
for(j=0;j<=i;j++)
{
comb=0;
nfact=1;
rfact=1;
difffact=1; for(n=i;n>=1;n--)
nfact=nfact*n; for(r=j;r>=1;r--)
rfact=rfact*r; diff=i-j;
for(;diff>=1;diff--)
difffact=difffact*diff; comb=(nfact/(rfact*difffact));
printf("%d ",comb);
}
printf("\n");
}
}
write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?
There's a nice for Loop at the link below.
You may exit a nested loop in Java using a break with a label for the outer loop.
how to print "square" using for loop
In programming, a loop works by conditionally jumping to the start of the loop and repeating the instructions. If the condition evaluates false, execution continues to the next instruction, thus breaking out of the loop. We can also break out of a loop from within the body of the loop itself using another conditional jump which jumps out of the loop. If we jump backwards out of a loop we effectively create an intertwined loop, known as spaghetti code which is difficult to read and maintain. Structured loops help make it easier to digest the logic. In C, a jump is achieved using a goto and a label. However, structured loops using for, while and do-while statements make loops much easier to read and maintain.
The time complexity of using a while loop inside a for loop is O(nm), where n is the number of iterations of the for loop and m is the number of iterations of the while loop.
yes
int maxNum = 1000; for(int i = 0; i <= maxNum; i += 2) { // Java solution System.out.println(i); // C solution printf("%d\n", i); }
write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?
for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { print what u need } print to go to next line }
A mobius loop is the symbol often reffered to as the recycling symbol. It consits of three arrows pointing at eachother, forming a type of triangle.
It is a possible solution, yes.
There's a nice for Loop at the link below.
You may exit a nested loop in Java using a break with a label for the outer loop.
To create a loop using a knot, you can make a simple overhand knot in a rope or string and leave a small loop at the end. This loop can be used for various purposes such as attaching a hook or securing an object.
HTML has no notion of a loop. This cannot be done.
how to print "square" using for loop