This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Sunday, May 5, 2013

Simple addition Program Using Java

import java.lang.*;
import java.io.*;
class Add
{
    public static void main(String args[])
    {
        int x=10,y=7,z;
        z=x+y;
        System.out.println("The result is:"+z);
    }
}

Write a java Program to find the area of the Circle formula

import java.lang.*;
import java.io.*;
class Circlearea
{
    public static void main(String args[])
    {
        float pi=3.14159f,area;
        int r=5;
        area=pi*r*r;
        System.out.println("The area of the circle is:"+area);
    }
}

Write a java Program to find the Quadratic Equation roots

import java.lang.*;
import java.io.*;
class Quadratic
{
    public static void main(String args[])
    {
        double b=12.1,a=2.35,c=12.50,dis,root1,root2;
        dis=(b*b)-(4*a*c);
        root1=(-b+Math.sqrt(dis)/2*a);
        root2=(-b-Math.sqrt(dis)/2*a);
        if(root1<=0 && root2<=0)
        {
            System.out.println("Roots are imaginary");
        }
        else
        {
        System.out.println("The result is:"+root1);
        System.out.println("The result is:"+root2);
        }
    }
}
       

Write a java Program to find the Simple Interest rate


import java.lang.*;
import java.io.*;
class Simpleinterest
{
    public static void main(String args[])
    {
        int p=5000,t=12,r=3;
        int interest=((p*t*r)/100);
        System.out.println("The Simple interest is:"+interest);
    }
}

The Fibonacci sequence is defined by the following rule. The first 2 values in the sequence are 1,1. Every subsequent value is the sum of the 2 values preceding it. Write A Java Program (WAJP) that uses both recursive and non-recursive functions to print the nth value of the Fibonacci sequence.


/* Fibonacci series Program in Java */

/*1.Fibonacci program using Non-Recursive Functions*/

import java.lang.*;
import java.io.*;
class Fibonacci
{
    public static void main(String args[])throws IOException
    {
    int i,sum=0,f=1,res,n;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Hey boss This is Fibonacci series Generator program");
    System.out.println("Enter The range");
    n=Integer.parseInt(br.readLine());
    System.out.println("The fibonacci series is:");
    for(i=0;i<n;i++)
    {
        res=sum+f;
        System.out.println(sum);
        sum=f;
        f=res;
    }
    System.out.println("\nTask completed.");
    }
}

Output:

Hey boss This is Fibonacci series Generator program
Enter The range
20
The fibonacci series is:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181

Task completed.

Write a java program on Bubble Sort


/* Bubble Sort program in java */
import java.lang.*;
import java.io.*;
class BubbleSort
{
        public static void main(String args[])throws IOException
        {
               BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
               int n,i,j,temp;
               System.out.println("----Welcome to the Bubble Sort Prog----");
               System.out.println("Hi mani how many elements you have");
               n=Integer.parseInt(br.readLine());
               int a[]=new int[n];
               System.out.println("Enter " +n+ " Elements");
               for(i=0;i<n;i++)
                a[i]=Integer.parseInt(br.readLine());
               System.out.println("Before Sorting");
               for(i=0;i<n;i++)
                System.out.print("\t"+a[i]);

               for(i=0;i<n;i++)
               {
                for(j=i+1;j<n;j++)
                {
                        if(a[i]>a[j])
                        {
                                temp=a[j];
                                a[j]=a[i];
                                a[i]=temp;
                        }
                 }
                }
                System.out.println("\nAfter Sorting");
                for(i=0;i<n;i++)
                 System.out.print("\t" +a[i]);
       }
}
              
Output:

----Welcome to the Bubble Sort Prog----
Hi mani how many elements you have
5
Enter 5 Elements
20
30
20
15
20
Before Sorting
        20      30      20      15      20
After Sorting
        15      20      20      20      30

Write a java program to find the area of the Circle


/* Program to find the Area of the Circle using pi*r*r formula */
import java.lang.*;
import java.io.*;
class Circlearea
{
    public static void main(String args[])
    {
        float pi=3.14159f,area;
        int r=5;
        area=pi*r*r;
        System.out.println("The area of the circle is:"+area);
    }
}

Output:

E:\javamani>java Circlearea
The area of the circle is:78.53975

The Fibonacci sequence is defined by the following rule. The first 2 values in the sequenc are 1,1. Every subsequent value is the sum of the 2 values preceding it. Write A Java Program (WAJP) that uses both recursive and non-recursive functions to print the n th value of the Fibonacci sequence.



/*1.Fibonacci program using Recursive Functions*/
import java.lang.*;
import java.io.*;
class FibonacciRecursive
{
    public static void main(String args[])throws IOException
    {
    int n;
    BufferedReader d=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter The range");
    n=Integer.parseInt(d.readLine());
    System.out.println("The fibonacci series is:");
    Fibonaccino(n);//funcion Calling
    }//Main method End.
  
    static void Fibonaccino(int n)
    {
        int i,sum=0,f=1,res;  
        for(i=0;i<n;i++)
        {
        res=sum+f;
        System.out.println(sum);
        sum=f;
        f=res;
        }
        System.out.println("\nTask completed.");
    }
}

Output:

E:\javamani>java FibonacciRecursive
Enter The range
10
The fibonacci series is:
0
1
1
2
3
5
8
13
21
34
Task completed.

Write a Java program that allows the user to draw lines, rectangles and ovals.


/*Write a Java program that allows the user to draw lines, 

rectangles and ovals.*/
import java.applet.*;
import java.awt.*;
import javax.swing.*;
public class LinesRectsOvals extends JApplet
{
    public void paint(Graphics g)
    {
        super.paint(g);
        g.setColor(Color.red);        

g.drawLine(5,30,350,30);
        g.setColor(Color.blue);
        g.drawRect(5,40,90,55);
        g.fillRect(100,40,90,55);
        g.setColor(Color.cyan);
        g.fillRoundRect(195,40,90,55,50,50);
        g.drawRoundRect(290,40,90,55,20,20);
        g.setColor(Color.yellow);
        g.draw3DRect(5,100,90,55,true);
        g.fill3DRect(100,100,90,55,false);
        g.setColor(Color.magenta);
        g.drawOval(195,100,90,55);
        g.fillOval(290,100,90,55);
    }
}
        

Output

Demonstrate the functionality of packages.


/*Write a java program to create and demonstrate packages.*/
package MyPack;

public class Balance
{
      String name;
      double bal;
      public Balance(String n,double b)
      {
                  name=n;
                  bal=b;
      }
      public void Show()
      {
                  if(bal<0)
                  {
                              System.out.print("--> ");
                  }
                  System.out.println(name + ": $" + bal);
      }
}

   TESTBALANCE.JAVA

   import MyPack.*;

class TestBalance
{
            public static void main(String args[])
            {
                        Balance test=new Balance("J.J.Jaspers",99.88);
                        test.Show();
            }
}

Write a java program to create an abstract class named Shape that contains an empty method named numberOfSides ( ).Provide three classes named Trapezoid, Triangle and Hexagon such that each one of the classes extends the class Shape. Each one of the classes contains only the method numberOfSides ( ) that shows the number of sides in the given geometrical figures.



abstract class Shape
{
    abstract int numberOfSides();
}

class Trapezoid extends Shape
{
    private static int sides=4;
    int numberOfSides()
    {
        return sides;
    }
    public String toString()
    {
        return "Trapezoid";
    }
}

class Triangle extends Shape
{
    private static int sides=3;
    int numberOfSides()
    {
        return sides;
    }
    public String toString()
    {
        return "Triangle";
    }
}

class Hexagon extends Shape
{   
    private static int sides = 6;
    int numberOfSides()
    {
        return sides;
    }
    public String toString()
    {
        return "Hexagon";
    }
}

