Q. Write a program to generate a following numbers triangle:
(Where user entered number through keyboard, for example if num=5)
1
12
123
1234
12345
Ans.
/* c program for number triangle*/
#include<stdio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; r<=num; r++)
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
1
12
123
1234
12345
***********************************/
i believe i am doing something wrong. but thanks a million to the programmer. it didn't work out trying to figure out....
ReplyDelete@banta savrait khanda,
DeleteAbove program is working, Write down your program for discuss and solutions.
I am going to recheck it this evening when I come home.
ReplyDeleteI comment above program in two lines bcoz C is working according to compiler. So you can check your program in different compiler.
DeleteI wants Write a program to generate a numbers triangle using while please explain me
ReplyDeletehow to print
ReplyDelete1234
2341
3421
4321
how to print
ReplyDelete1234
2341
3421
4321
void main()
Delete{
int i,j,k;
clrscr();
for(i=1;i<5;i++)
{
for(j=i;j<5;j++)
{
printf("%d",j);
}
k=i;
while(k>1)
{
printf("%d",k-1);
k--;
}
printf("\n");
}
getch();
}
void main()
Delete{
int i,j,k;
clrscr();
for(i=1;i<5;i++)
{
for(j=i;j<5;j++)
{
printf("%d",j);
}
k=i;
while(k>1)
{
printf("%d",k-1);
k--;
}
printf("\n");
}
getch();
}
how to print a
ReplyDeletea
ab
abc
abcd
@Karthik, your required character pattern design C program source code at:
Delete#include"stdio.h"
int main()
{
char ch,r,c;
printf("Enter any character : ");
scanf("%c", &ch);
if(ch>='a' && ch<='z')
ch=ch-32;
for(r='A'; r<=ch; r++)
{
for(c='A'; c<=r; c++)
printf("%c", c);
printf("\n");
}
getch();
return 0;
}
4
ReplyDelete43
432
4321
@Toki Tahmid Inan,
DeleteYour required Number Pyramid Source Code at:
#include"stdio.h"
int main()
{
int num,r,c,n;
printf("Enter Any Number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1,n=num; c<=r; c++,n--)
printf("%d", n);
printf("\n");
}
getch();
return 0;
}
1
ReplyDelete1 3
1 3 5
1 3 5 7
@ Nahidul Islam
DeleteYour required odd number triangle source code as:
#include"stdio.h"
int main()
{
int num,r,c,z;
printf("Enter no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1,z=1; c<=r; c++,z=z+2)
printf("%d ",z);
printf("\n");
}
getch();
return 0;
}
Hey please can u give me souce code for this
ReplyDelete1
**
234
****
5678
@ Nogs Mujeeb
DeleteYour required symbol number triangle C program source code as:
#include"stdio.h"
int main()
{
int num=5,r,c,p=1,q;
for(r=1; r<=num; r++)
{
if(r%2==0)
{
for(c=r; c>=1; c--)
printf("*");
}
else
{
for(c=r; c>=1; c--,p++)
printf("%d",p);
}
printf("\n");
}
getch();
return 0;
}
#include
ReplyDeletemain()
{
int i,j,k,n,l;
printf("Enter the number of rows");
scanf("%d",&n);
for(i=0;i<n;i++)
{
l=1;
for(j=0;j<=i;j++)
{
printf("%d",l);
l++;
}
printf("\n");
}
}
5
ReplyDelete4 4
3 3 3
2 2 2 2
1 1 1 1 1
pls reply fr this pattern
# Lalit Kumar
DeleteSource code for above number triangle pyramid program source code as:
#include "stdio.h"
int main()
{
int num,r,c,n;
printf("Enter loop start no. : ");
scanf("%d",&num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=1; c<=r; c++)
printf(" %d",n);
printf("\n");
}
getch();
return 0;
}
/******Output*******/
Enter loop start no. : 5
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1