55555
45555
34555
23455
12345
int main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
k = i;
for(j=1;j<=5;j++)
{
if(k <= 5)
{
printf("%d",k);
}
else
{
printf("5");
}
k++;
}
printf("\n");
}
return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C
class Pattern
ReplyDelete{
public static void main(String arr[])
{
int k;
for(int i=5;i>=1;i--)
{
k=i;
for(int j=1;j<=5;j++)
{
System.out.print(k);
k++;
if(k>5)
k=5;
}
System.out.println();
}
}
}
please explain this one.sir.
ReplyDeletedear sarathi its quite a easy one
Deleteits like how u think to take the values of i and j
say in the pattern above
threre are 5 rows which are constantly decreasing ie 5
4
3
2
1
so i's value ranges from 5 to 1
then come to j
u c j's work is to determine how many times it will print all right ?
so u would not print j here beacause j's starting from various intergers in various rows so we take the 3rd variable k which is equal to the value of i
now it(k) would print from 5 to the value of 5 as done by jth row
so there comes the ist line 5 as 5times now
i will decrement as i--
so k also will be equals to 4 as now i =4 so for the second row it will print 4 then k will increment and will print 5 as k still<=5 right?
then since k will increment to 6 so k would print 5 only as
if(k <= 5)
{
printf("%d",k);
}
else
{
printf("5");
}
k++;
so any value greater than 5 for k would be printed as 5 upto 5 times as j remains within i to 5 only
so this would continue until i reaches 1
this was the full explanation of how this code works
my suggestion u always must bresk up a code into units and then analyze
it is not correct
Delete#include
ReplyDeleteint main()
{
int r,i,j,k;
printf("Enter the no. of rows : ");
scanf("%d",&r);
for(i=r;i>=1;i--)
{
for(j=i;j<=r-1;j++)
{
printf("%d",j);
}
for(k=1;k<=i;k++)
{
printf("%d",r);
}
printf("\n");
}
}
Write a Java program for the given problem George loves to play with numbers. His friend Zuckerberg gives him two numbers to add. Zuckerberg writes sometimes 6 as 5 and vice versa. Given two numbers as x and y. Find the maximum and minimum sum Zuckerberg could possibly get the numbers?
ReplyDeleteIt could be done simply like this also
ReplyDeleteInt i, j,k,l;
For(I=5; I>=1;i--)
{
For(j=I;j<=4;j++)
{
Pritf("%d",j);
}
For (k=1;k<=I; k++)
{
l=5;
Printf("%d",l);
}
Printf ("\n");
}
#include
ReplyDeletevoid main()
{
int i,j,k;
for(i=5;i>=1;i--)
{
k=i;
for(j=1;j<=5;j++)
{
k<=5?printf("%d",k++):printf("5");
}
printf("\n");
}
}
12345
ReplyDelete22345
33345
44445
55555
I want to print this pattern.
int main()
Delete{
int i, j, k,n;
printf("\n enter n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
k = i;
for(j=1;j<=n;j++)
{
if(j <= k)
{
printf("%3d",k);
}
else
{
k++;
printf("%3d",k);
}
}
printf("\n");
}
return 0;
}
class Pattern4{
ReplyDeletepublic static void main(String[] args){
int ab=4;
square(ab);
}
static void square(int num){
//int count=0;
int count=1;
for(int i=0;i<(num+num-1);i++){
//System.out.print(count);
for(int j=1;j<=(num+num-1);j++){
//count=j;
if(j<=count){
System.out.print(count);
continue;
}
System.out.print(j);
}
count++;
System.out.println("");
}
}
}
5 4 1 2 3
ReplyDelete10 9 6 7 8
15 14 11 12 13
20 19 16 17 18
25 24 21 22 23
11112
ReplyDelete32222
33334
54444
55556
Code for this please
123
Delete456
789
As per the pattern the above program is not correct
ReplyDeletefor this pattern
ReplyDelete1234
1234
1234
1234