public class Shapes
{
    public static void main(String args[])
    {
    Shape[] shapes = new Shape[4];
    Trapezoid tp = new Trapezoid();
    Triangle tr = new Triangle();
    Hexagon hx = new Hexagon();
    shapes[0]=tp;
    shapes[1]=tr;
    shapes[2]=hx;
    for(int i=0 ; i<3 ;i++)
    {
        System.out.println(shapes[i].toString()+" #sides:"+shapes[i].numberOfSides());

    }

    }
}

Output:


E:\javamani>java Shapes
Trapezoid #sides:4
Triangle #sides:3
Hexagon #sides:6

Write a Java program that creates three threads. First thread displays “Good Morning” every one second, the second thread displays “Hello” every two seconds and the third thread displays “Welcome” every three seconds.


class A extends Thread
{
     synchronized public void run()
     {
    try
    {
        while(true)
        {
           sleep(1000);
           System.out.println("good morning");
        }
    }
    catch(Exception e)
    { }
      }
}
class B extends Thread
{
      synchronized public void run()
      {
    try
    {
        while(true)
        {
        sleep(2000);
        System.out.println("hello");
        }
        }
      catch(Exception e)
    { }
      }
}
class C extends Thread
{
     synchronized public void run()
     {
    try
    {
        while(true)
        {
            sleep(3000);
            System.out.println("welcome");
        }
    }
    catch(Exception e)
    { }
     }
}
class ThreadDemo
{
    public static void main(String args[])
    {
        A t1=new A();
        B t2=new B();
        C t3=new C();
        t1.start();
        t2.start();
        t3.start();
    }
}

Output:

E:\javamani>java ThreadDemo
good morning
good morning
hello
good morning
welcome
good morning
hello
good morning
welcome
hello
good morning
good morning
hello
good morning
welcome
good morning
hello
good morning
good morning
hello
welcome
good morning

Program to multiply given value with 2, but without using assignment operators


#include<stdio.h>
main()
{
    int a;
    clrscr();
    printf("Enter A value:");    scanf("%d",&a);
    a=a<<1;
    printf("The mul given value:%d",a);
    getch();
}


output:

Enter A value: 2
The mul given value : 4

Program to print days, years, months, weeks, to the given days.


#include<stdio.h>
#include<conio.h>
main()
{
    int days,years,months,weeks,temp;
    clrscr();
    printf("Enter Days:");
    scanf("%d",&days);
    years=days/360;            /*Years Logic*/
    days=days%360;            /*Days Logic*/
    temp=days;            /*Assign Days to the temp variable*/
    months=temp/30;            /*Months Logic*/
    days=temp%30;
    temp=days;
    weeks=temp/7;
    days=temp%7;
    printf("the years=%d months=%d weeks=%d days=%d",years,months,weeks,days);
    getch();
}



output
Enter Days:568
the years=1 months=6 weeks=4 days=0

 

Program to Count the number of vowels and consonants in a given string using Conditional operator


#include<stdio.h>
#include<string.h>
main()
{
    char s[25];
    int i,v=0,c=0;
    printf("Enter string--");   
    scanf("%s",&s);
    for(i=0;s[i]!='\0';i++)
    (s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='i'||s[i]=='o'||s[i]=='u')?v++:c++;
    printf("the count of v is %d \n the count of c is %d",v,c);
    getch();
}

output
Enter string--
this
the count of v is 1
 the count of c is 3

Adding C program using functions


/* An to the Functions*/
#include<stdio.h>
int add(int,int);
main()
{
    int a, b, c;
    clrscr();
    printf("Enter A and B values:");
    scanf("%d %d",&a,&b);
    c=add(a,b);
    /*Jump to the function name which has add()*/
    printf("The additon is: %d",c);
    getch();
}
int add(x,y)
/*x, y values means given a,b values copy to the x,y like x=a(value which is given)*/
{
    int z;
    /*Add procedure function*/
    z=x+y;
    return(z);     /*read the z value,send to the main where it was faced*/
}


output:

Enter A and B values:
2
5
The additon is: 7


Program to perform Matrix addition


/* ------------------------------------------------------------*
 | Program Addition of Two matrix                              |
 | Author : Mr.K.Manikanta         created @ 29-10-2011        |
 | in V.R.S and Y.R.N college of Eng & Tech                    |
 *------------------------------------------------------------*/

#include<stdio.h>     /*Linkage Section*/
#include<conio.h>     /*Linkage Section*/
int main()
{
    int a[10][10],b[10][10],c[10][10],i,j,p,q,m,n;        /*Initilization of Varibles*/
    clrscr();
    printf("Enter First Matrix row and column size");
    scanf("%d %d",&m,&n);
    printf("Enter Values into first Matrix \n");
    for(i=0;i<m;i++)                                         /*First Matrix */
     for(j=0;j<n;j++)
     scanf("%d",&a[i][j]);

    printf("Enter Second row and column size");
    scanf("%d %d",&p,&q);
    printf("Enter Values into Second Matrix");         /*Second Matrix*/
    for(i=0;i<p;i++)
     for(j=0;j<q;j++)
     scanf("%d",&b[i][j]);

       if(m==p && n==q)
       {
    printf("The result of Addition Matrix is: \n");
    for(i=0;i<m;i++)
     for(j=0;j<n;j++)
     c[i][j]=a[i][j]+b[i][j];

     for(i=0;i<m;i++)
     {
     for(j=0;j<n;j++)
     printf(" %4d",c[i][j]);                /*Result of addition matrix*/
     printf("\n");
     }
    }
    else
    {
        printf("Your given matrix values addition is not possible");
    }

    getch();
}

Output
Enter First Matrix row and column size
2
2
Enter Values into first Matrix
2
4
3
6
Enter Second row and column size
2
2
Enter Values into Second Matrix
5
4
2
3
The result of Addition Matrix is:
    7    8
    5    9

The total distance traveled by vehicle in 't' seconds is given by distance = ut+1/2at2 where 'u' and 'a' are the initial velocity(m/sec.) and acceleration (m/sec2). Write C program to find the distance travelled at regular intervals of time given the values of 'u' and 'a'.The program should provide the flexibility to the user to select his own time intervals and repeat the calculations for different values of 'u' and 'a'.



#include<stdio.h>
#include<conio.h>
main()
{
    float t, u, a,distance;
    /* t- time, u- Initial velocity, a- acceleration */
    char key;
    clrscr();
    do
    {
    clrscr();
    printf("\n Enter the Initial Velocity U (m/sec1): ");
    scanf("%f",&u);
    printf("\n Enter acceleration A (m/sec2): ");
    scanf("%f",&a);
    printf("\n Enter Time T (minutes): ");
    scanf("%f",&t);

    /*Logic point*/

    distance=(u*t)+0.5*a*(t*t);

    printf("\n Travelled distance is %f",distance);
    printf("\n\n Sir, Do more enter y, e-exit \n");
    fflush(stdin);
    scanf("%c",&key);
    if(key=='e' || key=='E')
    exit();
    } while(key=='y' || key=='Y');
getch();
}

