## INDEX

### Write a c program to print Pascal triangle.

1. Pascal triangle in c without using array

2. C code to print Pascal triangle

3. Simple c program for Pascal triangle

4. C program to generate Pascal triangle

5. Pascal triangle program in c language

6. C program to print Pascal triangle using for loop

#include<stdio.h>

long fact(int);
int main(){
int line,i,j;

printf("Enter the no. of lines: ");
scanf("%d",&line);

for(i=0;i<line;i++){
for(j=0;j<line-i-1;j++)
printf(" ");

for(j=0;j<=i;j++)
printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
printf("\n");
}
return 0;
}

long fact(int num){
long f=1;
int i=1;
while(i<=num){
f=f*i;
i++;
}
return f;
}

Sample output:

Enter the no. of lines: 8
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1

10. Write a c program to add two numbers without using addition operator.
11. Write a c program to subtract two numbers without using subtraction operator.
15. Write a c program to solve quadratic equation.
18. Write a c program which passes structure to function.
28. Write a c program which takes password from user.
29. Write a scanf function in c which accept sentence from user.
30. Write a scanf function in c which accept paragraph from user.

#### 58 comments:

Anonymous said...

good site
thanks to Administrator

Ruchi said...

#include
int main()
{
int i,j,k,n,m;
printf("Enter the range ");
scanf("%d",&n);
m = n-1;
for(i=1;i<=n;i++)
{
k = i;
j = m;
while(j)
{
printf(" ");
j--;
}
while(k)
{
printf("*");
printf(" ");
k--;
}
printf("\n");
m--;
}
}

radman said...

dude your code is right but this a code for pyramid

Einstein's Descendents said...

please write a program to display all the perfect and prime numbers within a range.
(I tried them, but after entering the range, the screen holds showing nothing.. on further clicking the program execution exits)

GUNAVATHIPALANISAMY said...

how to say a number is perfect or not?

rose_preethi said...

The 6 is a perfect number , because we can divide a 6 by 1,2,3 and if we add 1+2+3 we will get an answer as 6... When the sum of divisior of a particular number is equal to the number then we say that is a perfect number..
Another Example is 28 which is divided by 1,2,4,7,14 and when we add the number we will get as 28, 1+ 2 + 4 + 7 + 14 = 28

Ritesh kumar said...

Hi Pavani,
Which compiler are you using?

preema& reema said...

good site,thank u.......

prasad said...

wat is pascal triangle

sandhya said...

confusin

sandhya said...

incomplete,,,,,,,,,,,,, jst luk 1st for loop of i

Raja said...

gud clean example

dinilps said...

simple way with out using function....

#include
#include

void main()
{
int i,j,n,c,k,space;
clrscr();
printf("Enter the limit ");
scanf("%d",&n);
printf("\n\n");
space=n;
for(i=0;i<=n;i++)
{
c=1;
for(k=space;k>=0;k--)
printf(" ");

space--;
for(j=0;j<=i;j++)
{
printf("%d ",c);
c=(c*(i-j)/(j+1));
}
printf("\n");
}
getch();
}

Parminder Singh said...

why hav u used long datatype for fact() function... why d things don't work up with int as a return type???
Please reply me at psvalent05@yahoo.com

farzana said...

function get more confusion....

farzana said...

function get more confusion....

Anonymous said...

lots of confusion.....

Raja Venkatesh said...

can u please give me solution for the following pattern
1
2 2
3 3 3
4 4 4 4

Kranthi Akula said...

send code for fallowing o/p::
1
2 3
4 5 6
7 8 9 10

Anonymous said...

#include
void main()
{
int x,y;
for(x=1;x<=4;x++)
{
for(y=1;y<=x;y++)
printf("%2d",x);
printf("\n");
}

}

Anonymous said...

can u please give me solution for the following pattern...
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

ritesh kumar said...

I hope thins link will help you:
C program to print different shapes using printf function

Anonymous said...

can u pls give me solution for fibonacci series in use for loop...

Anonymous said...

thank u

Anonymous said...

can u pls provide ans for dis
5987
987
87
7

NageswaraRao Ch said...

provide the answer this question

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1

Anonymous said...

#include
int main()
{
int i,j,n,c;
printf("Enter the limit ");
scanf("%d",&n);
printf("The pascal triangle is print in floyd's triangle\n\n");
for(i=0;i<n;i++)
{
c=1;
for(j=0;j<=i;j++)
{
printf("%d ",c);
c=(c*(i-j)/(j+1));
}
printf("\n");
}
return;
}

by Muthusamy.S GCT

Anonymous said...

#include
int main()
{
int r,n,c;
printf("Enter the limit ");
scanf("%d",&n);
int s=n;
for(r=0;r<n;r++)
{
for(c=1;c<=s;c++)
{
printf("%d ",c);
}
s--;
printf("\n");
}
return;
}
by Muthusamy.s from GCT

Anonymous said...

#include
int main()
{
int r,n,c;
printf("Enter the limit ");
scanf("%d",&n);
int s=n;
for(r=0;r<n;r++)
{
for(c=1;c<=s;c++)
{
printf("%d ",c);
}
s--;
printf("\n");
}
return;
}
by Muthusamy.s from GCT

srinath reddy said...

stack operations are used for storing elements in a stack. The input method for stack is last in first out. Thank you for sharing this program.
regards:
srinath reddy.
admin of Programming Tutorials for Beginners

simson raj said...

#include
#include
#include
void main()
{
int a[20],n,n1,num,sum=0,r,i,j;
clrscr();
printf("enter the power of 11");
scanf("%d",&n);
for(i=0;i0)
{
r=num%10;
//sum=sum+r;

printf(" %d ",r);
num=num/10;
}
printf("\n");

}

getch();
}

Anonymous said...

can someone tell me whats wrong with this code for generating pascal triangle .iwish to print the pascal triangle line by line without having to induct spaces among elements

int fact1(int j)
{
int k=1,i;
for(i=j;i>=0;i-- ){
k=i*k;
}
return k;
}

int main()
{
int res,line,k;
for(line=0;line<7;line+=1){
for(k=0;k<line;k++)
{
res=fact1(line)/fact1(line-k)*fact1(k);
printf("%d\t",res);
}
printf("\n");
}
return 0;
}

Anonymous said...

#include

int main()
{
int n, i, c, a = 1;

printf("Enter the number of rows of Floyd's triangle to print\n");
scanf("%d", &n);

for (i = 1; i <= n; i++)
{
for (c = 1; c <= i; c++)
{
printf("%d ",a);
a++;
}
printf("\n");
}

return 0;
}

Anonymous said...

#include
int main ()
{
int i,j,a=1;
for(i=1;i<=4;i++){
for(j=1;j<=i;j++){
printf ("%d ",a);
}
a++;
printf ("\n");
}
getchar();
return 0;
}

Anonymous said...

****** *******
***** *****
*** ***
** **
* *

provide answer for this

Anonymous said...

Thanx a lot darling...!!!!!!!!

avadh kumar sharma said...

nice but plz give the many pascal question that we butter understand about the pascal.....

Shehin Fn said...

I have this one works 100% i coded this my self although it's little foolish
#include
main()
{
int i, j, b[50],a[50],k,n,count;
printf("enter the limit \n") ;
scanf("%d", & n) ;

for(i=0;i0;k--)
printf(" ");
printf("1 \n\n");
}
if(j==1)
{
for(k=2*(n-i) ;k>0;k--)
printf(" ");
printf("1 ");
}
}
count=0;
k=0;
for(j=1;j<i;j++)
{
a[1]=1;
a[i]=1;
b[k]=a[j]+a[j+1];
printf(" %d ", b[k]) ;
k++;
count++;
}
for(j=2,k=0;k<=i-1;j++, k++)
a[j]=b[k] ;
for(j=1;j<=i;j++)
{
if(j==i)
{
printf(" 1");
printf("\n\n") ;
}
}
}
return 0 ;
}

Shehin Fn said...

please add header file #include < stdio. h>

Krishna chowdary said...

#include
#include

int main()
{
int a[10][10];
int no;
printf("Enter the number of rows for pascal triangle : ");
scanf("%d",&no); //taking input
for(int i=1; i<=no; i++)
{
for(int j=1; j<=i; j++)
{
if(j==1||j==i)
{
a[i][j]=1;
}
else // taking arrays value
{
a[i][j]=a[i-1][i-j]+a[i-1][i-j+1];
}
}
}
for(int i=1; i<=no; i++)
{
for(int k=1; k<=no-i; k++)
{
printf(" ");
}
for(int j=1; j<=i; j++)
{
printf("%d ",a[i][j]); //printing pascal triangle
}
printf("\n");
}
getch();
}

Krishna chowdary said...

simple easy approach

#include
void main()
{
int i,j,x,n,s;
printf("Enter The Number : ");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
x=1;
for(s=1;s<=n-i;s++)
printf("\t");
for(j=1;j<=i+1;j++)
{
printf("%d\t\t",x);
x=x*(i-j+1)/j;
}
printf("\n");
}
}

Harendra Nath Choudhury said...
This comment has been removed by the author.
Harendra Nath Choudhury said...

#include
main()
{
int i,j,n,k,temp,c;

printf("Enter the number of lines\n");
scanf("%d",&n);
printf("\n\n");
temp=n;
for(i=0;i<=n;i++,printf("\n"))
{
c=1;
for(k=temp;k>=0;k--)
printf(" ");
temp--;
for(j=0;j<=i;j++)
{
printf("%d ",c);
c=(c*(i-j)/(j+1));
}
}

}

YARRAYYA Barri said...
This comment has been removed by the author.
YARRAYYA Barri said...

plz tell me code of this patten:

1*2*3*4*17*18*19*20
-5*6*7*14*15*16
--8*9*12*13
---10*11

Tarek Magdy said...

please i want pointers codes

JMP V said...

how to do this???

A1234
AB123
ABC12
ABCD1
ABCDE

Please... answer my question... Thanks... ^_^

Unknown said...

Small correction : if we give n rows it will print n+1 rows ,so write I<n in first for loop

Morad Alyan said...

1
1
2
12
3
123
4
1234

Unknown said...

if num=3 then
1
2*3
4*5*6
4*5*6
2*3
1

saeed ahmad said...

can u please give me solution of this question?
Question: Write program using loop to draw 50 stars in five rows.Through pascal programming language.

saeed ahmad said...

can u please give me solution of this question?
Question: Write program using loop to draw 50 stars in five rows.Through pascal programming language.

Wasif Khan said...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication39
{
class Program
{
static void Main(string[] args)
{
int i, j;
for(i=0 ;i<5 ;i++)
{
for(j=5 ;j>i;j--)
{
Console.Write("*");

}
Console.Write(" ");
for (j = 5; j > i; j--)
{
Console.Write("*");

}
Console.ReadLine();
}

}
}

}

cyrus Browns said...

can you assist me to create a pascal program to output the digital pyramid

Nithish Rao said...

any 1 can solve tis plzzzzz
1
12
123
12345 tis is a o/p u can gv a sol. plzzzz gv me soon

vivek kurapati said...

How can we execute with out using factorial.

raj kumar said...

ruchi is it a star pattern program

Avi Singh said...

can u help me to write a program in c

rite a program to print the first n terms in the series
2, 6, 11, 10, 15, 21, 18, 24, 31, 26, 33, 41 ....

Input and Output Format:
Input consists of a single integer 'n' that corresponds to the number of terms to be printed.

Output consists of n terms in the series separated by a single space. There is a trailing space at the end of the series.

Sample Input:
12
Sample Output:
2 6 11 10 15 21 18 24 31 26 33 41