Posts

Showing posts from November, 2016

C++ Code that uses a do..while loop to compute and print the sum of the squares of a number obtained from the operator.

#include<iostream> using namespace std; int main() /* QUESTION:Write a C++ program that uses a do..while loop to compute and print           the sum of the squares of  a number obtained from the operator.           For  example if 5 is input, it will print 55 (i.e 1^2 + 2^2 + 3^2 + 4^2 + 5^2)                     BY: OYENIRAN OLUWASHINA AKINLOYE */ {     // variable decleartion  int v,x,sax = 0;  cout<<"TYPE IN THE NUMBER"<<endl;  cin>> v;  //the initail value of x is set to 0 instead of 1 because if 1 is used, the result will be decreased by 1  // using 0 value will by default set 1 as the intial value although 0 will be printed as the first value  x=0;     do  {      //the result of each square are presented and the total was shown...

C++ Code that uses a for loop to compute and print the sum of the squares of a number obtained from the operator.

#include<iostream> using namespace std; int main() /* QUESTION: Write a C++ program that uses a for loop to compute and print           the sum of the squares of  a number obtained from the operator.           For  example if 5 is input, it will print 55 (i.e 1^2 + 2^2 + 3^2 + 4^2 + 5^2)                     BY: OYENIRAN OLUWASHINA AKINLOYE */ {     // variable decleartion  int v,x,sax = 0;  cout<<"TYPE IN THE NUMBER"<<endl;  cin>> v;  //the initail value of x is set to 1 while the increment was also set to 1   for(x=1;x<=v;x++)   {        sax += x*x;        //the result of each square are presented and the total was shown at the last line of the results.        cout<<"THE RESULT IS: "<...

C++ Code that uses a while loop to compute and print the sum of the squares of a number obtained from the operator.

#include<iostream> using namespace std; int main() /* C++ program that uses a while loop to compute and print the sum of the squares of  a number obtained from the operator. For  example if 5 is input, it will print 55 (i.e 1^2 + 2^2 + 3^2 + 4^2 + 5^2)           BY: OYENIRAN OLUWASHINA AKINLOYE */ {     // variable decleartion  int v,x,sax = 0;  cout<<"TYPE IN THE NUMBER"<<endl;  cin>> v;  //the initail value of x is set to 1  x=1;  while (x<=v)  {       sax += x*x;       x++;       //the result of each square are presented and the total was shown at the last line of the results.        cout<<"THE RESULT IS: "<< sax<<endl;  }    return 0; }  

C++ Code to find odd number

#include <iostream> using namespace std; int main () /*     Name: for loop to find odd numbers between a certain range of figure     Copyright: Oluwashina A. Oyeniran     Author: Oyeniran Oluwashina Akinloye     Date: 23-07-16 08:59     Description: C++ code to find the odd numbers between certain range of figure     // z is defined as odd number (as in int z = 1)     // 1 is the initial value (as in int z = 1)     // 2 is the incremential value (as in z += 2)     // 10 is the heighst range of value while 1 is the least (z <= 10) */ {     for (int z = 1; z <= 10; z += 2)     {         cout << "The number is " << z << endl;     }     return 0; }

C++ Code to find numbers divisible by 7 using do..while loop

#include<iostream> using namespace std; int main () //C++ Program to find numbers divisible by 7 using do..while loop {     int z = 7;     do     {         cout << "The number divisible by 7 is " << z << endl;         z +=7;     }     while (z <= 1000);     return 0; }

C++ Code to find numbers divisible by 7 using for loop

#include <iostream> using namespace std; int main() // C++ program to find numbers divisible by 7 using for loop {     for (int z = 7; z <= 1000; z += 7)     {         cout << "The number divisible by 7 is " << z << endl;     }     system("pause");     return 0; }