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)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(); }
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(); }
Please post you code inside code-blocks. If you are not allowed to change your post, shabbir might change it for you.
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'); } } }
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(""); } } }
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(); }
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(); }
(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(); }
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(); }
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(); }
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"); } }
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"); } }
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!
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"); } }
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"); } }
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*/