Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Difficult C programs (http://www.go4expert.com/forums/difficult-c-programs-t10025/)

aijaz 15Apr2008 03:05

Difficult C programs
 
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

dipakdayanand 1Jun2009 00:17

Re: Difficult C programs
 
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();
}


dipakdayanand 1Jun2009 00:39

Re: Difficult C programs
 
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();
}


SaswatPadhi 1Jun2009 06:49

Re: Difficult C programs
 
Please post you code inside code-blocks.

If you are not allowed to change your post, shabbir might change it for you.

cvikas78 14May2010 13:37

Re: Difficult C programs
 
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');
                }
        }
}


xpi0t0s 15May2010 14:43

Re: Difficult C programs
 
OK, now where are the difficult C programs?

sameerthapa2050 25Feb2011 12:32

Re: Difficult C programs
 
[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("");

                }

        }

}


sameerthapa2050 25Feb2011 12:40

Re: Difficult C programs
 
Quote:

Originally Posted by aijaz (Post 27389)
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("");
                       
                }
        }
}


sameerthapa2050 25Feb2011 12:46

Re: Difficult C programs
 
[QUOTE=sameerthapa2050;79916]
Quote:

Originally Posted by aijaz (Post 27389)
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");

}

}

}


Sharad Sharma 22Aug2011 18:01

Re: Difficult C programs
 
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();
}



All times are GMT +5.5. The time now is 20:19.