Monday, 11 November 2013

C program to find largest and second largest among four numbers


C program to find largest and second largest among four numbers:

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

 main()
{
    int A[4];
    int i,j,b;
clrscr();
   for(i=0;i<4;i++)
{
   printf("\nEnter the Number %d : ", i+1);
   scanf("%d", &A[i]);
}
   for(i=0;i<4;i++)
{
   for(j=i;j<4;j++)
{
   if(A[i]< A[j])
{
   b=A[j];
  A[j]=A[i];
  A[i]=b;
}
}
}
  printf("\nLargest Number is: %d\n",A[0]);
  printf("\nSecond Largest Number is : %d\n",A[1]);
getch();
return 0;
}



OUTPUT:







  

Saturday, 9 November 2013

C program (MENU DRIVEN) to find the area of circle,triangle,equilateral triangle,right angled triangle,rectangle,square, trapezium,rhombus and parallelogram

C program (MENU DRIVEN) to find the area of circle, triangle,
 equilateral triangle, right angled triangle, rectangle,
 square, trapezium, rhombus and parallelogram.


 #include <stdio.h>
 #include<conio.h>
 #include <stdlib.h>
 #include <math.h>
  int main()

 {
    float area, s;
    int a, b, c, length, breath, height, radius, side, ch;
    clrscr();
    while(1) {
        /* get the option from user */
        printf("1. Circle\t2. Triangle\n");
        printf("3. Rectangle\t4. Square\n");
        printf("5. Trapezoid\t6. Rhombus\n");
        printf("7. Parallelogram\t8.Equilateral triangle \n");
    printf("9.aright angled triangle\t10.Exit\n");
        printf("Enter your choice:");
        scanf("%d", &ch);

        switch(ch) {
            case 1:                printf("Enter the radius of the circle:");
                scanf("%d", &radius);
                area = 3.14 * radius * radius;

                printf("Area of Circle: %f\n", area);
                break;

            case 2:
                printf("Enter the sides of the triangle:");
                scanf("%d%d%d", &a, &b, &c);
                s = (1.0 * (a + b + c)) / 2;
                area = sqrt(s * (s - a) * (s - b) * (s - c));
                printf("Area of Triangle: %f\n", area);
                break;

            case 3:
                printf("Enter the length and breath of Rectangle:");
                scanf("%d%d", &length, &breath);
                area = length * breath;
                printf("Area of Rectangle: %f\n", area);
                break;

            case 4:
                printf("Enter the side of a square:");
                scanf("%d", &side);
                area = side * side;
                printf("Area of square: %f\n", area);
                break;

            case 5:
                printf("Enter the length of parallel sides(a & b):");
                scanf("%d%d", &a, &b);
                printf("Enter the height:");
                scanf("%d", &height);
                area = ((a + b) * 1.0 * height) / 2;
                printf("Area of trapezoid: %f\n", area);
                break;

            case 6:
                printf("Enter the diagonal values(p & q):");
                scanf("%d%d", &a, &b);
                area = a * b / 2;
                printf("Area of rhombus: %f\n", area);
                break;

            case 7:
                printf("Enter the breath and height of parallelogram:");
                scanf("%d%d", &b, &height);
                area = b * height * 1.0 / 2;
                printf("Area of parallelogram: %f\n", area);
                break;

            case 8:
                printf("Enter the side of a Equilateral triangle:");
                scanf("%d", &a);
                area = (sqrt(3)/4)*(a*a);
                printf("Area of Equilateral triangle: %f\n", area);
                break;
         

            case 9:
                printf("Enter the value of a and b for right angled triangle:");
                scanf("%d%d", &a,&b);
                area = (1/2)*(a*b);
                printf("Area of right angled triangle: %f\n", area);
                break;

            case 10:
                exit(0);

            default:
                printf("Wrong Option!!\n");
                break;
        }
    getch();
    return 0;
  }
  }
  OUTPUT:
     1. Circle                   2. Triangle
     3. Rectangle                4. Square
     5. Trapezoid                6. Rhombus
     7. Parallelogram            8.Equilateral triangle
     9.aright angled triangle   10.Exit

     Enter your choice: 2
     Enter the size of the triangle: 2 5 6
     Area of Triangle: 4.683749
 

C program (menu driven) to find the volume and surface area of cube, cuboids, cylinder, cone, sphere and hemi-sphere

C program (menu driven) to find the volume and surface area of cube,
cuboids, cylinder, cone, sphere and hemi-sphere


#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <math.h>
  int main() {
    float v,sa;
    int a,l,b,h,ch,r,s;
    clrscr();
    while(1) {
        /* get the option from user */
        printf("1. Cube\t2. Cuboid\n");
        printf("3. Cylinder\t4. Cone\n");
        printf("5. Sphere\t6. Hemi-sphere\n");
        printf("7. Exit\n");

        printf("Enter your choice:");
        scanf("%d", &ch);
        switch(ch) {
            case 1:
                printf("Enter the value of a for cube:");
                scanf("%d", &a);
                v=a*a*a;
                sa=6*a*a*a*a*a*a;
        printf("Surface Area of Cube: %f\n", sa);
        printf("\nVolumn of Cube: %f\n",v);
                break;

            case 2:
        printf("\nEnter the value of l,h and b for cuboid:");
        scanf("%d%d%d",&l,&h,&b);
                v=l*h*b;
                sa=(2*l*h)+(2*h*b)+(2*b*l);
        printf("Surface Area of Cuboid: %f\n", sa);
        printf("\nVolumn of Cuboid: %f\n",v);

                break;

            case 3:
        printf("\nEnter the value of r and h for Cylinder:");
        scanf("%d%d",&r,&h);
                v=3.14*r*r*h;
                sa=(2*3.14*r*r)+(2*3.14*r*h);
        printf("Surface Area of Cylinder: %f\n", sa);
        printf("\nVolumn of Cylinder: %f\n",v);

                break;


            case 4:
        printf("\nEnter the value of r, h and s for Cone:");
        scanf("%d%d%d",&r,&h);
                v=(1/3)*3.14*r*r*h;
                sa=(3.14*r*s)+(3.14*r*r);
        printf("Surface Area of Cone: %f\n", sa);
        printf("\nVolumn of Cone: %f\n",v);

                break;


            case 5:
        printf("\nEnter the value of r for Sphere:");
        scanf("%d%d",&r,&h);
                v=(4/3)*3.14*r*r*r;
                sa=4*3.14*r*r;
        printf("Surface Area of Sphere: %f\n", sa);
        printf("Volumn of Sphere: %f\n",v);

                break;


            case 6:

        printf("\nEnter the value of r for Hemi-Sphere:");
        scanf("%d%d",&r,&h);
                v=(2/3)*3.14*r*r*r;
                sa=2*3.14*r*r;
        printf("Surface Area of Hemi-Sphere: %f\n", sa);
        printf("Volumn of Hemi-Sphere: %f\n",v);

                break;


            case 7:
                exit(0);

            default:
                printf("Wrong Option!!\n");
                break;
         }
         getch();
         return 0;
    }


  }


OUTPURT:
     
       1. Cube     2. Cuboid
       3. Cylinder 4. Cone
       5. Sphere   6. Hemi-sphere
       7. Exit

       Enter your choice: 5
       Enter the value for r for Sphere: 6 5
       Surface Area of Sphere: 452.160004
       Volume of Sphere: 678.239990


Thursday, 7 November 2013

C program to find Fibonacci series of a number (using ARRAY)

C program to find Fibonacci series of a number (using ARRAY)

#include<stdio.h>
#include<conio.h>
main()
{

    int i,n;
    long int arr[40];

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

    arr[0]=0;
    arr[1]=1;

    for(i=2;i<n;i++){
         arr[i] = arr[i-1] + arr[i-2];
    }

    printf("Fibonacci series is: ");
    for(i=0;i<n;i++)
         printf("%ld ",arr[i]);
 
getch();   

return 0;
}




OUTPUT:

Enter the number range: 8

Fibonacci series is: 0 1 1 2 3 5 8 13

C program to find fibonacci series (using FOR Loop)

C program to find fibonacci series:

#include<stdio.h>
#include<conio.h>
main()
{
int i,x,y,z,n;
clrscr();
printf("\nEnter a number:");
scanf("%d",&n);
x=0;
y=1;
printf("%d%d",x,y);
for(i=3;i<=n;i++)
{
z=x+y;
printf("%d ",z);
x=y;
y=z;
}
getch();
return 0;
}



OUTPUT:

Enter a number: 8
       0 1 1 2 3 5 8 13
 

C program to check whether a number is EVEN or ODD

C program to check whether a number is EVEN or ODD

#include<stdio.h>
#include<conio.h>
main()
{
int number;
clrscr();
printf("Enter any integer: ");
scanf("%d", &number);
if(number%2==0)
printf("%d is even number.",number);
else
printf("%d is odd number.",number);
getch();
return 0;
}



OUTPUT:

Enter any integer: 17

17 is odd number. 

 

Monday, 4 November 2013

C program to find quotent and remainder of 2 integers

C program to find quotent and remainder of 2 integers:

#include<stdio.h>
#include<conio.h>
main()
{
int n,t,quot,rem;
clrscr();
printf("\nEnter two numbers: \t");
scanf("%d%d",&n,&t);
quot=(n/t);
rem=(n%t);
printf("Quotient is: %d",quot);
printf("Remainder is: %d", rem);
getch();
return 0;
}

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan