Welcome To Uday Satya Blog

16 - 20 PROGRAMS



                                                                                                                                               
/* **************************************************
     16. To Convert Farenheit(F) to Centigrade(C) Degrees
    ************************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    float c,f;
    clrscr();
    printf("\n Enter The Temperature in Farenheit Degrees = ");
    scanf("%f", &f);
    c = 5*(f-32)/9;
    printf("\n\n Given Farenheit Value in Centigrade Degrees is : %f", c);
    getch();
    }

   Output :

   Enter The Temperature in Farenheit Degrees = 32

   Given Farenheit Value in Centigrade Degrees is : 0
                                                                                                                                                
/* ************************************************
         17. To Find the Roots of Given Quadratic Equation
    ************************************************ */

   #include<*stdio.h>
   #include<*conio.h>
   #include
   void main()
    {
    int a,b,c,D,r1,r2;
    clrscr();
    printf("\n Enter The Values of : \n");
    printf("\n Coefficient of x^2 = ");
    scanf("%d", &a);
    printf("\n Coefficient of x = ");
    scanf("%d", &b);
    printf("\n Constant Coefficient = ");
    scanf("%d", &c);
    D = b*b-4*a*c;
    if(D>=0)
        {
        r1 = (-b + sqrt(D))/(2*a);
        r2 = (-b - sqrt(D))/(2*a);
        printf("\n\n Roots of Given Equation are : %d,%d", r1, r2);
        }
    else
        printf("\n\n Ooops !!! Given Equation have Complex Roots");
    getch();
    }

   Output :
   Enter The Values of :
   Coefficient of x^2 = 1
   Coefficient of x = -2
   Constant Coefficient = 1

   Roots of Given Equation are : 1,1
                                                                                                                                               

/* ************************************************
        18. To Swap values of a and b using Third Variable
    ************************************************ */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int a,b,temp;
    clrscr();
    printf("\n Enter The Values of a and b to be Swapped : \n");
    printf("\n a = ");
    scanf("%d", &a);
    printf("\n b = ");
    scanf("%d", &b);
    temp=a;
    a=b;
    b=temp;
    printf("\n\n After Swapping : \n\n a = %d \n\n b = %d", a, b);
    getch();
    }

   Output :

   Enter The Values of a and b to be Swapped :
   a = 5
   b = 6

   After Swapping :
   a = 6
   b = 5
                                                                                                                                                
/* ***************************************************
   19. To Swap values of a and b without using Third Variable
   *************************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int a,b;
    clrscr();
    printf("\n Enter The Values of a and b to be Swapped : \n");
    printf("\n a = ");
    scanf("%d", &a);
    printf("\n b = ");
    scanf("%d", &b);
    a = a + b;
    b = a - b;
    a = a - b;
    printf("\n\n After Swapping : \n\n a = %d \n\n b = %d", a, b);
    getch();
    }

   Output :

   Enter the Values of a and b to be Swapped :
   a = 5
   b = 6

   After Swapping :
   a = 6
   b = 5 
                                                                                                                                                
/* ****************************************
         20. To Print Nubers from 1-5 using ++i
    **************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int i=1;
    clrscr();
    printf("\n %d \n", i);
    printf("\n %d \n", ++i);
    printf("\n %d \n", ++i);
    printf("\n %d \n", ++i);
    printf("\n %d \n", ++i);
    getch();
    }

   Output :
   1
   2
   3
   4
   5

0 comments:

Post a Comment