Tuesday, 19 December 2017

Number Patterns In C

1                                                                                                                              
22                                                                                                                             
333                                                                                                                            
4444                                                                                                                           
55555
#include<stdio.h>
#include<conio.h>
void main()
{
  int i, j;
  clrscr();
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",i);
        }
        printf("\n");
    }
getch();
}



1                                                                                                                              
23                                                                                                                             
456                                                                                                                            
78910                                                                                                                          
1112131415 
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j, k=1;
clrscr();
for(i=1;i<=6;i++)
{
for(j=1;j<i;j++)
{
printf("%d",k);
k++;
}
printf("\n");
}
getch();
}



      1                                                                                                                        
    2 3 4                                                                                                                      
  5 6 7 8 9                                                                                                                    
10 11 12 13 14 15 16  
#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j,k;
  k=1;
  clrscr();
  for(i=1;i<=7;i+=2)
  {
    for(j=7;j>=1;j--)
    {
      if(j>i)
        printf(" ");
      else
        printf("%d ",k++);
    }
    printf("\n");
  }
getch();
}




Enter any number                                                                                                               
 3                                                                                                                             
  1                                                                                                                            
 232                                                                                                                           
34543 
 #include<stdio.h>
#include<conio.h>
void main()
{
int n, a, b, num = 1, space;
clrscr();
printf("Enter any number\n ");
scanf("%d",&n);
space=n-1;
for(b=1; b<=n; b++)
{
num=b;
for(a=1; a<=space; a++)
printf(" ");
space--;
for(a=1; a<=b; a++)
{
printf("%d", num);
num++;
}
num--;
num--;
for(a=1; a<b; a++)
{
printf("%d", num);
num--;
}
printf("\n");
}
getch();
}



1                                                                                                                              
123                                                                                                                            
12345                                                                                                                          
12345                                                                                                                          
123                                                                                                                            
1  

123                                                                                                                            
12345                                                                                                                          
12345                                                                                                                          
123                                                                                                                            
1  
 #include<stdio.h>
#include<conio.h>
void main()
{
int i, j;
clrscr();
for(i=1;i<=5;i+=2)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
for(i=5;i>=1;i-=2)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
getch();
}



1111                                                                                                                           
2222                                                                                                                           
3333                                                                                                                           
4444                                                                                                                           
      
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j;
clrscr();
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
printf("%d",i);
printf("\n");
}
getch();
}



54321                                                                                                                          
 4321                                                                                                                          
  321                                                                                                                          
   21                                                                                                                          
    1
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j;
clrscr();
for(i=5;i>=1;i--)
{
for(j=5;j>=1;j--)
{
if(j>i)
printf(" ");
else
printf("%d",j);
}
printf("\n");
}
getch();

}

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...