output

 Enter the Initial Velocity U (m/sec1): 1

 Enter acceleration A (m/sec2): 2

 Enter Time T (minutes): 4

 Travelled distance is 20.000000

 Sir, Do more enter y, e-exit

Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result.(Consider the Operator +,-,*,/,% and use switch statement.


#include<stdio.h>
#include<conio.h>
main()
{
    int a,b;
    char operator;
    clrscr();
    printf("Enter A,B values:");
    scanf("%d %d",&a,&b);
    printf("Choose one of the operator\n");
    printf(" + for addition \n - for subtraction \n * for multiply \n / for division \n \%   modulus\n");
    fflush(stdin);
    scanf("%c",&operator);
    switch(operator)
    {
        case '+' : printf("sum %d + %d= %d",a,b,a+b);
                break;
        case '-' : printf("Subtraction %d - %d = %d",a,b,a-b);
                break;
        case '*' : printf("Multiplication is %d",a,b,a*b);
                break;
        case '/' : printf("Division is %d / %d = %f",a,b,(float)(a)/b);
                break;
        case '%' : printf("Modules %d % %d = %d",a,b,a%b);
                break;
        default : printf("Wrong action");
    }
getch();
}

output 
Enter A,B values:
2 5 
Choose one of the operator 
 + for addition
 - for subtraction
 * for multiply
 / for division
 %   modulus
+
sum 2 + 5= 7

Program to find the given number is Fibonacci number or not.


#include<stdio.h>
#include<conio.h>
int main()
{
    int n,t,f=1;
    clrscr();
    printf("Enter Value");
    /*Read the n value */
    scanf("%d",&n);
    /*Logic for factorial */
    for(t=n;t>0;t--)
    {
       f=f*t;
    }
    printf("The factorial of the %d is %d",n,f);
getch();
}

output

Enter Value5
The factorial of the 5 is 120

Program to find the Perfect Square of a Given number using C program


#include<stdio.h>
#include<math.h>
int main()
{
    int n,t;
    clrscr();
    printf("Enter n value :");
    scanf("%d",&n);
    t=sqrt(n);
    printf("%d \n",t);
    if(n==t*t)
    {
        printf("Given number is Perfect Square %d",t);
    }
    else
    printf("Given number is Not perfect");
getch();
}



output
Enter n value :49
7
Given number is Perfect Square 7

Program to find the radious of a circle Using C language


#include<stdio.h>
#include<conio.h>
void main()
{
 float a,pi,r;
 clrscr();
 printf("enter the radius:");
 scanf("%f",&r);
 pi=3.14159;
 if(r>=0)
 {
  a=pi*r*r;
  printf("the area of the circle of radius %f is %f",r,a);
 }
  else
  {
   printf("negative values are not permitted:");
  }
  getch();
}
 
output

enter the radius:5
the area of the circle of radius 5.000000 is 78.539749

Program to Convert the temparature celcius to farenheit value


#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float c,f,temp;
clrscr();
printf("Enter Temperature Value in Celsius\t");
scanf("%f",&c);
temp=c*9/5;
temp=temp+32;
f=temp;
printf("          The foreign heat Value\t%f",temp);
getch();
}
output:

Enter Temperature Value in Celsius    1
          The foreign heat Value        33.799999

Find fibonacci series to the given number


#include<stdio.h>
int main()
{
    int k=2,r;
    long int i=0l,j=1,f;

    printf("Enter the number range:");
    scanf("%d",&r);

    printf("Fibonacci series is: %ld %ld",i,j);

    while(k<r){
         f=i+j;
         i=j;
         j=f;
         printf(" %ld",j);
          k++;
    }
 
    return 0;
}


output

Enter the number range: 10
Fibonacci series is: 0 1 1 2 3 5 8 13 21 34

Addition of Two Matrices Using Functions


/*C Program addion of two matrixes using function*/

#include<stdio.h>
#include<conio.h>

void read_mat(int,int[10][10]);
void add_mat(int,int[10][10],int[10][10]);

main()
{
    int a[10][10],b[10][10],n;
    clrscr();
    printf("Enter Matrix size:");
    scanf("%d",&n);
    printf("Your chooses %d*%d Matrix:\n",n,n);

    printf("Enter elements into First Matrix:");
    read_mat(n,a);

    printf("Enter elements into Second Matrix:");
    read_mat(n,b);

    printf("Addition of the Matrix is :\n");
    add_mat(n,a,b);

    getch();
}

/*Function Starts Main follow Me*/

void read_mat(int x,int a[10][10])
{
    int i,j;
    for(i=0;i<x;i++)
    for(j=0;j<x;j++)
    scanf("%d",&a[i][j]);
}

void add_mat(int x,int a[10][10],int b[10][10])
{
    int i,j,c[10][10];
    for(i=0;i<x;i++)
    for(j=0;j<x;j++)

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

    for(i=0;i<x;i++)
    {
        for(j=0;j<x;j++)
        printf("%d  ",c[i][j]);
        printf("\n");
    }
}

output
Enter Matrix size:2

Your chooses 2*2 Matrix:

Enter elements into First Matrix:
2
2
2
2
Enter elements into Second Matrix:
2
2
2
2
Addition of the Matrix is :
4  4
4  4

C program to find the sum of individual digits


/*Program to find the sum of individual digits*/
#include<stdio.h>
#include<conio.h>
main()
{
    int a,r,result;
    clrscr();
    printf("Enter A value:");
    scanf("%d",&a);
    r=result=0;
    while(a>0)
    {
        r=a%10;
        a=a/10;
        result=result+r;
    }
    printf("Sum of individual digits: %d",result);
    getch();
}

output:

Enter A value:125
Sum of individual digits: 8

Program to find the LARGEST and smallest number in the given array


/*Write a C program to find both the LARGEST and SMALLEST number in a
list of integers
*/

#include<stdio.h>

