Difficult C programs

Newbie Member
15Apr2008,03:05   #1
aijaz's Avatar
hello frends ... i need sme help in developing some programs in C

1) i want the out like this 1
1 1
1 1 2
1 1 2 3
1 1 2 3 5
1 1 2 3 5 8 ... & soon .. till the range i specify

... here you can see tht we are adding the Diagonal digits ... plz help

2 ) program .. i want out like this .. in this program .....

1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
Newbie Member
1Jun2009,00:17   #2
dipakdayanand's Avatar
2)this is the answer:
Code:
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,before=0,array[10][10];
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=(2*i);j++)
{
if(j<=i)
{
array[i][j]=before+1;
before++;
}
else
{
array[i][j]=before-1;
before--;
}
}
before=0;
}
for(i=1;i<=5;i++)
{
for(j=1;j<=((2*i)-1);j++)
{
printf("%d",array[i][j]);
printf("\t");
}
printf("\n");
}
getch();
}

Last edited by shabbir; 1Jun2009 at 10:04.. Reason: Code blocks
abhix95 like this
Newbie Member
1Jun2009,00:39   #3
dipakdayanand's Avatar
1)
Code:
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,c,i,j,array[10][10];
clrscr();
for(i=1;i<=5;i++)
{
a=0,b=1;
for(j=1;j<=i;j++)
{
if(j==1)
array[i][j]=1;
else
{
c=a+b;
array[i][j]=c;
a=b;
b=c;
}
}
}
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",array[i][j]);
printf("\t");
}
printf("\n");
}
getch();
}

Last edited by shabbir; 1Jun2009 at 10:04.. Reason: Code blocks
abhix95 like this
~ Б0ЯИ Τ0 С0δЭ ~
1Jun2009,06:49   #4
SaswatPadhi's Avatar
Please post you code inside code-blocks.

If you are not allowed to change your post, shabbir might change it for you.
Newbie Member
14May2010,13:37   #5
cvikas78's Avatar
Code:
#include<stdio.h>
int main(int argc , char *argv[])
{
        int next = 1;
        int range = 1, rangeEnd = 0;
        int nextInRange = 0;
        int prev = 1;
        if(argv[1] == NULL) {
                printf("Usage : ./a.out <range_number>\n");
        } else {
                rangeEnd = atoi(argv[1]);
        }
        for(; range <= rangeEnd ; range++) {
                next = 1;
                prev = 1;
                if(range >= nextInRange) {
                        printf("%d %d ", prev, next);
                        for(; next < range ;) {
                                next = prev + next;
                                printf("%d ", next);
                                prev = next - prev;
                        }
                        nextInRange = next + prev;
                        putchar('\n');
                }
        }
}

Last edited by shabbir; 14May2010 at 14:01.. Reason: Code blocks
abhix95 like this
Mentor
15May2010,14:43   #6
xpi0t0s's Avatar
OK, now where are the difficult C programs?
Newbie Member
25Feb2011,12:32   #7
sameerthapa2050's Avatar
[QUOTE=aijaz;27389]hello frends ... i need sme help in developing some programs in C

Code:
1) i want the out like this       1
                                           1  1
                                           1  1  2
                                           1  1  2  3
                                           1  1  2  3  5
                                           1  1  2  3  5  8 ... & soon .. till the range i specify
... here you can see tht we are adding the Diagonal digits ... plz help



Code:
public class Pattern {

	public static void main(String[] args) {

		for(int i=1;i<7;i++) {

			int p=0,n=1,t;

			for(int j=1;j<=i;j++) {

				System.out.print(n);
				
                                t=n;
				
                                n+=p;
				
                                p=t;

			}

			System.out.println("");

		}

	}

}

Last edited by shabbir; 25Feb2011 at 14:30.. Reason: Code blocks
Newbie Member
25Feb2011,12:40   #8
sameerthapa2050's Avatar
Quote:
Originally Posted by aijaz View Post
hello frends ... i need sme help in developing some programs in C

2 ) program .. i want out like this .. in this program .....

1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1

Code:
public class Pattern {

	public static void main(String[] args) {
		
		System.out.println("1");
		
		for(int i=1,j;i<5;i++){
			
			for(j=1;j<=i;j++){
		
				System.out.print(j+" ");
			
			}
			
			for(;j>=1;j--){
			
				System.out.print(j+" ");
			
			}
			
			System.out.println("");
			
		}
	}
}

Last edited by shabbir; 25Feb2011 at 14:30.. Reason: Code blocks
Newbie Member
25Feb2011,12:46   #9
sameerthapa2050's Avatar
[QUOTE=sameerthapa2050;79916]
Quote:
Originally Posted by aijaz View Post
hello frends ... i need sme help in developing some programs in C

1) i want the out like this 1
1 1
1 1 2
1 1 2 3
1 1 2 3 5
1 1 2 3 5 8 ... & soon .. till the range i specify

... here you can see tht we are adding the Diagonal digits ... plz help



#include<stdio.h>

void main()
{

int i,j,p,n,t;

for(i=1;i<7;i++)
{

p=0,n=1,t;

for(j=1;j<=i;j++)
{

printf("%d",n);

t=n;

n+=p;

p=t;

}

printf("\n");

}

}

}
abhix95 like this
Newbie Member
22Aug2011,18:01   #10
Sharad Sharma's Avatar
Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
long n,j,p=0,q;
clrscr();
printf("\n Enter the number of rows : ");
scanf("%ld",&n);
for(j=0;j<=n-1;j++)
{
p=1*pow(10,j)+p;
q=p*p;
printf("%ld",q);
printf("\n");
}
getch();
}

Last edited by shabbir; 22Aug2011 at 19:39.. Reason: Code blocks
abhix95 like this