Showing posts with label C Programs. Show all posts
Showing posts with label C Programs. Show all posts

Friday, 15 March 2013

Multiplication of Array Matrix with the help of program


Multiply two Array matrix with the help of Program:-

Q)Write a program to enter matrix(2) and print the multiplication of matrices.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.



void main()
{
int matrix1[10][20],matrix2[10][20],mul[20][30],i,j,row1,col1,row2,col2,s;
clrscr();
printf("Enter row and column");
scanf("%d%d",&row,&col);
printf("Enter first Matrix");
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
scanf("%d",&matrix1[i][j]);
}
}
printf("Enter second Matrix");
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
scanf("%d",&matrix2[i][j]);
}}
if(col1==row2)
{
for(i=0;i<row1;i++)
{
for(j=0;j<col2;j++)
{
s=0;
for(k=0;k<col1;k++)
{
s=s+matrix1[i][j]+matrix2[i][j];
mul[i][j]=s;
}}
printf("Matrix is");
for(i=0;i<row1;i++)
{
for(j=0;j<col2;j++)
{
printf("%d",mul[i][j]);
}
printf("\n");
}}
else
printf(No Result");
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Saturday, 9 March 2013

Sum of Array Matrix with the help of Program


Sum of Array Matrix:-

Q)Write a program to enter matrix(2) and print the sum of matrices.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


void main()
{
int matrix1[10][20],matrix2[10][20],sum[20][30],i,j,row,col;
clrscr();
printf("Enter row and column");
scanf("%d%d",&row,&col);
printf("Enter first Matrix");
for(i=0;i<row;i++)
{

for(j=0;j<col;j++)
{
scanf("%d",&matrix1[i][j]);
}
}
printf("Enter second Matrix");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&matrix2[i][j]);
}}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
sum[i][j]=matrix1[i][j]+matrix2[i][j];
}}
printf("Sum is");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d",&sum[i][j]);
}
printf("\n");
}
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Transpose of Array Matrix with the help of Program


Transpose of Array Matrix in C language:-

Q)Write a program to enter matrix and print the transpose of matrix.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.

void main()
{
int matrix[10][20],i,j,row,col;
clrscr();
printf("Enter row and column");
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&matrix[i][j]);
}
}
printf("Transpose of Matrix is");
for(j=0;j<col;j++)
{
for(i=0;i<row;i++)
{
printf("%d",&matrix[i][j]);
}
printf("/n");
}
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Friday, 8 March 2013

2-D Array(2-Dimensional Array)


2-D Array or 2-Dimensional Array are the arrays which are the collection of rows and columns.

Syntax of 2-D array:-


name-of-matrix[Row size][Column size];


Example:-


int add-matrix[20][30]; 


Programming example of 2-d matrix in C language:-


Q)Write a program to create matrix and print the matrix.



Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.

void main()
{

int matrix[10][20],i,j,row,col;
clrscr();
printf("Enter row and column");
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&matrix[i][j]);
}
}
printf("Matrix is");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d",&matrix[i][j]);
}
getch();
}}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Wednesday, 6 March 2013

Program to split array into another array


Split Program in C language:-

Q)Write a program to create array and split the array into two parts i.e. even and odd.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.



void main() 
{
int a[20],e[20],o[20],i,j,k,n;
clrscr();
printf("Enter array limit");
scanf("%d",&n);
printf("Enter array element");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
j=k=0;
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
e[j]=a[i];
j++;
}
else
{
o[k]=a[i];
k++;
}
}
printf("Even Array");
for(i=0;i<j;i++)
printf("%d",e[i]);
printf("Odd Array");
for(i=0;i<k;i++)
printf("%d",o[i]);
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Tuesday, 5 March 2013

Program to detect duplicacy and remove duplicate value


Program to detect duplicacy and remove duplicate value:-


Q)Write a program to create array and print the array without duplicacy.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
Void main()
{
int i,lim,a[50],p,q;
printf("enter limit");
scanf("%d",&l);
printf("Enter Array");
for(i=0;i<lim;i++)
scanf("%d",&a[i]);
for(i=0;i<lim-1;i++)
{
for(p=i+1;p<lim;p++)
{
if(a[i]==a[p])
{
for(q=p;q<lim-1;q++)
a[q]=a[q+1];
lim--;
p--;
}
}
}
printf("Array as follows");
for(i=0;i<lim;i++)
printf("%d",a[i]);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Program to print Reverse of Array


Reversing of Array in c programming:


Q)Write a program to create array and print the array in reverse format.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
Void main()
{
int i,lim,a[50];
printf("enter limit");
scanf("%d",&l);
printf("Enter Array");
for(i=0;i<lim;i++)
scanf("%d",&a[i]);
for(i=lim-1;i>=0;i--)
printf("%d",a[i]);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Friday, 1 March 2013

Program to find minimum element of Array


Q)Write a program to create array and find the minimum or smallest element of array with its location?

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) etc. with the same logic.


P:void main()
{
int arr[30],i,limit,min,l;
printf("Enter limit");
scanf("%d"&l);
l=0;
printf("Enter Array");
for(i=0;i<limit;i++)
scanf("%d",&arr[i]);
min=arr[0];
l=0;
for(i=0;i<limit;i++)
{
if(arr[i]<min)
{
min=a[i];
l=i;
}
}
printf("%d",l=%d,min,l);
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Program to find maximum element of Array


Q)Write a program to create array and find the maximum or largest element of array with its location?

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) etc. with the same logic.



P:void main()
{
int arr[30],i,limit,max,l;
printf("Enter limit");
scanf("%d"&l);
l=0;
printf("Enter Array");
for(i=0;i<limit;i++)
scanf("%d",&arr[i]);
max=arr[0];
l=0;
for(i=0;i<limit;i++)
{
if(arr[i]>max)
{
max=a[i];
l=i;
}
}
printf("%d",l=%d,max,l);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Wednesday, 27 February 2013

Factor Program


Factor Program in C language:-

Q)Write a program in c language to enter a value and print factor of this number/value.


Note:-You can also create this program in java,c#,c++(c plus plus) etc. with the same logic.



P:#include<stdio.h>
void main()
{
int i,x;
printf("enter no.");
scanf("%d",&x);
for(i=0;i<=x;i++)
{
if(n%i==0)
printf("%d",i);
}
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Armstrong Program


Program of Armstrong Number:

Armstrong no. like 153 = (1*1*1)+(5*5*5)+(3*3*3).

Q)Write a program in c language to enter a value and check the number is Armstrong or not.

Note:-You can also create this program in java,c#,c++(c plus plus) etc. with the same logic.


P:#include<stdio.h>
void main()
{
int s,n,d;
printf("enter no.");
scanf("%d",&n);
s=0,a=n;
while(n!=0)
{
d=n%10;
s=s*d*d*d;
n=n/10;
}
if(a==s)
printf("Number is Armstrong");
else
printf("Number is not Armstrong");
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Friday, 23 November 2012

Example:Program of Perfect Number and Reverse of a Number in C language


Program of Perfect Number:

Suppose we enter 6 then


Perfect no. like   "  6->1+2+3+6=12(factors)  then 

                                    2*6=12 when we double"     

Q)Write a program to enter a value and check the number is perfect or not.


Note:-You can also create this program in java,c# etc. with the same logic.


P:#include<stdio.h>
void main()
{
int i,n,s;
printf("enter no.");
scanf("%d",&n);
s=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
s=s+i;
}
if(s==2*n)
printf("perfect no.");
else
printf("No. is not perfect");
getch();
}

Program of Reverse Number:


Reverse of no. like 134=431(Reverse)


Q)Write a program to enter a value and print the reverse of digit.



P:#include<stdio.h>
void main()
{
int r,n,d;
printf("enter no.");
scanf("%d",&n);
r=1;
while(n!=0)
{
d=n%10;
r=r*10+d;
n=n/10;
}
printf("reverse value=%d",r);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter. 

Example:Program of Prime numbers and Factorial in C language


Program of Prime number:

Q)Write a program to enter a no. and check number is prime or not.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
void main()
{
int n;
printf("enter no.");
scanf("%d",&n);
n=a                                       //initialization 
for(i=2;i<=n;i++)
{
if(n%i==0)
{
break;
}}
if(n==i)
printf("No. is Prime");
else
printf("No is not prime");
getch();
}

Program of Factorial:


Q)Write a program to enter  a number  and print the factorials of that number.



Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.

P:#include<stdio.h>
void main()
{
int i,n,f;
printf("enter no.");
scanf("%d",&n);
f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
printf("%d",f);
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Example:Program of Fibonacci Series and Lucas Series in C language


Fibonacci Series:1 1 2 3 5 8 13 21...(means addition of next digit with previous digit).

Q)Write a program to enter limit and print the Fibonacci series.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
Void main()
{
int i,l,a,b,c;
printf("enter limit");
scanf("%d",&l);
a=0;
b=1;
printf("%d%d",a,b);
for(i=3;i<=l;i++)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
getch();
}

Lucas Series:1 3 4 7  11 18......(means addition of next digit with previous digit).


Q)Write a program to enter limit and print the Lucas series.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
Void main()
{
int i,l,a,b,c;
printf("enter limit");
scanf("%d",&l);
a=1;
b=3;
printf("%d%d",a,b);
for(i=3;i<=l;i++)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Example:C Palindrome Program


Firstly I explain you what we done in this program or what is palindrome program in c language.Let us take an example 

121=121(The reverse of no. 121 is 121 ,that's the palindrome program) other example like 131=131,141=141.


Q)Write a program to enter digit and check the number is palindrome or not.



Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
void main()
{
int r,n,d,a;

printf("enter digit/no.");
scanf("%d",&n);
r=0;a=n;
while(n!=0)  //while(n)
{
d=n%10;
r=r*10+d;
n=n/10;
}
if(r==a)
{
printf("Your's number is palindrome")
}
else
{
printf("Not palindrome")
}
getch();
}}



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.


Thursday, 22 November 2012

Example:Basic C programs


Now I discuss some sample cum simple programs of C language.

Q)Write a program to print "hello world"?

P: #include<stdio.h>    // optional in c
      void main()
     {
      printf("Hell World"); // print
     }
       
Q)Write a basic program to input 2 no.s and print its sum(using third variable).

P: #include<stdio.h>    
      void main()
     {
      int a,b,c;
      printf("enter value of a and b"); 
      scanf("%d%d",&a,&b);
      c=a+b;
      printf("sum=%d",c);
      }

                                                       Or

     #include<stdio.h>    
     void main()
     {
     int a,b,c;
     a=10;
     b=20;
     c=a+b;
     printf("sum=%d",c);
     }



If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.