Difficult C programs

Discussion in 'C++' started by aijaz, Apr 14, 2008.

  1. aijaz

    aijaz New Member

    Joined:
    Apr 14, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. dipakdayanand

    dipakdayanand New Member

    Joined:
    May 31, 2009
    Messages:
    4
    Likes Received:
    3
    Trophy Points:
    0
    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 a moderator: Jun 1, 2009
    persysweb and abhix95 like this.
  3. dipakdayanand

    dipakdayanand New Member

    Joined:
    May 31, 2009
    Messages:
    4
    Likes Received:
    3
    Trophy Points:
    0
    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 a moderator: Jun 1, 2009
    abhix95 likes this.
  4. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    Please post you code inside code-blocks.

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

    cvikas78 New Member

    Joined:
    May 14, 2010
    Messages:
    1
    Likes Received:
    1
    Trophy Points:
    0
    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 a moderator: May 14, 2010
    abhix95 likes this.
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    OK, now where are the difficult C programs?
     
  7. sameerthapa2050

    sameerthapa2050 New Member

    Joined:
    Feb 25, 2011
    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    0
     
    Last edited by a moderator: Feb 25, 2011
  8. sameerthapa2050

    sameerthapa2050 New Member

    Joined:
    Feb 25, 2011
    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    0

    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 a moderator: Feb 25, 2011
  9. sameerthapa2050

    sameerthapa2050 New Member

    Joined:
    Feb 25, 2011
    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    0
     
    abhix95 likes this.
  10. Sharad Sharma

    Sharad Sharma New Member

    Joined:
    Aug 22, 2011
    Messages:
    3
    Likes Received:
    2
    Trophy Points:
    0
    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 a moderator: Aug 22, 2011
    abhix95 likes this.
  11. Sharad Sharma

    Sharad Sharma New Member

    Joined:
    Aug 22, 2011
    Messages:
    3
    Likes Received:
    2
    Trophy Points:
    0
    1
    121
    12321

    #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();
    }
     
  12. Sharad Sharma

    Sharad Sharma New Member

    Joined:
    Aug 22, 2011
    Messages:
    3
    Likes Received:
    2
    Trophy Points:
    0
    (2)
    1
    121
    12321

    #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();
    }
     
    abhix95 likes this.
  13. abhix95

    abhix95 New Member

    Joined:
    Jan 18, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    1
    11
    112
    11235
    112358

    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    int a, b,c,r,p=0,n=1;
    clrscr();
    cout<<"Enter number of line";
    cin>>a;
    for(b=1;b<=a;b++)
    {
    cout<<1<<"\t";
    for(c=1;c<b;c++)
    {
    r=p+n;
    p=n;
    n=r;
    cout<<r<<"\t";
    }
    cout<<endl;
    n=1;
    p=r=0;
    }
    getch();
    }
     
  14. cwizard

    cwizard New Member

    Joined:
    Jul 29, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int a[20],n;
    a[0]=1;
    a[1]=1;
    cout<<"Enter the limit"<<endl;
    cin>>n;
    for(int j=1;j<=n;j++)
     {
      for(int i=2;i<=j;i++)
      {
       a[i]=a[i-1]+a[(i-1)-1];
      }
     }
    for(j=0;j<=n;j++)
     {
      for(int i=0;i<=j;i++)
      {
      cout<<a[i];
      }
     cout<<endl;
     }
    getch();
    }
     
    Last edited by a moderator: Jul 30, 2012
  15. vijayuit

    vijayuit New Member

    Joined:
    Aug 3, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<stdio.h>
    void main(){
    int n,i,j,f1=0,f2=1,f3=0,k,a[25];
    printf("ENTER THE NUMBER\n");
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
    f1=f2;
    f2=f3;
    f3=f2+f1;
    a[i]=f3;
    for(j=1;j<=i;j++)
    {
    printf("%d\t",a[j]);
    }
    printf("\n");
    }
    }
     
    Last edited by a moderator: Aug 3, 2012
  16. vijayuit

    vijayuit New Member

    Joined:
    Aug 3, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<stdio.h>
    void main(){
    int n,i,j,k;
    printf("ENTER THE NUMBER\n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=i;j++)
    printf("%d",j);
    for(k=j-2;k>0;k--)
    printf("%d",k);
    printf("\n");
    }
    }
     
    Last edited by a moderator: Aug 3, 2012
  17. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    But where are the *difficult* C programs? These 10-15 line tiddlers might be challenging for beginners for about 5 minutes, but that doesn't qualify them to be called difficult. IOCCC - now THERE are some difficult C programs!
     
  18. manojgdhv

    manojgdhv New Member

    Joined:
    Aug 17, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    1)
    Code:
    void main()
    {
    int f1=1,f2=1,f3=0,n=5,i,j;
    for(i=1;i<=5;i++)
    {
       printf("\n%d %d ",f1,f2);
       for(j=2;j<=i;j++)
       {
        
        f3=f1+f2;
        printf("%d ",f3);
        f1=f2;
        f2=f3;
       }
    }
    }
     2)
    void main()
    {
    int i=0,j=0;
    for(i=1;i<=4;i++)
    {
        for(j=1;j<=i;j++)
      printf("%d",j);
      for(j=i-1;j>=1;j--)
      printf("%d",j);
    printf("\n");
    }
    }
     
    Last edited by a moderator: Aug 17, 2012
  19. Kush Pandey

    Kush Pandey New Member

    Joined:
    Jan 10, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    here is the output of program to print
    11
    112
    1123
    11235
    112358


    Code:
    #include<stdio.h>
    #include<conio.h>
     main(){
        int i,j,a=1,b=1,c;
    
        for(i=1;i<=5;i++)
        {
            printf("%d\t%d\t",a,b);
        for(j=3;j<=i+1;j++)
        {
            c=a+b;
            printf("%d\t",c);
            a=b;
            b=c;
        }
        a=1;b=1;
        printf("\n");
        }
    }
     
    Last edited by a moderator: Jan 10, 2013
  20. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Just thought I'd borrow something from IOCCC to show you people what a difficult C program really looks like. These piddly examples to draw stars in triangles or whatever are nothing compared to these:
    Code:
    #include<stdio.h> /******** SpigotQuine -- usage: ./spigot [pi or e] ********/
    char*s="G1%%xJ{;Q7wunmuGuu%%uu#include<stdio.h>/*Spigot_Quine*/#include<stdli"
    "b.h>/*_IOCCC2012_*/int*e,"    "i,j,k,n"     ";char*q"    ",*a,*d,*z,*p=%s%c;"
    "int" "%cmain(){a=calloc("                                 "1,1e4+n*2);;for(*"
    "a=\0@3,z=d=a+n+1,j=n*8-7;"    "k=0,j-1"     ";j-=2){"    "for(a[1]+=2;--z-a;"
    "*z=k%%10,k/=10)k+=j/2**z;;for(;k=k%%j*"     "10+*++z,z<d;)*z=k/" "j;;\0@2,z="
    "d=a+n*2,*z=1,j=0;++j<n;){for(;k=k%%"           "j*10+*z,a-z;*z"   "--=k/j)a+"
    "+;for(k=0;z-d;*a--=k%%10,k/=10)k+"               "=*++z+*a\0"     "@;}d+=spr"
    "intf(q=d-20,p,p,34,32,n+1)+2;;;;"                 "for(n=n*2"     "0-400;k<n"
    ";++k%%n?j=!puts("                                                 "d):(d[j]="
    "47,d++,d[j-2"                                                     "]=42),k%%"
    "20<1?puts(d"                                                      "-1),a++:0"
    "){for(i=-1"                                                       ";i++<32;!"
    "*z?q[662]"          "=0,z=q+207:"                 "*z+z[1]<6"     "5?z+=11:*"
    "z==34?p=0"         ":0)d[i]=((k/2"               "0-1?275*q["     "*a+10]-8*"
    "q[*a+0]-8"         ":128)>>(i/11+k/"           "4%%5*3))&1?k"     "/3*!j&&p?"
    "j=34:(j="           "i+1,*z++):32;k/3*"     "j--&&p?d[z--,j]=3"   "4:0;}}int"
    "*y,n=%d;/*..~",*f="nnLa5~z23~|22t$q(s82r&q(s82q'q(s8;q(s8;q(s8:" "r(s8:r(s8:"
    "q)s89r)sLr#t+" "sLx,uJw-yGu/wnnnU",*g="nnLa<z::t$u88t(u67t*u57s,t56t,t56~v56"
    "tF6tF6tF8t1p"   "Nu/qOv+rS}Xxnng";int main(int m,char**v){char a[2012],b[2012
    ],*p=a,*r=m>1     &&*v[1]=='e'?g:f,*q=b,*t=r;;sprintf(a,"%s%s%s",s,r==g?s+281:
    s+168,s+386);     sprintf(b,a+22,a,34,32,24);for(sprintf(a,"%.33s/*%.28s*/%.3"
    "3s/*%.28s*/%"   ".33s\"%s*/",b,b+66,b+33,b+76,b+66,b+99);*r;r++){;for(m=0;m++
    <(*r-34)%77;*q++=*r>111?32:*p++)(q-b)%66<1?*q++=10:0;*r-110&&*r-126&&r-t<(t-g?
    62:45)?*q++=34,((q-b)%66<1?*q++=10,*q++=34:0):0;}*q=0;puts(b+1);}/*IOCCC2012*/
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice