Simple C Program :
Program :
/* Simple C Program .
Creation Date : 12:34 PM 07/11/2010
Author : R.K.Singh*/
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
printf("n My first program in C !");
getch();
}
Output :
My first program in C !_
Program to print value of existing
number :
Program :
/* Program to print value of existing number .
Creation Date : 12:38 PM 07/11/2010
Author :R.K.Singh */
#include <stdio.h>
#include <conio.h>
void main()
{
int no = 19;
clrscr();
printf("n Number is : %d",no);
getch();
}
Output :
Number is : 19 !_
Program to demonstrate scanf()
and printf() : 3.C :
Program :
/* Program to demonstrate scanf() and printf().
Creation Date : 12:41 PM 07/11/2011
Author : R.K.Singh */
#include <stdio.h>
#include <conio.h>
void main()
{
int no;
clrscr();
printf("n Enter any number :");
scanf("%d",&no);
printf("n Number is : %d",no);
getch();
}
Output :
Enter any number :12
Number is : 12_
Operators
Program to calculate addition of two
numbers :
Program :
/* Program to calculate addition of two numbers.
Creation Date : 09:51 PM 21/11/2011
Author : R.K.Singh */
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
clrscr();
printf("n Enter any 2 numbers : ");
scanf("%d %d",&a,&b);
c = a + b;
printf("n Addition is : %d",c);
getch();
}
Output :
Enter any 2 numbers : 12 14
Addition is : 26_
Program to calculate subtraction of two
numbers :
/* Program to calculate subtraction of two numbers.
Creation Date : 10:43 PM 21/11/2011
Author : R.K.Singh */
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
clrscr();
printf("n Enter any 2 numbers : ");
scanf("%d %d",&a,&b);
c = a - b;
printf("n Subtraction is : %d",c);
getch();
}
Output :
Enter any 2 numbers : 8 6
Subtraction is : 2_
Program to calculate division of two
numbers :
Program :
/* Program to calculate division of two numbers.
Creation Date : 10:58 PM 21/11/2011
Author : R.K.Singh */
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
clrscr();
printf("n Enter any 2 numbers : ");
scanf("%d %d",&a,&b);
c = a / b;
printf("n Division is : %d",c);
getch();
}
Output :
Enter any 2 numbers : 12 5
Division is : 2_
Program to calculate multiplication of
two numbers :
• Program :
• /* Program to calculate multiplication of two numbers.
• Creation Date : 10:51 PM 21/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int a,b,c;
• clrscr();
• printf("n Enter any 2 numbers : ");
• scanf("%d %d",&a,&b);
• c = a * b;
• printf("n Multiplication is : %d",c);
• getch();
• }
Output :
Enter any 2 numbers : 8 12
Multiplication is : 96_
Program to calculate modulus of two
numbers :
• Program :
• /* Program to calculate modulus of two numbers.
• Creation Date : 11:01 PM 21/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int a,b,c;
• clrscr();
• printf("n Enter any 2 numbers : ");
• scanf("%d %d",&a,&b);
• c = a % b;
• printf("n Modulus is : %d",c);
• getch();
• }
Output :
Enter any 2 numbers : 11 5
Modulus is : 1_
Pyramid in c
Program to print pyramid in C :
Pattern 1 :
• Program :
• /* Program to print pyramid pattern in C : Pattern 1
• Creation Date : 12:36 AM 22/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j;
• clrscr();
• for(i=0; i<5; i++)
• {
• for(j=0; j<5; j++)
• {
• printf(" * ");
• }
• printf("n");
• }
• getch();
• }
Output :
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *_
Program to print pyramid in C :
Pattern 2 :
• Program :
• /* Program to print pyramid pattern in C : Pattern 2
• Creation Date : 12:43 AM 22/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j;
• clrscr();
• for(i=0; i<5; i++)
• {
• for(j=0; j<=i; j++)
• {
• printf(" * ");
• }
• printf("n");
• }
• getch();
• }
Output :
*
* *
* * *
* * * *
* * * * *_
Program to print pyramid in C :
Pattern 3 :• /* Program to print pyramid pattern in C : Pattern 3
• Creation Date : 12:28 AM 22/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j,k;
• clrscr();
• for(i=1; i<=5; i++)
• {
• for(j=5; j>=i; j--)
• {
• printf(" ");
• }
• for(k=1; k<=i; k++)
• {
• printf("*");
• }
• printf("n");
• }
• getch();
• }
Output :
*
* *
* * *
* * * *
* * * * *_
Program to print pyramid in C :
Pattern 4 :• /* Program to print pyramid pattern in C : Pattern 4
• Creation Date : 12:54 AM 22/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j,k,samp=1;
• clrscr();
• for(i=5; i>=1; i--)
• {
• for(k=samp; k>=0; k--)
• {
• printf(" "); // only 1 space
• }
• for(j=i; j>=1; j--)
• {
• printf("*");
• }
• samp = samp + 1;
• printf("n");
• }
• getch();
• }
Output :
* * * * *
* * * *
* * *
* *
*_
Program to print pyramid in C :
Pattern 5 :
• Program :
• /* Program to print pyramid pattern in C : Pattern 5
• Creation Date : 01:08 AM 22/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j;
• clrscr();
• for(i=5; i>=1; i--)
• {
• for(j=1; j<=i; j++)
• {
• printf(" * ");
• }
• printf("n");
• }
• getch();
• }
Output :
* * * * *
* * * *
* * *
* *
*_
Program to print pyramid in C :
Pattern 6 :
• Program :
• /* Program to print pyramid pattern in C : Pattern 6
• Creation Date : 01:52 AM 22/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j,k,t=0;
• clrscr();
• for(i=1; i<=5; i++)
• {
• for(k=t; k<5; k++)
• {
• printf(" ");
• }
• for(j=0; j< i; j++)
• {
• printf(" * ");
• t = t + 1;
• }
• printf("n");
• }
• getch();
• }
Output :
*
* *
* * *
* * * *
* * * * *_
Program to print pyramid in C :
Pattern 7 :• Program :
• /* Program to print pyramid pattern in C : Pattern 7
• Creation Date : 01:13 AM 22/11/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j,k,samp=1;
• clrscr();
• for(i=1; i<=5; i++)
• {
• for(k=samp; k<=5; k++)
• {
• printf(" ");
• }
• for(j=0; j< i; j++)
• {
• printf("*");
• }
• samp = samp + 1;
• printf("n");
• }
• samp = 1;
• for(i=4; i>=1; i--)
• {
• for(k=samp; k>=0; k--)
• {
• printf(" ");
• }
• for(j=i; j>=1; j--)
• {
• printf("*");
• }
• samp = samp + 1;
• printf("n");
• }
• getch();
• }
•
Output :
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*_
Program to print pyramid in C :
Pattern 8 :
• Program :
• /* Program to print pyramid pattern in C : Pattern 8
• Creation Date : 02:39 PM 01/10/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int rw, c, no=1 ,len;
• clrscr();
• printf("Enter number of rows: ");
• scanf("%d," &len);
• for(rw=1; rw<=len; rw++)
• {
• printf("n");
• for(c=1; c<=rw; c++)
• {
• printf(" %2d ", no);
• no++;
• }
• }
• getch();
• }
Output :
Enter number of rows: 5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15_
Program to print pyramid in C :
Pattern 9 :• Program :
• /* Program to print pyramid pattern in C : Pattern 9
• Creation Date : 03:19 PM 01/10/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int no,i,y,x=35;
• clrscr();
• printf("Enter number of rows: ");
• scanf("%d," &no);
• for(y=0;y<=no;y++)
• {
• goto(x,y+1);
• for(i=0-y; i<=y; i++)
• {
• printf(" %3d ", abs(i));
• x=x-3;
• }
• }
• getch();
• }
Output :
Enter number of rows: 5
0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
5 4 3 2 1 0 1 2 3 4 5_
Program to print pyramid in C :
Pattern 10 :
• Program :
• /* Program to print pyramid pattern in C : Pattern 10
• Creation Date : 03:14 PM 01/10/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i, j=5, k, x;
• clrscr();
• for(i=1;i<=5;i++)
• {
• for(k=1;k<=j;k++)
• {
• printf(" ");
• }
• for(x=1;x<=i;x++)
• {
• printf("%d",i);
• printf(" ");
• }
• printf("n");
• j=j-1;
• }
• getch();
• }
Output :
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5_
Program to print pyramid in C :
Pattern 11 :• Program :
• /* Program to print pyramid pattern in C : Pattern 11
• Creation Date : 03:24 PM 01/10/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int rw,c,no,spc;
• clrscr();
• printf("Enter number of rows : ");
• scanf("%d", &no);
• for(rw=1; rw<=no; rw++)
• {
• for(spc=no; spc>=rw; spc--)
• {
• printf(" ");
• }
• for(c=1; c<=rw; c++)
• {
• printf("%2d",c);
• }
• printf("n");
• }
• getch();
• }
Output :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5_
Program to print pyramid in C :
Pattern 12 :
• Program :
• /* Program to print pyramid pattern in C : Pattern 12
• Creation Date : 03:24 PM 01/10/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j,k;
• clrscr();
• for(i=1; i<=5; i++)
• {
• for(j=1; j<=5-i; j++)
• {
• printf(" ");
• }
• for(k=1; k<=2*i-1; k++)
• {
• printf(" %d ",k);
• }
• printf("n");
• }
• getch();
• }
Output :
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9_
Program to print pyramid in C :
Pattern 13 :
• Program :
• /* Program to print pyramid pattern in C : Pattern 13
• Creation Date : 04:24 PM 01/10/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int i,j,asci,spc;
• clrscr();
• for(i=7; i>=1; i--)
• {
• for(spc=6; spc>=i; spc--)
• {
• printf(" ");
• }
• asci=65;
• for(j=1; j<=i; j++)
• {
• printf("%2c",asci++);
• }
• for(j=i-1; j>=0; j--)
• {
• printf("%2c",--asci);
• }
• printf("n");
• }
• getch();
• }
Output :
A B C D E F G G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A_
Program to all Combinations of
characters A,B,C in C : Pattern 14 :
• Program :
• /* Program to print all Combinations of characters
A, B, C : Pattern 14
• Creation Date : 11:33 PM 01/10/2011
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• char ch1, ch2, ch3;
• clrscr();
• for(ch1='A' ; ch1<='C' ; ++ch1)
• {
• for(ch2='A' ; ch2<='C' ; ++ch2)
• {
• for(ch3='A' ; ch3<='C' ; ++ch3)
• {
• printf(" %c%c%c", ch1, ch2, ch3);
• }
• }
• }
• getch();
• }
Output :
AAA AAB AAC ABA ABB ABC ACA ACB ACC BAA BAB BAC BBA BBB
BBC BCA BCB BCC CAA CAB CAC CBA CBB CBC CCA CCB CCC_
Addition of two matrices :
Program :
/* Program to demonstrate addition of two matrices. Creation Date : 25 Nov 2011 11:35:00 PM
Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
•
• void main()
• {
• int a[3][3],b[3][3],c[3][3],i,j;
• clrscr();
• printf("nt Enter First Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• printf("nt Enter Second Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&b[i][j]);
• }
• }
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• c[i][j]=a[i][j]+b[i][j];
• }
• }
• printf("nt Matrix Addition is : nn");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• printf("t %d",c[i][j]);
• }
• printf("n");
• }
• getch();
• }
Output :
Enter First Matrix : 2 1 2
3 2 1
2 3 3
Enter Second Matrix : 2 1 0
2 3 0
1 1 2
Matrix Addition is :
4 2 2
5 5 1
3 4 5_
Subtraction of two matrices :
• Program :
•
• /* Program to demonstrate subtraction of two matrices.
• Creation Date : 25 Nov 2011 11:42:08 PM
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
•
• void main()
• {
• int a[3][3],b[3][3],c[3][3],i,j;
• clrscr();
• printf("nt Enter First Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• printf("nt Enter Second Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&b[i][j]);
• }
• }
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• c[i][j]=a[i][j]-b[i][j];
• }
• }
• printf("nt Matrix Subtraction is : nn");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• printf("t %d",c[i][j]);
• }
• printf("n");
• }
• getch();
• }
Output :
Enter First Matrix : 2 1 2
3 2 1
2 3 3
Enter Second Matrix : 2 1 0
2 3 0
1 1 2
Matrix Subtraction is :
0 0 2
1 -1 1
1 2 1_
Multiplication of two matrices :• Program :
• /* Program to demonstrate multiplication of two matrices.
Creation Date : 25 Nov 2011 11:50:11 PM
Author : R.K.Singh */
#include <stdio.h>
• #include <conio.h>
• void main()
• {
• int a[3][3],b[3][3],c[3][3],i,j,k;
• clrscr();
• printf("nt Enter First Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• printf("nt Enter Second Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&b[i][j]);
• }
• }
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• c[i][j]=0;
• for(k=0;k<3;k++)
• {
• c[i][j]=c[i][j]+a[i][k]*b[k][j];
• }
• }
• }
• printf("nt Matrix Multiplication is : nn");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• printf("t %d",c[i][j]);
• }
• printf("n");
• }
• getch();
• }
Output :
Enter First Matrix : 1 2 1
3 2 1
1 2 1
Enter Second Matrix : 3 3 3
1 2 1
1 1 1
Matrix Multiplication is :
6 8 6
12 14 12
6 8 6_
Transpose of matrix :• Program :
•
• /* Program to demonstrate transpose of matrix.
• Creation Date : 26 Nov 2011 12:03:59 PM
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
•
• void main()
• {
• int a[3][3],i,j;
• clrscr();
• printf("nt Enter Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• printf("nt Transpose of Matrix is : nn");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• printf("t%d",a[j][i]);
• }
• printf("n");
• }
• getch();
• }
Output :
Enter Matrix : 2 1 2
3 2 1
2 3 3
Transpose of Matrix is :
2 3 2
1 2 3
2 1 3_
Check matrix is lower triangular or not :
• Program :
•
• /* Program to check lower triangular matrix or not.
• Creation Date : 26 Nov 2011 01:14:54 PM
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
•
• void main()
• {
• int a[3][3],i,j,flg=0;
• clrscr();
• printf("nt Enter 3*3 Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• if(a[i]<a[j] && a[i][j]==0)
• {
• flg=flg+1;
• }
• }
• }
• if(flg==3)
• printf("nn Lower triangular matrix !");
• else
• printf("nn Not lower triangular matrix !");
• getch();
• }
Output :
Enter 3*3 Matrix :
1 0 0
1 1 0
2 2 3
Lower triangular matrix !_
Check matrix is upper triangular or not :
• Program :
•
• /* Program to check upper triangular matrix or not.
• Creation Date : 26 Nov 2011 01:14:54 PM
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
•
• void main()
• {
• int a[3][3],i,j,flg=0;
• clrscr();
• printf("nt Enter 3*3 Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• if(a[i]>a[j] && a[i][j]==0)
• {
• flg=flg+1;
• }
• }
• }
• if(flg==3)
• printf("nn Upper triangular matrix !");
• else
• printf("nn Not Upper triangular matrix !");
• getch();
• }
Output :
Enter 3*3 Matrix :
1 2 3
0 1 1
0 0 3
Upper triangular matrix !_
Check matrix is unit/identity matrix or not :
• Program :
•
• /* Program to check unit/identity matrix or not.
• Creation Date : 26 Nov 2011 08:28:08 PM
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
•
• void main()
• {
• int a[3][3],i,j,flg=0,flg2=0,flg3=0;
• clrscr();
• printf("nt Enter 3*3 Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• if(a[i]<a[j] && a[i][j]==0)
• {
• flg=flg+1;
• }
• if(a[i]>a[j] && a[i][j]==0)
• {
• flg2=flg2+1;
• }
• if(a[i][j]==1)
• {
• flg3=flg3+1;
• }
• }
• }
• if(flg==3 && flg2==3 && flg3==3)
• printf("nn Unit/Identity matrix !");
• else
• printf("nn Not Unit/Identity matrix !");
• getch();
• }
Output :
Enter 3*3 Matrix :
1 0 0
0 1 0
0 0 1
Unit/Identity matrix !_
Check matrix is zero/null matrix or not :
• Program :
•
• /* Program to check zero/null matrix or not.
• Creation Date : 26 Nov 2011 02:09:04 PM
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
•
• void main()
• {
• int a[3][3],i,j,flg=0;
• clrscr();
• printf("nt Enter 3*3 Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• if(a[i][j]==0)
• {
• flg=flg+1;
• }
• }
• }
• if(flg==9)
• printf("nn Zero/Null matrix !");
• else
• printf("nn Not Zero/Null matrix !");
• getch();
• }
Output :
Enter 3*3 Matrix :
0 0 0
0 0 0
0 0 0
Zero/Null matrix !_
Check matrix is diagonal or not :
• Program :
•
• /* Program to check diagonal matrix or not.
• Creation Date : 26 Nov 2011 01:14:54 PM
• Author : R.K.Singh */
• #include <stdio.h>
• #include <conio.h>
•
• void main()
• {
• int a[3][3],i,j,flg=0,flg2=0;
• clrscr();
• printf("nt Enter 3*3 Matrix : ");
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• scanf("%d",&a[i][j]);
• }
• }
• for(i=0;i<3;i++)
• {
• for(j=0;j<3;j++)
• {
• if(a[i]<a[j] && a[i][j]==0)
• {
• flg=flg+1;
• }
• if(a[i]>a[j] && a[i][j]==0)
• {
• flg2=flg2+1;
• }
• }
• }
• if(flg==3 && flg2==3)
• printf("nn Diagonal matrix !");
• else
• printf("nn Not Diagonal matrix !");
• getch();
• }
•
Output :
Enter 3*3 Matrix :
2 0 0
0 5 0
0 0 1
Diagonal matrix !_

Simple c program

  • 1.
    Simple C Program: Program : /* Simple C Program . Creation Date : 12:34 PM 07/11/2010 Author : R.K.Singh*/ #include <stdio.h> #include <conio.h> void main() { clrscr(); printf("n My first program in C !"); getch(); }
  • 2.
    Output : My firstprogram in C !_
  • 3.
    Program to printvalue of existing number : Program : /* Program to print value of existing number . Creation Date : 12:38 PM 07/11/2010 Author :R.K.Singh */ #include <stdio.h> #include <conio.h> void main() { int no = 19; clrscr(); printf("n Number is : %d",no); getch(); }
  • 4.
  • 5.
    Program to demonstratescanf() and printf() : 3.C : Program : /* Program to demonstrate scanf() and printf(). Creation Date : 12:41 PM 07/11/2011 Author : R.K.Singh */ #include <stdio.h> #include <conio.h> void main() { int no; clrscr(); printf("n Enter any number :"); scanf("%d",&no); printf("n Number is : %d",no); getch(); }
  • 6.
    Output : Enter anynumber :12 Number is : 12_
  • 7.
  • 8.
    Program to calculateaddition of two numbers : Program : /* Program to calculate addition of two numbers. Creation Date : 09:51 PM 21/11/2011 Author : R.K.Singh */ #include <stdio.h> #include <conio.h> void main() { int a,b,c; clrscr(); printf("n Enter any 2 numbers : "); scanf("%d %d",&a,&b); c = a + b; printf("n Addition is : %d",c); getch(); }
  • 9.
    Output : Enter any2 numbers : 12 14 Addition is : 26_
  • 10.
    Program to calculatesubtraction of two numbers : /* Program to calculate subtraction of two numbers. Creation Date : 10:43 PM 21/11/2011 Author : R.K.Singh */ #include <stdio.h> #include <conio.h> void main() { int a,b,c; clrscr(); printf("n Enter any 2 numbers : "); scanf("%d %d",&a,&b); c = a - b; printf("n Subtraction is : %d",c); getch(); }
  • 11.
    Output : Enter any2 numbers : 8 6 Subtraction is : 2_
  • 12.
    Program to calculatedivision of two numbers : Program : /* Program to calculate division of two numbers. Creation Date : 10:58 PM 21/11/2011 Author : R.K.Singh */ #include <stdio.h> #include <conio.h> void main() { int a,b,c; clrscr(); printf("n Enter any 2 numbers : "); scanf("%d %d",&a,&b); c = a / b; printf("n Division is : %d",c); getch(); }
  • 13.
    Output : Enter any2 numbers : 12 5 Division is : 2_
  • 14.
    Program to calculatemultiplication of two numbers : • Program : • /* Program to calculate multiplication of two numbers. • Creation Date : 10:51 PM 21/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int a,b,c; • clrscr(); • printf("n Enter any 2 numbers : "); • scanf("%d %d",&a,&b); • c = a * b; • printf("n Multiplication is : %d",c); • getch(); • }
  • 15.
    Output : Enter any2 numbers : 8 12 Multiplication is : 96_
  • 16.
    Program to calculatemodulus of two numbers : • Program : • /* Program to calculate modulus of two numbers. • Creation Date : 11:01 PM 21/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int a,b,c; • clrscr(); • printf("n Enter any 2 numbers : "); • scanf("%d %d",&a,&b); • c = a % b; • printf("n Modulus is : %d",c); • getch(); • }
  • 17.
    Output : Enter any2 numbers : 11 5 Modulus is : 1_
  • 18.
  • 19.
    Program to printpyramid in C : Pattern 1 : • Program : • /* Program to print pyramid pattern in C : Pattern 1 • Creation Date : 12:36 AM 22/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j; • clrscr(); • for(i=0; i<5; i++) • { • for(j=0; j<5; j++) • { • printf(" * "); • } • printf("n"); • } • getch(); • }
  • 20.
    Output : * ** * * * * * * * * * * * * * * * * * * * * * *_
  • 21.
    Program to printpyramid in C : Pattern 2 : • Program : • /* Program to print pyramid pattern in C : Pattern 2 • Creation Date : 12:43 AM 22/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j; • clrscr(); • for(i=0; i<5; i++) • { • for(j=0; j<=i; j++) • { • printf(" * "); • } • printf("n"); • } • getch(); • }
  • 22.
    Output : * * * ** * * * * * * * * * *_
  • 23.
    Program to printpyramid in C : Pattern 3 :• /* Program to print pyramid pattern in C : Pattern 3 • Creation Date : 12:28 AM 22/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j,k; • clrscr(); • for(i=1; i<=5; i++) • { • for(j=5; j>=i; j--) • { • printf(" "); • } • for(k=1; k<=i; k++) • { • printf("*"); • } • printf("n"); • } • getch(); • }
  • 24.
    Output : * * * ** * * * * * * * * * *_
  • 25.
    Program to printpyramid in C : Pattern 4 :• /* Program to print pyramid pattern in C : Pattern 4 • Creation Date : 12:54 AM 22/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j,k,samp=1; • clrscr(); • for(i=5; i>=1; i--) • { • for(k=samp; k>=0; k--) • { • printf(" "); // only 1 space • } • for(j=i; j>=1; j--) • { • printf("*"); • } • samp = samp + 1; • printf("n"); • } • getch(); • }
  • 26.
    Output : * ** * * * * * * * * * * * *_
  • 27.
    Program to printpyramid in C : Pattern 5 : • Program : • /* Program to print pyramid pattern in C : Pattern 5 • Creation Date : 01:08 AM 22/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j; • clrscr(); • for(i=5; i>=1; i--) • { • for(j=1; j<=i; j++) • { • printf(" * "); • } • printf("n"); • } • getch(); • }
  • 28.
    Output : * ** * * * * * * * * * * * *_
  • 29.
    Program to printpyramid in C : Pattern 6 : • Program : • /* Program to print pyramid pattern in C : Pattern 6 • Creation Date : 01:52 AM 22/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j,k,t=0; • clrscr(); • for(i=1; i<=5; i++) • { • for(k=t; k<5; k++) • { • printf(" "); • } • for(j=0; j< i; j++) • { • printf(" * "); • t = t + 1; • } • printf("n"); • } • getch(); • }
  • 30.
    Output : * * * ** * * * * * * * * * *_
  • 31.
    Program to printpyramid in C : Pattern 7 :• Program : • /* Program to print pyramid pattern in C : Pattern 7 • Creation Date : 01:13 AM 22/11/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j,k,samp=1; • clrscr(); • for(i=1; i<=5; i++) • { • for(k=samp; k<=5; k++) • { • printf(" "); • } • for(j=0; j< i; j++) • { • printf("*"); • } • samp = samp + 1; • printf("n"); • } • samp = 1; • for(i=4; i>=1; i--) • { • for(k=samp; k>=0; k--) • { • printf(" "); • } • for(j=i; j>=1; j--) • { • printf("*"); • } • samp = samp + 1; • printf("n"); • } • getch(); • } •
  • 32.
    Output : * * * ** * * * * * * * * * * * * * * * * * * * *_
  • 33.
    Program to printpyramid in C : Pattern 8 : • Program : • /* Program to print pyramid pattern in C : Pattern 8 • Creation Date : 02:39 PM 01/10/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int rw, c, no=1 ,len; • clrscr(); • printf("Enter number of rows: "); • scanf("%d," &len); • for(rw=1; rw<=len; rw++) • { • printf("n"); • for(c=1; c<=rw; c++) • { • printf(" %2d ", no); • no++; • } • } • getch(); • }
  • 34.
    Output : Enter numberof rows: 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15_
  • 35.
    Program to printpyramid in C : Pattern 9 :• Program : • /* Program to print pyramid pattern in C : Pattern 9 • Creation Date : 03:19 PM 01/10/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int no,i,y,x=35; • clrscr(); • printf("Enter number of rows: "); • scanf("%d," &no); • for(y=0;y<=no;y++) • { • goto(x,y+1); • for(i=0-y; i<=y; i++) • { • printf(" %3d ", abs(i)); • x=x-3; • } • } • getch(); • }
  • 36.
    Output : Enter numberof rows: 5 0 1 0 1 2 1 0 1 2 3 2 1 0 1 2 3 4 3 2 1 0 1 2 3 4 5 4 3 2 1 0 1 2 3 4 5_
  • 37.
    Program to printpyramid in C : Pattern 10 : • Program : • /* Program to print pyramid pattern in C : Pattern 10 • Creation Date : 03:14 PM 01/10/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i, j=5, k, x; • clrscr(); • for(i=1;i<=5;i++) • { • for(k=1;k<=j;k++) • { • printf(" "); • } • for(x=1;x<=i;x++) • { • printf("%d",i); • printf(" "); • } • printf("n"); • j=j-1; • } • getch(); • }
  • 38.
    Output : 1 2 2 33 3 4 4 4 4 5 5 5 5 5_
  • 39.
    Program to printpyramid in C : Pattern 11 :• Program : • /* Program to print pyramid pattern in C : Pattern 11 • Creation Date : 03:24 PM 01/10/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int rw,c,no,spc; • clrscr(); • printf("Enter number of rows : "); • scanf("%d", &no); • for(rw=1; rw<=no; rw++) • { • for(spc=no; spc>=rw; spc--) • { • printf(" "); • } • for(c=1; c<=rw; c++) • { • printf("%2d",c); • } • printf("n"); • } • getch(); • }
  • 40.
    Output : 1 1 2 12 3 1 2 3 4 1 2 3 4 5_
  • 41.
    Program to printpyramid in C : Pattern 12 : • Program : • /* Program to print pyramid pattern in C : Pattern 12 • Creation Date : 03:24 PM 01/10/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j,k; • clrscr(); • for(i=1; i<=5; i++) • { • for(j=1; j<=5-i; j++) • { • printf(" "); • } • for(k=1; k<=2*i-1; k++) • { • printf(" %d ",k); • } • printf("n"); • } • getch(); • }
  • 42.
    Output : 1 1 23 1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 9_
  • 43.
    Program to printpyramid in C : Pattern 13 : • Program : • /* Program to print pyramid pattern in C : Pattern 13 • Creation Date : 04:24 PM 01/10/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • int i,j,asci,spc; • clrscr(); • for(i=7; i>=1; i--) • { • for(spc=6; spc>=i; spc--) • { • printf(" "); • } • asci=65; • for(j=1; j<=i; j++) • { • printf("%2c",asci++); • } • for(j=i-1; j>=0; j--) • { • printf("%2c",--asci); • } • printf("n"); • } • getch(); • }
  • 44.
    Output : A BC D E F G G F E D C B A A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A_
  • 45.
    Program to allCombinations of characters A,B,C in C : Pattern 14 : • Program : • /* Program to print all Combinations of characters A, B, C : Pattern 14 • Creation Date : 11:33 PM 01/10/2011 • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • void main() • { • char ch1, ch2, ch3; • clrscr(); • for(ch1='A' ; ch1<='C' ; ++ch1) • { • for(ch2='A' ; ch2<='C' ; ++ch2) • { • for(ch3='A' ; ch3<='C' ; ++ch3) • { • printf(" %c%c%c", ch1, ch2, ch3); • } • } • } • getch(); • }
  • 46.
    Output : AAA AABAAC ABA ABB ABC ACA ACB ACC BAA BAB BAC BBA BBB BBC BCA BCB BCC CAA CAB CAC CBA CBB CBC CCA CCB CCC_
  • 47.
    Addition of twomatrices :
  • 48.
    Program : /* Programto demonstrate addition of two matrices. Creation Date : 25 Nov 2011 11:35:00 PM Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • • void main() • { • int a[3][3],b[3][3],c[3][3],i,j; • clrscr(); • printf("nt Enter First Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • printf("nt Enter Second Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&b[i][j]); • } • } • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • c[i][j]=a[i][j]+b[i][j]; • } • } • printf("nt Matrix Addition is : nn"); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • printf("t %d",c[i][j]); • } • printf("n"); • } • getch(); • }
  • 49.
    Output : Enter FirstMatrix : 2 1 2 3 2 1 2 3 3 Enter Second Matrix : 2 1 0 2 3 0 1 1 2 Matrix Addition is : 4 2 2 5 5 1 3 4 5_
  • 50.
    Subtraction of twomatrices : • Program : • • /* Program to demonstrate subtraction of two matrices. • Creation Date : 25 Nov 2011 11:42:08 PM • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • • void main() • { • int a[3][3],b[3][3],c[3][3],i,j; • clrscr(); • printf("nt Enter First Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • printf("nt Enter Second Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&b[i][j]); • } • } • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • c[i][j]=a[i][j]-b[i][j]; • } • } • printf("nt Matrix Subtraction is : nn"); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • printf("t %d",c[i][j]); • } • printf("n"); • } • getch(); • }
  • 51.
    Output : Enter FirstMatrix : 2 1 2 3 2 1 2 3 3 Enter Second Matrix : 2 1 0 2 3 0 1 1 2 Matrix Subtraction is : 0 0 2 1 -1 1 1 2 1_
  • 52.
    Multiplication of twomatrices :• Program : • /* Program to demonstrate multiplication of two matrices. Creation Date : 25 Nov 2011 11:50:11 PM Author : R.K.Singh */ #include <stdio.h> • #include <conio.h> • void main() • { • int a[3][3],b[3][3],c[3][3],i,j,k; • clrscr(); • printf("nt Enter First Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • printf("nt Enter Second Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&b[i][j]); • } • } • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • c[i][j]=0; • for(k=0;k<3;k++) • { • c[i][j]=c[i][j]+a[i][k]*b[k][j]; • } • } • } • printf("nt Matrix Multiplication is : nn"); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • printf("t %d",c[i][j]); • } • printf("n"); • } • getch(); • }
  • 53.
    Output : Enter FirstMatrix : 1 2 1 3 2 1 1 2 1 Enter Second Matrix : 3 3 3 1 2 1 1 1 1 Matrix Multiplication is : 6 8 6 12 14 12 6 8 6_
  • 54.
    Transpose of matrix:• Program : • • /* Program to demonstrate transpose of matrix. • Creation Date : 26 Nov 2011 12:03:59 PM • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • • void main() • { • int a[3][3],i,j; • clrscr(); • printf("nt Enter Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • printf("nt Transpose of Matrix is : nn"); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • printf("t%d",a[j][i]); • } • printf("n"); • } • getch(); • }
  • 55.
    Output : Enter Matrix: 2 1 2 3 2 1 2 3 3 Transpose of Matrix is : 2 3 2 1 2 3 2 1 3_
  • 56.
    Check matrix islower triangular or not : • Program : • • /* Program to check lower triangular matrix or not. • Creation Date : 26 Nov 2011 01:14:54 PM • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • • void main() • { • int a[3][3],i,j,flg=0; • clrscr(); • printf("nt Enter 3*3 Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • if(a[i]<a[j] && a[i][j]==0) • { • flg=flg+1; • } • } • } • if(flg==3) • printf("nn Lower triangular matrix !"); • else • printf("nn Not lower triangular matrix !"); • getch(); • }
  • 57.
    Output : Enter 3*3Matrix : 1 0 0 1 1 0 2 2 3 Lower triangular matrix !_
  • 58.
    Check matrix isupper triangular or not : • Program : • • /* Program to check upper triangular matrix or not. • Creation Date : 26 Nov 2011 01:14:54 PM • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • • void main() • { • int a[3][3],i,j,flg=0; • clrscr(); • printf("nt Enter 3*3 Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • if(a[i]>a[j] && a[i][j]==0) • { • flg=flg+1; • } • } • } • if(flg==3) • printf("nn Upper triangular matrix !"); • else • printf("nn Not Upper triangular matrix !"); • getch(); • }
  • 59.
    Output : Enter 3*3Matrix : 1 2 3 0 1 1 0 0 3 Upper triangular matrix !_
  • 60.
    Check matrix isunit/identity matrix or not : • Program : • • /* Program to check unit/identity matrix or not. • Creation Date : 26 Nov 2011 08:28:08 PM • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • • void main() • { • int a[3][3],i,j,flg=0,flg2=0,flg3=0; • clrscr(); • printf("nt Enter 3*3 Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • if(a[i]<a[j] && a[i][j]==0) • { • flg=flg+1; • } • if(a[i]>a[j] && a[i][j]==0) • { • flg2=flg2+1; • } • if(a[i][j]==1) • { • flg3=flg3+1; • } • } • } • if(flg==3 && flg2==3 && flg3==3) • printf("nn Unit/Identity matrix !"); • else • printf("nn Not Unit/Identity matrix !"); • getch(); • }
  • 61.
    Output : Enter 3*3Matrix : 1 0 0 0 1 0 0 0 1 Unit/Identity matrix !_
  • 62.
    Check matrix iszero/null matrix or not : • Program : • • /* Program to check zero/null matrix or not. • Creation Date : 26 Nov 2011 02:09:04 PM • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • • void main() • { • int a[3][3],i,j,flg=0; • clrscr(); • printf("nt Enter 3*3 Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • if(a[i][j]==0) • { • flg=flg+1; • } • } • } • if(flg==9) • printf("nn Zero/Null matrix !"); • else • printf("nn Not Zero/Null matrix !"); • getch(); • }
  • 63.
    Output : Enter 3*3Matrix : 0 0 0 0 0 0 0 0 0 Zero/Null matrix !_
  • 64.
    Check matrix isdiagonal or not : • Program : • • /* Program to check diagonal matrix or not. • Creation Date : 26 Nov 2011 01:14:54 PM • Author : R.K.Singh */ • #include <stdio.h> • #include <conio.h> • • void main() • { • int a[3][3],i,j,flg=0,flg2=0; • clrscr(); • printf("nt Enter 3*3 Matrix : "); • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • scanf("%d",&a[i][j]); • } • } • for(i=0;i<3;i++) • { • for(j=0;j<3;j++) • { • if(a[i]<a[j] && a[i][j]==0) • { • flg=flg+1; • } • if(a[i]>a[j] && a[i][j]==0) • { • flg2=flg2+1; • } • } • } • if(flg==3 && flg2==3) • printf("nn Diagonal matrix !"); • else • printf("nn Not Diagonal matrix !"); • getch(); • } •
  • 65.
    Output : Enter 3*3Matrix : 2 0 0 0 5 0 0 0 1 Diagonal matrix !_