12345 1234 123 12 1
#include <stdio.h>
int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C
what is the error in this code for the above program?
ReplyDelete#include
main()
{
int i,j;
for( i=1; i>=5;i--)
{
for(j=1;j<5-(i-1);j++)
{
printf("%d",j);
}
printf("\n");
}
}
How this fow loop condition will get satisfied ??
Deletefor( i=1; i>=5;i--)
i is eq 1 and your condition is i >=5 which will be false...
for condition is false:
Deletecorrect condition
for(i=1;i<=5;i++)
This comment has been removed by the author.
Delete#include
ReplyDeleteusing namespace std;
int main(){
int n,i,j;
cout<<"asdf";
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<n-i+1;j++){
cout<<j;
}
cout<<endl;
}
return 0;
}
write the same program with the help of a while loop
ReplyDelete/*
Delete* To represent the parts of a for loop,
* we'll use the for(x;y;z) representation,
* where x is the initializer (e.g. i = 1),
* y is the conditional statement (e.g. i <= j),
* and z is the increment statement (e.g. ++j).
*
* In this code, there are two loops used,
* so we'll refer to first one as the outer loop,
* and the second as the inner loop.
*/
#include
void main(void)
{
int i, j;
printf("Enter a number (for lines): ");
scanf("%d", &i); /* If we are to use the value inputted here
* as the initial value for our outer loop below,
* then we need not initialize it,
* i.e., we would leave the x part of the for loop,
* so it looks like 'for(;y;z)' if we use the for loop
*/
while (i) // 'while(i)' is basically the same as 'while(i>0)' here
{ // since any nonzero number is considered true. This is the outer y.
j = 1; // This is the inner x.
while (j <= i) // The inner y.
{
printf("%d ", j);
++j; // The inner z.
}
printf("\n");
--i; // The outer z.
}
}
/* You see, the program is really hard to read and maintain
* if we use while loop for these things, that's why for loops
* are preferred here.
*/
temp=n;
ReplyDeletefor(i=1;i<=n;i++)
{
for(j=1;j<=temp;j++)
printf("j");
temp--;
printf("\n");
}
no errors
DeleteWat is the need of temp--
Deleteint i,j;
ReplyDeletefor(i=1;i<=5;i++) {
for(j=1;j<=(6-i);j++) {
printf("%d",j);
}
printf("/n");
}
#include
ReplyDeleteint main()
{
int r,i,j;
printf("Enter the number of rows : ");
scanf("%d",&r);
for(i=1;i<=r;i++)
{
for(j=1;j<=r-i+1;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
Bhai easy language me kaise likhe...,
DeleteThe soltn is incorrect there is no coding for sopace first apply for loop for space then another for loop to print the pattern
ReplyDeleteWrite a program to input any Sentence and find the longest word and the second longest word.
ReplyDeleteeg: India is my Country
longest word: Country
Second longest word: India.
How do i write this program.
somebody please explain me this code
ReplyDeleteexplain this code please
ReplyDelete#include
ReplyDeletevoid main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=6-i;j++)
{
printf("%d",j);
}
printf("\n");
}
}
can you write a pragram for belo pattern
ReplyDelete12345
1234
123
12
1
no i can't,bcz i dont know.HAHAHA(lol)
Delete#include
ReplyDeleteint main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=n;j>=i;j--)
{
printf("%d ",n-j+1);
}
printf("\n");
}
return 0;
}
int main()
ReplyDelete{
int k,n,i,j;
scanf("%d",&n);
k=n;
for(i=1;i<=n;i++)
{
for(j=1;j<=k;j++)
{
printf("%d ",j);
}
printf("\n");
k--;
}
return 0;
}
correct answer is i<=1
ReplyDeletethe error is i>=1
In C++ language.
ReplyDelete#include
using namespace std;
int main(){
int n;
cin >> n;
int i = 1;
while(i<=n){
int j = 1;
while(j <= n-i+1){
cout << j;
j++;
}
i++;
cout << endl;
}
}
Helpful article...learn more C programming examples from Pattern Programs
ReplyDeleteGood brother..here anyone interested in digital marketing, visit expertskeys.com
ReplyDeleteA2C4E
ReplyDelete1B3D
A2C
1B
A
PLEASE GIVE ME A SOLUTION
12345
ReplyDelete1234
123
12
1
program for this one