Difficult C programs

aijaz's Avatar, Join Date: Apr 2008
Newbie Member
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
0
dipakdayanand's Avatar, Join Date: Jun 2009
Newbie Member
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
0
dipakdayanand's Avatar, Join Date: Jun 2009
Newbie Member
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
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Please post you code inside code-blocks.

If you are not allowed to change your post, shabbir might change it for you.
0
cvikas78's Avatar, Join Date: May 2010
Newbie Member
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
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
OK, now where are the difficult C programs?
0
sameerthapa2050's Avatar, Join Date: Feb 2011
Newbie Member
[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
0
sameerthapa2050's Avatar, Join Date: Feb 2011
Newbie Member
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
0
sameerthapa2050's Avatar, Join Date: Feb 2011
Newbie Member
[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
0
Sharad Sharma's Avatar
Newbie Member
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