Skip to content

Instantly share code, notes, and snippets.

@saiprasad1996
Last active September 20, 2016 01:52
Show Gist options
  • Save saiprasad1996/f955d6926c603151cf62011043b4ac7a to your computer and use it in GitHub Desktop.
Save saiprasad1996/f955d6926c603151cf62011043b4ac7a to your computer and use it in GitHub Desktop.
//Program for printing a patter as shown in the output below
#include<stdio.h>
int main(){
int step=4,start,i,j; //variable step is for defining number of steps
//start is for the starting number from which the pattern starts
//i and j are the iterators for outer and inner loop
printf("Enter the number to start ");
scanf("%d",&start); //accept the starting number
//This loop is for the upper part
for(i=1;i<=step;i++){
for(j=0;j<i;j++){
printf("%d",start);
}
printf("\n"); //add a new line character after inner loop
start++;//increment the start once the pattern line is printed
}
start=start-1;//once the top pattern is completed then after the
//defined number of steps the start value is one morethan the required
//so it is decremented once
//the below code prints the bottom half of the pattern
for(i=step;i>=1;i--){
for(j=i;j>0;j--){
printf("%d",start);
}
printf("\n");
start--;
}
//printf("%d",start);
getchar();
return 0;
}
/*
OUTPUT :-
Enter the number to start 5
5
66
777
8888
8888
777
66
5
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment