1
23
456
78910
#include<stdio.h>
int main()
{
int i,j,k;
k=1;
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",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
program to print the above pattern up to a given value n & the program should use a function which takes n as its parameter..........
ReplyDeletepls help me....
#include
Deleteint main()
{
int i,j,k,n;
printf("Enter value of n:")
scanf("%d",&n);
k=1;
for(i=1;i<n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",k++);
}
printf("\n");
}
return 0;
}
#include
Deleteint main()
{
int i,j,k;
k=1;
printf("%d",k);
printf("\n");
for(i=2;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",k++);
}
printf("\n");
}
return 0;
}
If k=1 then it will print 2 ati=1 and j=1. We need 1 at I=1and j=1. So we need to put k=0 no?
Deleteinsert printf and scanf to scan the value of n
ReplyDeletethen instead of i<5, put i<n
the program has prototype error.
ReplyDeletesir pls do this program using only two variable i and j not any other variable
ReplyDeletewhy j<=i
ReplyDeleteankita anand ,
ReplyDeletebecause u cannot predict the value naturally that where its ending in each row that is
weather 3 6 pr 10
in the ist line its printing from 1 to 1 as the value of i is equal to 1
similarly
in the second line its printing the from the incremented value of i ie
from 2 to 3 as i = 2 here so two time u are printing two numbers two and 3 as k is also incrementing simultaneously
got it?
#include
ReplyDeleteint main()
{
int r,i,j,k;
printf("Enter the no. of rows : ");
scanf("%d",&r);
for(i=1,k=1;i<=r;i++)
{
for(j=1;j<=i;j++,k++)
{
printf("%d",k);
}
printf("\n");
}
}
// A program written very silly
ReplyDelete1 // Program will display the following pattern
2 // 1
3 // 2 3
4 // 4 5 6
5 // 7 8 9 10
6 #include
7
8 int main(void)
9 {
10
11 int i, j, k;
12
13 for(i = 1, k = 0; i < 10; ++k, i += k)
14 {
15 for(j = i; j <= (k + i); j++)
16 {
17 printf("%3d", j);
18 }
19 printf("\n");
20 }
21 return 0;
22 }
Sir can you please explain why we are getting output from 1 ,if k++ has been used and it was initialised by 1 the output should start from 2 .
ReplyDeletek++ is postfix increment, which is done after the statement is executed.
DeleteThank you so much sir.
Deletevery strong logic good sir g
ReplyDelete#include
ReplyDeletevoid main()
{
int i,j;
for(i=1;i<5;i++)
{
for(j=i*(i-1)/2+1;j<=i*(i+1)/2;j++)
printed("%d ",j);
print("\n");
}
}
thanku
ReplyDeleteWrite a C program for the following pattern?
ReplyDelete0
7 0 7
6 7 0 7 6
5 6 7 0 7 6 5
4 5 6 7 0 7 6 5 4
3 4 5 6 7 0 7 6 5 4 3
2 3 4 5 6 7 0 7 6 5 4 3 2
1 2 3 4 5 6 7 0 7 6 5 4 3 2 1