main()
{
    int a[10],n,i,small,large;
    clrscr();
    printf("Enter how many integers:");
    scanf("%d",&n);
    printf("Enter %d integers:",n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    small=large=a[0];
    for(i=0;i<n;i++)
    {
        if(a[i]<small)
        small=a[i];
        if(a[i]>large)
        large=a[i];
    }
    printf("\n\t LARGEST %d",large);
    printf("\n\t small   %d",small);
    getch();
}

output:

Enter how many integers:10
Enter 10 integers:
20
30
50
10
256
4
178
25
45
24

         LARGEST 256
         small   4

Write a C program that uses functions to perform the Matrix Multiplication to the 2 Given Matrixes


/*Write a C program that uses functions to perform the
Matrix Multiplication to the 2 Given Matrixes
*/
#include<stdio.h>
#include<conio.h>

void read_mat(int,int,int[10][10]);
void print_mat(int,int,int[10][10]);
void mul_mat(int,int,int,int[10][10],int[10][10]);

main()
{
    int a[10][10],b[10][10],i,j,m,n,p,q;
    clrscr();
    printf("Enter 1st Matrix Row size and Column size:");
    scanf("%d %d",&m,&n);
            read_mat(m,n,a);
    printf("Enter 2nd Matrix Row size and Column size:");
    scanf("%d %d",&p,&q);
        read_mat(p,q,b);

    if(n!=p)
    {
        printf("Mulatiplication Not Possible");
    }
    else
    {
        printf("After Maultiplication:\n");
        mul_mat(m,q,n,a,b);
    }
    getch();
}

void read_mat(int x,int y,int c[10][10])
{
    int i,j;
    printf("Enter Elements:");
    for(i=0;i<x;i++)
    for(j=0;j<y;j++)
    scanf("%d",&c[i][j]);
}

void print_mat(int x,int y,int c[10][10])
{
    int i,j;
    for(i=0;i<x;i++)
    {
        for(j=0;j<y;j++)
        printf("%5d",c[i][j]);
        printf("\n");
    }
}

void mul_mat(int x,int y,int z,int a[10][10],int b[10][10])
{
    int i,j,k,c[10][10];
    for(i=0;i<x;i++)
    {
        for(j=0;j<y;j++)
        {
             c[i][j]=0;
             for(k=0;k<z;k++)
             c[i][j]=c[i][j]+a[i][k]*b[k][j];
        }
    }
    print_mat(x,y,c);
}

output:
Enter 1st Matrix Row size and Column size:
2
2
Enter Elements:
1
2
3
4
Enter 2nd Matrix Row size and Column size:2
2
Enter Elements:
9
8
7
6
After Multiplication:
   23   20
   55   48

Write a C program that uses functions to perform the Calculating transpose of a matrix in-place manner.


/*Write a C program that uses functions to perform the
Calclulating transpose of a matrix in-place manner.
*/
#include<stdio.h>
#include<conio.h>

void read_mat(int,int,int[10][10]);
void print_mat(int,int,int[10][10]);
void transpose_mat(int,int,int[10][10]);

main()
{
    int a[10][10],b[10][10],i,j,m,n;
    clrscr();
    printf("Enter Matrix Row size and Column size:");
    scanf("%d %d",&m,&n);
            read_mat(m,n,a);
    printf("Before Transpose:\n");
        print_mat(m,n,a);
    printf("After Transpose Matrix:\n");
        transpose_mat(m,n,a);
    getch();
}

void read_mat(int x,int y,int c[10][10])
{
    int i,j;
    printf("Enter Elements:");
    for(i=0;i<x;i++)
    for(j=0;j<y;j++)
    scanf("%d",&c[i][j]);
}

void print_mat(int x,int y,int c[10][10])
{
    int i,j;
    for(i=0;i<x;i++)
    {
        for(j=0;j<y;j++)
        printf("%5d",c[i][j]);
        printf("\n");
    }
}

void transpose_mat(int x,int y,int a[10][10])
{
    int i,j,b[10][10];
    for(i=0;i<x;i++)
    for(j=0;j<y;j++)
    b[j][i]=a[i][j];
    print_mat(x,y,b);
}

output:

Enter Matrix Row size and Column size:
3
3
Enter Elements:
1
2
3
4
5
6
7
8
9
Before Transpose:
    1    2    3
    4    5    6
    7    8    9
After Transpose Matrix:
    1    4    7
    2    5    8
    3    6    9

Write a C program to determine if the given String is Palindrome or not


/*Write a C program to determine if the given String is Palindrome or not*/

#include<stdio.h>
#include<conio.h>
#include<string.h>

int is_palindrome(char[]);

main()
{
    char ch[50];
    int t;
    clrscr();
    printf("Enter String:");
    scanf("%s",ch);
    t=is_palindrome(ch);
    if(t==1)
    printf("Given is palindrome");
    else
    printf("Given is not palindrome");
    getch();
}

int is_palindrome(char s1[])
{
    char s2[50];
    int l,i;
    l=strlen(s1);
    for(i=0;i<l;i++)
    s2[l-(i+1)]=s1[i];
    for(i=0;i<l;i++)
    if(s1[i]!=s2[i])
        return 0;
    else
        return 1;
}


output:

Enter String:  liril
Given is palindrome

Write a C program that uses functions to perform ii.) To Delete a string in to given main string from a Given position.


/*Write a C program that uses functions to perform
    ii.) To Delete a string in to given main string from a Given position.
*/


#include<stdio.h>
#include<conio.h>
#include<string.h>

void string_deletion(char[100]);    /*FUNCTION DECLARATION*/

main()
{
    char ms[100];
    int i;
    clrscr();
    printf("Enter Main String:");
    scanf("%s",ms);

    printf("Main string and its position:\n");
    for(i=0;ms[i]!='\0';i++)
       printf("%c ",ms[i]);
       printf("\n");
       for(i=0;ms[i]!='\0';i++)
       printf("%d ",i);

    string_deletion(ms);            /*FUNCTION CALLING BY PASSING THE VALUES*/
    getch();
}

void string_deletion(char ms[100])    /*FUNCTION DEFINITION*/
{
    int position,s1,i,n;
    printf("\n Enter number of charaters your want to remove:");
    scanf("%d",&n);
    printf("Enter the position:");
    scanf("%d",&position);
    s1=strlen(ms);
    if(position<0||position>s1)
        printf("\nInvalid position........!");
    else
    {
        for(i=position+n;i<=s1;i++)
        ms[i-n]=ms[i];
        printf("After Deletion %s",ms);
    }
}


output:
Enter Main String:
MAHESHBABU
 

Main string and its position:
M A H E S H B A B U
0 1 2 3 4 5 6 7 8 9
 

Enter number of charaters your want to remove:4
Enter the position:6


After Deletion MAHESH

WRITE A PROGRAM USING RECURSIVE FUNCTIONS TO GET THE BINARY VALUE FOR THE GIVEN DECIMAL NUMBER


/*WRITE A PROGRAM USING RECURSIVE FUNCTIONS TO GET THE BINARY VALUE FOR THE GIVEN DECIMAL NUMBER*/

#include<stdio.h>
#include<conio.h>

void binary(int x);

main()
{
    int num;
    clrscr();
    printf("Enter number:");
    scanf("%d",&num);
    printf("The binary value for the given number:\n");
    binary(num);
    getch();
}

void binary(int x)
{
    if(x/2)
    binary(x/2);
    printf("%d",x%2);
}

output:

Enter number:
25
The binary value for the given number:11001

Checking symmetric of a square matrix using functions in C program.


#include<stdio.h>
#include<conio.h>

int symmetric(int[10][10],int);
void read_mat(int[10][10],int);

main()
{
    int a[10][10],i,j,n,s;
    clrscr();
    printf("Enter Matrix size:");
    scanf("%d",&n);

    printf("Enter %d Elements:",n*n);
    read_mat(a,n);

    s=symmetric(a,n);

    if(s==1)
    printf("Symmetric");
    else
    printf("Not Symmetric");
    getch();
}

void read_mat(int a[10][10],int n)
{
    int i,j;
    for(i=0;i<n;i++)
    for(j=0;j<n;j++)
        scanf("%d",&a[i][j]);
}

int symmetric(int a[10][10],int n)
{
    int i,j,at[10][10],c;
    for(i=0;i<n;i++)
    for(j=0;j<n;j++)
       at[i][j]=a[j][i];

       printf("After Transpose:\n");

       for(i=0;i<n;i++)
       {
       for(j=0;j<n;j++)
       printf("%5d",at[i][j]);
       printf("\n");
       }


       for(i=0;i<n;i++)
       for(j=0;j<n;j++)
        if(a[i][j]!=at[i][j])
        return 0;
        else
        c++;
}


output:
Enter Matrix size:2
Enter 4 Elements:
1
2
2
1
After Transpose:
    1    2
    2    1
Symmetric


Write a C program to generate Pasal's Triangle


 /*Write a C program to generate Pasal's Triangle*/
#include<stdio.h>
#include<conio.h>

long factorial(int);

main()
{
    int i,j,n;
    /*clear screen logic*/
        for(i=0;i<50;i++)
        printf("\n");
        gotoxy(1,1);
    /*clear screen login end*/

    printf("                Pascal Triangle\n");
    printf("Enter Range:");
    scanf("%d",&n);
    for(i=0;i<=n;i++)
    {
        for(j=0;j<n-i;j++)
        printf(" ");

        for(j=0;j<=i;j++)
        {
            printf("%ld ", factorial(i)/(factorial(i-j)*factorial(j)));
        }

        printf("\n");
    }
    getch();
}

long factorial(int n)
{
    int i;
    long int result=1;
    if(n==0)
        return 1;
    else
    {
        for(i=1;i<=n;i++)
        result=result*i;
        return (result);
    }
}

output:
                Pascal Triangle
Enter Range:5
     1
    1 1
   1 2 1
  1 3 3 1
 1 4 6 4 1
1 5 10 10 5 1


Twitter Delicious Facebook Digg Stumbleupon Favorites More