Monday, August 22, 2011

Program to calculate the unknowns of simultaneous linear equations



#include<stdio.h>
#include<math.h>
int main()
{
int i,j,k,n;
float c,a[100][101],x[100];
printf("Enter the no. of variables:");

Read more!

Thursday, March 10, 2011

C++ program to add two Complex no. using this pointer



#include<iostream>
using namespace std;
class Complex
{
private:
float real,imag;
public:
Complex():real(0),imag(0){}

Read more!

Thursday, March 3, 2011

C++ program that illustrates the order of constructor and destructor invocation in nice way



#include<iostream>
using namespace std;
class Dept{
    private:
        int id;
        char name[30];
    public:
        Dept(){}

Read more!

Monday, January 24, 2011

program to store the information about students in file and retrieve information arranging in alphabetical order


#include<stdio.h>
#include<string.h>
int main()
{
    struct student
    {
        char name[20],address[20],phone[15];
        int roll;
    }s[20];
    int i,j,n;
    FILE *fp;

Read more!

Wednesday, January 19, 2011

Program to arrange the given names in ascending order

#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,n;
    char name[15][20],temp[20];
    printf("Enter number of students:");
    scanf("%d",&n);

Read more!

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!