Logo 
Search:

C++ Programming Forum

Ask Question   UnAnswered
Home » Forum » C++ Programming       RSS Feeds

triangle of numbers,:-( i owe you one

  Asked By: Iman    Date: Nov 01    Category: C++ Programming    Views: 7743
  

Write a program to triangle as shown below.(please help me as soon as possible)
1
2
1 3
2 4
1 3 5
2 4 6
1 3 5
2 4
1 3
2
1

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Shruti Sharma     Answered On: Nov 01

Hi iman,

I tried to make triangle as you want , but due to less time i have only created it for increment part. Check code and output below.



#include <stdio.h>
#include <conio.h>

void main(){
int i,j,num,c=1,d=2,n=1;
clrscr();
printf("*****FLOYD'S TRIANGLE*****\n\n");
printf("Enter number upto which u want to generate : ");
scanf("%d",&num);
for(i=c;i<=num;){
c=1;
d=2;
for(j=1;j<=i;j++){
if(n == 1)
{
printf("%5d ",c);
c = c+2;
}
if(n == 0)
{
printf("%5d ",d);
d = d + 2;
}
if(c > num || d > num)
{
goto out;
}
}
printf("\n");
if(n == 1)
n = 0;
else
n = 1;
if(n == 1)
i++;
}
out:
getch();
}



Output


1
2
1 3
2 4
1 3 5
2 4 6




I will try for the decrement part when i will get time.
Hope this helps you.

 
Didn't find what you were looking for? Find more on triangle of numbers,:-( i owe you one Or get search suggestion and latest updates.




Tagged: