You Are The Visitor Number

Sunday, May 18, 2008

/* Program to test whether given string is a palindrome */

This is an another Program to show check Palindrome , But this check Palindrome of a string instead of a number..

A string is any array of Characters. For example word "Arora " is a palindrome…..

/*"Author: Mitochondria Technologies Inc. "*/

/* Program to test whether given string is a palindrome */


 

#include<stdio.h>

#include<conio.h>

#include<string.h>

enum boolean{false,true};

enum boolean string_palindrome(char string[]);

void main()

{

char string [40];

clrscr();

printf("enter a string:");

scanf("%s",&string);

if (string_palindrome(string))

printf("string is a palindrome\n");

else

printf("string is not a palindrome\n");

getch();

}

enum boolean string_palindrome(char string[])

{

int left,right,len=strlen(string);

enum boolean matched=true;

if(len==0)

return true;

left=0;

right=len-1;

while(left<right && matched)

{

if (string[left]!=string[right])

matched=false;

else

{

left++;

right--;

}

}

return matched;

}

 

Saturday, May 17, 2008

/* Program to add two matrices */

Here is the program The student find most tough!!! Why?? Because it so lenghty. Again tough?? because it uses so many for loops many times first for filling of first matrices showing filled matrices & also one loop shows output matrix…

If you understand this program you can do anything in matrix algebra But you should also know mathematics!!! J
J
J
J


 

This program also helps you to understand the concept of arrays.. Now you try substraction by your own skills… till then wait for multiplication of matrices one>>>>


 

/* Program to add two matrices */

/*"Author: Mitochondria Technologies Inc.(Regd.)"*/


 

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,m,n,a[5][5],b[5][5],c[5][5];

clrscr();

printf("enter the no. of rows n columns:");

scanf("%d %d",&n,&m);

printf("enter matrix A:");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

scanf("%d",&a[i][j]);

}

}

printf("\nMatrix A is inserted.");

printf("\n");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

printf("%d",a[i][j]);

}

printf("\n");

}

printf("\nEnter matrix B:");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

scanf("%d",&b[i][j]);

}

}

printf("\nMatrix B is inserted.");

printf("\n");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

printf("%d",b[i][j]);

}

printf("\n");

}

printf("The Addition of two matrices is:\n");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

c[i][j]=a[i][j]+b[i][j];

}

}

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

printf("%d\t",c[i][j]);

}

printf("\n");

}

getch();

}


 


 


 

/* Program to show Number is a Palindrome*/

Here is the Program of the series that tell a number is pallindrome or not , a number is pallindrome if it has same digits when we read it from first digit or last digit. For example 12121 is a pallindrome number & a number 1212 is not a pallindrome.

Try this program by some examples from your side…..

Remember Dear C is not for FEAR…..

/* Program to show No. is a Palindrome */

/*Author: Mitochondria Technologies Inc.*/

#include<stdio.h>

#include<conio.h>

void main()

{

int temp,rev=0,rema,num;

clrscr();

printf("Enter the no. which is to be Checked : ");

scanf("%d",&num);

temp=num;

rev=0;

while(num>0)

{

rema=num%10;

num=num/10;

rev=rev*10+rema;

}

if (temp==rev)

{

printf("The given no. is Palindrome");

}

else

{

printf("The Given No. is Not Palindrome");

}

getch();

}


 

Sunday, March 16, 2008

/* Program to evaluate the expression (ax+b)/(ax-b) */

This Program Evaluates the expression (ax+b)/(ax-b) . As this program uses the Associativity of operators , an important topic while using so many arithmetic operators in an equation. So note this ….. Also this program uses division , obviously you have to be careful about choosing integer or float . Especially while considering the output. You take these variables as integer & see what happens??!!


 

/* Program to Evaluate the expression (ax+b)/(ax-b) */

/* Author Mitochondria Technologies Inc. (Regd.)*/

#include<stdio.h>

#include<conio.h>

void main()

{

float a,b,x,sum;

clrscr();

printf("Enter the values of a,b & x : ");

scanf("%f%f%f",&a,&b,&x);

sum=((a*x+b)/(a*x-b));

printf("The Result of the Expression is : %f",sum);

getch();

}

Friday, March 14, 2008

/* Program to evaluate sum of series S=1+1/2+1/3...+1/N */

I think in this case no introduction is required. I have taken output as float because naturally it will be float. Taking output as int the program will work but don't give accurate answers.

/* Program to evaluate sum of series S=1+1/2+1/3...+1/N */

/* Author Mitochondria Technologies Inc. */

#include<stdio.h>

#include<conio.h>

void main()

{

int i,n;

float sum;

clrscr();

printf("\n Enter the value to N : ");

scanf("%d",&n);

sum=0;

for(i=1;i<=n;i++)

sum=sum+1.0/i;

printf("\n Sum of series : %f",sum);

getch();

}

Thursday, March 13, 2008

/* Program to find Largest of three numbers */

This Program will tell you which number the largest of all the three number you have entered. For example you have entered 16, 25, 41 obviously it will tell 41 as largest of all. Programs are created with utmost care. User may check the logic error if any please report me immediately as a comment on this web page. Remember C is not for fear it's for Enjoy Dear!!!!

/* Program to find Largest of three nos. */

/* Author Mitochondria Technologies Inc. */

#include<stdio.h>

#include<conio.h>

void main()

{

int x,y,z,large;

clrscr();

printf("Enter three numbers : ");

scanf("%d%d%d",&x,&y,&z);

large=x;

if (y>large)

large=y;

if (z>large)

large=z;

printf("The Biggest no. is :%d",large);

getch();

}


 

/* Program to Calculate Factorial of a No. */

Here is Program which calculates Factorial of a number. For Example 4! =24, 5! =120. See again I have used FOR loop in this program you can also try it with while also to widen your horizons. But soon you realize that FOR loop is the shortest, finest method of programming. Enjoy Programming!!!!!!

/* Program to Calculate Factorial of a Number */

/* Author Mitochondria Technologies Inc. */

#include<stdio.h>

#include<conio.h>

void main()

{

int num,i=1,facto=1;

clrscr();

printf("\n Enter The Number : ");

scanf("%d",&num);

facto=1;

for(i=1;i<=num;i++)

{

facto=i*facto;

}

printf("\n The Factorial of the number entered is : %d",facto);

getch();

}

Saturday, March 8, 2008

/* Program to Create a Fibonacci Series */

This is a simple Program in C language you can Generate
Fibonacci Series From
this Program I have made this program Using While Loop Scratch your mind & you can also try it with For & do while loop. Fibonacci series starts with 0 & 1 & precede with the addition of last two terms ie net term will be 0+1 i.e. 1 & next 1+1=2 Then next 2+1=3 so series becomes 0,1,1,2,3,5,8,13,21,34,65……so on

/* Program to Create a Fibonacci Series */

/* Author Mitochondria Technologies Inc. */

#include<stdio.h>

#include<conio.h> /*Header Files */

void main() /*Main function to begin program & it is kept empty*/

{

int a,b,c,count=0,n; /*variable declaration & also initialization counter in one statement*/

clrscr(); /*clear screen to clear outputs after usage*/

printf("Enter The Value of No. : "); /*Input command for user for length of series*/

scanf("%d",&n); /*Taking input*/

a=0,b=1;

printf("%d\n",a);

printf("%d\n",b);

while(count<n-2) /*condition counter*/

{

c=a+b; /*series generating logic*/

printf("%d\n",c);

a=b;

b=c;

count++; /*increment counter*/

}

getch(); /*getch function to retain output on screen*/

}