Showing posts with label C tutorial. Show all posts
Showing posts with label C tutorial. Show all posts

Sunday, 28 July 2013

Print Quotient and Remainder in C++

// Write a C++ program that takes two values of x(dividend) and
// y(divisor) from user and prints quotient and remainder of x/y

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int x,y,q,r;
    cout<<"Enter dividend number x : ";
    cin>>x;
    cout<<"Enter divisor number y : ";
    cin>>y;

    cout<<"\n\n------------------------------------\n";
    cout<<" Quotient and Remainder of x/y \n";
    cout<<"------------------------------------\n";

    q = x / y ;
    r = x % y;
    cout<<"Quotient  = "<<q<<endl<<"Remainder = "<<r;
    getch();
}


Wednesday, 24 July 2013

Even Numbers in Descending Order

// Write a C++ program that prints odd numbers in
// descending order from a given range.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Even numbers in Descending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 != 0 )
    n--;
    for( i = n ; i >= 0 ; i = i-2 )
    cout<<"         "<<i<<endl;
    getch();
}

Sunday, 21 July 2013

Even Numbers in Ascending Order

// Write a C++ program that prints even numbers in
// ascending order up to given range.


#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number for ending range : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Even numbers in Ascending Order \n";
    cout<<"------------------------------------\n";

    for( i = 0 ; i <= n ; i = i+2 )
    cout<<"         "<<i<<endl;
    getch();
}

Odd Numbers in Ascending Order

// Write a C++ program that prints odd numbers in
// ascending order up to given number.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Odd numbers in Ascending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 == 0 )
    n--;
    for( i = 1 ; i <= n ; i = i+2 )
    cout<<"         "<<i<<endl;
    getch();
}

Wednesday, 17 July 2013

Odd numbers in descending order

// Write a C++ program that prints odd numbers in 
// descending order from a given input.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Odd numbers in Descending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 == 0 )
    n--;
    for( i = n ; i >= 1 ; i = i-2 )
    cout<<"  "<<i<<endl;
    getch();
}


Monday, 15 July 2013

Temperature Conversion

Convert Fahrenheit to Celsius

C = 5/9(F - 32)

Convert Celsius to Fahrenheit


F = 9/5(C + 32)


Convert Celsius to Kelvin


K = C + 273.15

Convert Kelvin to Celsius

C = K - 273.15

If you are interested in C++ programming, please visit the following links.

Kelvin to Celsius Conversion

// Write a C++ program to convert temperature from
// Kelvin to Celsius.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float k,c;

    cout<<"\n------------------------------------\n";
    cout<<"  Kelvin to Celsius Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Kelvin : ";
    cin>>k;
    c = k - 273.15 ;
    cout<<"\n\n Temp in Kelvin = "<<c;
    getch();
}


Celsius to Kelvin Conversion

// Write a C++ program to convert temperature from
// Celsius to Kelvin.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float c,k;

    cout<<"\n------------------------------------\n";
    cout<<"  Celsius to Kelvin Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Celsius : ";
    cin>>c;
    k = c + 273.15 ;
    cout<<"\n\n Temp in Kelvin = "<<k;
    getch();
}

Sunday, 14 July 2013

Farenheit to Celsius conversion

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float f,c;

    cout<<"\n------------------------------------\n";
    cout<<"  Farenheit to Celsius Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Farenheit : ";
    cin>>f;
    c = (f-32)/1.8;
    cout<<"\n\n Temp in Celsius = "<<c;
    getch();
}

Celsius to Farenheit Conversion

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float c,f;

    cout<<"\n------------------------------------\n";
    cout<<"  Celsius to Farenheit Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Celsius : ";
    cin>>c;
    f=(9/5)*c+32;
    cout<<"\n\n Temp in Farenheit = "<<f;
    getch();
}

Saturday, 13 July 2013

if statement syntax

C++ "if" statement contains following elements.
  • Test expression
  • if body

Figure: if statement

The operation of "if" statement is explained by using flow chart.

Figure: if statement flow chart

Friday, 12 July 2013

do while loop syntax

C++ "do while loop" contains following elements.
  • Test expression
  • Increment expression
  • Loop body
 
Figure: do while loop

The operation of "do while loop" is explained by using flow chart.

Figure: do while loop flow chart

while loop syntax

C++ "while loop" contains following elements.
  • Test expression
  • Increment expression
  • Loop body

Figure: while loop syntax

The operation of "while loop" is explained by using flow chart.

Figure: while loop flow chart

for loop syntax

C++ "for loop" contains following elements.
  • Initialization expression
  • Test expression
  • Increment expression
  • Loop body


Figure: for loop syntax

The operation of "for loop" is explained by using flow chart.

Figure: for loop flow chart