Monday, December 13, 2010

program to find palindrome of a string

/*program to find palindrome of a string*/
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,len,flag=1;
    char string[100];
    printf("Enter a string:");

Read more!

Program to calculate the length of string without using string handling function

/*Program to calculate the length of string*/
/*without using string handling functions*/
#include<stdio.h>
int main()
{
    char string[100];
    int i,count=0;
    printf("Enter the string:");

Read more!

Program to display the prime numbers in the given range and show its count

#include<stdio.h>

int main()
{
    int i,j,a,b,m=0;
    printf("Enter the range:");
    scanf("%d%d",&a,&b);
    printf("The prime numbers in this range are:\n");

Read more!

Program to check whether the entered number is prime or not

#include<stdio.h>

int main( )
{
    int num, i ;
    printf ( "Enter a number:" ) ;
    scanf ( "%d", &num ) ;

Read more!

Program to find the factorial of a number using recursive function

#include<stdio.h>

int factorial(int);
int main()
{
    int n;
    printf("Enter the number:");
    scanf("%d",&n);
    printf("The factorial is %d",factorial(n));

Read more!

Program to find the transpose of the matrix of nth order

#include<stdio.h>
int main()
{
    int i,j,a[10][10],m,n;
    printf("Enter the no.of rows and columns:");
    scanf("%d%d",&m,&n);
    printf("\nEnter the elements of Matrix:\n");
    for(i=0;i< m;i++)
    for(j=0;j< n;j++)
    {
        printf("Enter element a[%d][%d]:",i+1,j+1);
        scanf("%d",&a[i][j]);
    }
    printf("\nThe original matrix is:\n");
    for(i=0;i< m;i++)
    {
    for(j=0;j< n;j++)
    {
     printf("%d\t",a[i][j]);
    }
    printf("\n");
    }
    printf("\nThe transposed matrix is:\n");
    for(i=0;i< n;i++)
    {
        for(j=0;j< m;j++)
        {
            printf("%d\t",a[j][i]);
        }
        printf("\n");
    }
    return 0;
}

Read more!

Program to concatenate two strings

#include<stdio.h>
#include<string.h>
int main()
{
    char a[20],b[20];
    printf("Enter the  first string:");
    gets(a);
    printf("Enter the second string:");
    gets(b);
    strcat(a,b);
    printf("The concatenated string is %s.",a);
    return 0;
}

Read more!

Program to calculate the total number of words in the given text

#include<stdio.h>
#include<string.h>
int main()
{
    char a[20];
    int i,n,count=0;
    printf("Enter the text:");
    gets(a);
    n=strlen(a);

    for(i=0;i<=n;i++)
    {
        if(a[i]==' '||a[i]=='\0')
        count++;
    }
    printf("\nTotal number of words in the string is %d.",count);
    return 0;
}

Read more!

Program to find the greatest number using pointers

#include<stdio.h>

void main()
{
    int a[20],i,*p,x,*y,n;
    printf("How many numbers?");
    scanf("%d",&n);
    p=a;
    y=&x;
    printf("Enter %d numbers:",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",(p+i));
    }
    *y=*p;
    for(i=0;i<n;i++)
    {
        if(*y<*(p+i))
        *y=*(p+i);
    }
    printf("\n The greatest number is %d.",x);
}

Read more!

Program to sort the numbers entered by user in ascending and descending order using function

#include<stdio.h>
void ascending (int[],int);
void descending (int[],int);
int main()
{
    int a[20],i,n;
    printf("How many numbers?");
    scanf("%d",&n);
    printf("Enter %d numbers:",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    ascending(a,n);
    descending(a,n);
    return 0;
}
void ascending(int a[],int n)
{
    int i,j,temp;
    printf("\nNumbers sorted in ascending order:\n");
    for(i=0;i<n;i++)
     {
         for(j=i+1;j<n;j++)
         {
             if(a[i]>a[j])
             {
                 temp=a[i];
                 a[i]=a[j];
                 a[j]=temp;
             }
         }
     }
     for(i=0;i<n;i++)
     {
         printf("%d\t",a[i]);
     }

}
void descending(int a[],int n)
{
    int i, j,temp;
    printf("\nNumbers sorted in descending order:\n");
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]<a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
  for(i=0;i<n;i++)
  {
      printf("%d\t",a[i]);
  }
}

Read more!

Program to display the largest and smallest numbers among those entered by the user using functions

#include<stdio.h>

int largest(int[],int);
int smallest(int [],int);
int main()
{
    int a[20],i,l,m,n;
    printf("How many numbers?");
    scanf("%d",&n);
    printf("Enter %d numbers:",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("The largest number is %d\n",largest(a,n));
    printf("The smallest number is %d",smallest(a,n));
    return 0;
}
int largest(int a[],int n)
{
    int i,x;
    x=a[0];
    for(i=0;i<n;i++)
    {
        if(x<a[i])
        x=a[i];
    }
        return(x);
}
int smallest(int a[],int n)
{
    int i,x;
    x=a[0];
    for(i=0;i<n;i++)
    {
        if(x>a[i])
        x=a[i];
    }
    return(x);
}

Read more!

Program to generate fibonacci series upto n terms

#include<stdio.h>
int fib(int);
int main()
{
    int n,i;
    printf("How many terms?");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        printf("%d\t",fib(i));
    }
    return 0;
}
int fib(int x)
{
    if(x<=2)
        return 1;
    else
        return (fib(x-1)+fib(x-2));
}

Read more!

Hurt

What is hurt? Don't go verbally but actually go into yourself, look at yourself. Psychologically you are hurt, your parents hurt you when you were a child, your friends hurt you when you were a child. Then the school hurt you by saying, "You should be as clever as your brother", or your uncle, or your headmaster, or whoever it was. And then at college you must pass exams, and if you fail, you are hurt. And if you don't get a job, you are hurt. Everything in the world is put together so that it hurts you. Our education, which is so rotten, hurts you. So you are hurt. Do you actually realize that you are hurt? And see the results of being hurt - that you want to hurt others? From that arises anger, resistance, you withdraw, become more and more inwardly separate. And the more you are inwardly separate, and withdraw, the more you are hurt. So you build a wall around yourself and pretend, but always within the wall. These are all the symptoms.
            So you are hurt. And if you really, deeply realize that you are hurt, not only at the conscious level but deep down, then what will you do? Now, how does this hurt take place? Because you have an image about yourself. If I have an image about myself always sitting on a platform talking to an audience - thank God, I don't - and if the audience disapproves or doesn't come, my image about myself is hurt. The fact is that as long as I have image about myself, that image is going to be hurt. That's clear, isn't it? Now is it possible to live without a single image? Which means no conclusions, no prejudices - all these are images. And the moment that you insult me, which is when you say something contary to the image I have about myself, then you hurt me. Now if at that moment when you are saying something that is harmful, hurtful, I am aware and I give total attention to what you are saying, then no registration takes place. It is only when there is inattention that the registration of hurt or flattery takes place. So when somebody says you are a fool, can you at that moment give your total attention? If you do, there is no hurt. The past hurts have gone in that attention. Attention is like a flame that burns out the past and the present hurt. Have you got this?
                                                                                                            - J. Krishnamurti
Read more!