Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Tuesday, March 20, 2012

Sum of number divisible by 7 between 100 and 200

#include <iostream>
using namespace std;

int main()
{
    int i, count = 0, sum = 0;
   
    for (i=101; i<200; i++)
    {
        if(i%7 == 0)
        {
            count = count++;
            sum = sum + i;
        }
    }
   
    cout << "\n Total no of integer div by 7 is: " << count << endl;
    cout << "\n sum of these number: " << sum << endl;
   
    return 0;
}


OUTPUT:

Thursday, March 15, 2012

program to print sum of its integer in given digit

#include <iostream>
using namespace std;

int main()
{
    int num, temp, sum=0;
    cout << "\n Enter your number: ";
    cin >> num;
   
    while(num > 0)
    {
        temp = num%10;
        num = num/10;
        sum = sum + temp;
    }
   
    cout << "\n the sum of integer in your digit is: " << sum << endl;
    return 0;
}


OUTPUT:
 

Program to real roots of quadratic equation with output

// d = b^2 - 4ac

#include <iostream>
#include <cmath>          //when we used c library in c++
using namespace std;

int main()
{
    float a, b, c, d, root1, root2;


    cout << "\n Enter the value of a, b, c: " ;
    cin >> a >> b >> c;
 

    d = b*b - 4*a*c;
    cout << "\n discriminant is: " << d ;
   
    if ( d<0 )
    {
        cout << "\n Roots are imagenary.";
    }
    else
    {
        root1 = (-b + sqrt(d)) / (2*a);
        root2 = (-b - sqrt(d)) / (2*a);
        cout << "\n root1 is: " << root1 << "\n root2 is: " << root2 << endl;
    }
    return 0;
}


OUTPUT: