Q. Write the following number pattern program in C language as:
123454321
1234321
12321
121
1
Ans.
Before we start to write the source code of above number pattern program, if you look carefully on above pattern, there are 2 number pattern shows as:
123454321
1234321
12321
121
1
So just make above 2 number pattern and merge them, that's it, done! cheers!!
let's start the coding in C.
/*c program for number pattern*/
#include<stdio.h>
int main()
{
int num,r,c,n;
printf("Enter any number : ");
scanf("%d", &num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=1; c<=n; c++)
printf("%d", c);
for(c=n-1; c>=1; c--)
printf("%d", c);
printf("\n");
}
getch();
return 0;
}
You might also like:
123454321
1234321
12321
121
1
Ans.
Before we start to write the source code of above number pattern program, if you look carefully on above pattern, there are 2 number pattern shows as:
123454321
1234321
12321
121
1
So just make above 2 number pattern and merge them, that's it, done! cheers!!
let's start the coding in C.
/*c program for number pattern*/
#include<stdio.h>
int main()
{
int num,r,c,n;
printf("Enter any number : ");
scanf("%d", &num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=1; c<=n; c++)
printf("%d", c);
for(c=n-1; c>=1; c--)
printf("%d", c);
printf("\n");
}
getch();
return 0;
}
/****************************************************************
The output of above program would be:
******************************************************************/
Figure: Screen shot of Number Pattern In C Programming Language |
You might also like:
আমি বুঝতে পারলাম না !!!
ReplyDeleteThank you for sharing.
ReplyDelete