Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- // when you have something that you are gonna be using as a sum of some numbers, you set it like a 0
- // when you have something that you are gonna be using as a product of some numbers, you set it like a 1
- // in this case we have result = 1, because I'll use it like a product
- int base, result = 1;
- double exponent;
- cout << "Enter base: ";
- cin >> base;
- cout << "Enter exponent: ";
- cin >> exponent;
- while(exponent != 0){
- result = result * base;
- exponent--;
- }
- cout << "Result: " << result << endl;
- // it's the same like in past task(we have a product), that's why we have factorial = 1
- int n, factorial = 1;
- cout << "Enter a number: ";
- cin >> n;
- for(int i = 1; i <= n; i++){
- factorial = factorial * i;
- }
- cout << "The factorial of a number is: " << factorial << endl;
- int n;
- cout << "Enter a number: ";
- cin >> n;
- for(int i = 0; i < n; i++){
- cout << "a" << i << " = " << i * i + 3 * i << endl;
- }
- int n, currentNegativeNumber = INT_MAX;
- cin >> n;
- int number;
- for(int i = 0; i < n; i++){
- cin >> number;
- if(number > 0 && number < currentNegativeNumber){
- number =currentNegativeNumber;
- }
- }
- cout << currentNegativeNumber;
- // another solution for biggest negative number!
- double number;
- double negative = 0;
- double largest = 0;
- cout << "Enter a number until reaches zero: ";
- cin >> number;
- while(number != 0){
- if(number < 0){
- negative = number;
- if(largest == 0){
- largest = negative;
- } else {
- if(negative > largest){
- largest = negative;
- }
- }
- } // when we are at the end of the loop, we need to cin a number, until we get biggest negative
- cin >> number;
- }
- if(largest != 0){
- cout << largest << " ";
- } else {
- cout << "non negative number" << endl;
- }
- // find the sum of digits(n % 10 and n / 10 - that's what we need)
- // sum = 0, because we have the sum of digits and set it as zero
- int num, sum = 0;
- cout << "Enter a number: ";
- cin >> num;
- while(num > 0){
- sum += num % 10;
- num /= 10;
- }
- cout << "The sum of digits in one number is " << sum << endl;
- int number, sum = 0;
- while(number > 0){
- cin >> number;
- sum += number;
- }
- cout << "The sum of numbers is " << sum << endl;
- int a, b, product = 1;
- cout << "Enter two numbers: ";
- cin >> a >> b;
- for(int i = a; i <= b; i++){
- product *= i;
- }
- cout << "The product of this interval is " << product << endl;
- // there is one way to print fibonacci series
- int n, term1 = 0, term2 = 1, nextTerm = 0;
- cin >> n;
- for(int i = 2; i <= n; i++){ // it's started from 2, we are not counting 0 and 1
- nextTerm = term1 + term2;
- term1 = term2;
- term2 = nextTerm;
- }
- cout << nextTerm << endl;
- // here is another way
- int n, term1 = 0, term2 = 1, nextTerm = 0;
- cin >> n;
- for(int i = 0; i <= n; i++){ // it's kinda saving up the code
- if(i == 0){
- continue;
- }
- if(i == 1){
- continue;
- }
- nextTerm = term1 + term2;
- term1 = term2;
- term2 = nextTerm;
- }
- cout << nextTerm << endl;
- int n;
- bool isPrime = true;
- cin >> n;
- if(n == 0 || n == 1){ // if(n <= 1) - we can write it like that also
- isPrime = false;
- }
- for(int i = 2; i < n / 2; i++){
- if(n % i == 0){
- isPrime = false;
- break;
- }
- }
- cout << (isPrime ? "True" : "False") << endl;
- int n;
- char symbol1, symbol2;
- cin >> n;
- cin >> symbol1 >> symbol2;
- for(int i = 0; i < n - 1; i++){
- for(int j = 0; j < n; j++){
- if(i >= j){
- cout << symbol1 << " ";
- } else if(i < j){
- cout << symbol2 << " ";
- }
- }
- cout << endl;
- }
- int n, d = 1, binary_number = 0;
- cin >> n;
- if(n < 0 && n > 1000){
- cout << "Wtf are you doing, you're gonna get the error!" << endl;
- } else {
- while(n != 0){
- binary_number += (n % 2) * d;
- d *= 10;
- n /= 2;
- }
- cout << binary_number;
- }
- cout << "We need to get all consonants!" << endl;
- for(int i = 'A'; i <= 'Z'; i++){
- bool isConsonant = !(i == 'A' || i == 'E' || i == 'U' || i == 'O' || i == 'I');
- if(isConsonant){
- cout << (char)i << " ";
- }
- }
- int n;
- cin >> n;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- if(i > j){
- cout << "-";
- } else if(i == j){
- cout << "0";
- } else if(i < j){
- cout << "+";
- }
- }
- cout << endl;
- }
- for(int test = 5; test != 0; test++){
- cout << "< ";
- cin >> test;
- cout << test << endl;
- }
- for(int test = 5; test != 0;){
- cout << "< ";
- cin >> test;
- cout << test << endl;
- }
- int number;
- int count = 0;
- int sum = 0;
- double average;
- cout << "Enter a number: ";
- cin >> number;
- while(number != 0){
- sum += number;
- count++;
- cout << "Enter a number: ";
- cin >> number;
- }
- if(count != 0){
- average = sum / count;
- }
- cout << "Average: " << average << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment