• Sep 3, 2023 •AustinLeath
0 likes • 10 views
#include "stdio.h" #include <stdlib.h> int main (int argCount, char** args) { int a = atoi(args[1]); int b = atoi(args[2]); unsigned int sum = 0; unsigned int p = 1; for (unsigned int i = 1; i < b; i++) { p = p * i; } // (b!, (1 + b)!, (2 + b)!, ..., (n + b)!) for (unsigned int i = 0; i < a; i++) { p = p * (i + b); sum = sum + p; } printf("y: %u\n", sum); return 0; }
• Apr 15, 2025 •hasnaoui1
0 likes • 4 views
int main()
• Apr 16, 2023 •LeifMessinger
0 likes • 0 views
#include <iostream> #include <string> //Should already be in iostream #include <cstdlib> //A word score adds up the character values. a-z gets mapped to 1-26 for the values of the characters. //wordScore [wordValue] //Pipe in the input into stdin, or type the words yourself. //Lowercase words only int characterValue(const char b){ return ((b >= 'a') && (b <= 'z'))? ((b - 'a') + 1) : 0; } int main(int argc, char** argv){ //The first argument specifies if you are trying to look for a certain word score int wordValue = (argc > 1)? std::atoi(argv[1]) : 0; std::string line; while(std::getline(std::cin, line)){ int sum = 0; for(const char c : line){ sum += characterValue(c); } if(wordValue){ //If wordValue is 0 or the sum is the correct value if(wordValue == sum){ std::cout << line << std::endl; } } else { std::cout << sum << "\t" << line << std::endl; } } return 0; }
• Nov 18, 2022 •AustinLeath
#include <iostream> using namespace std; /* Description: uses switch case statements to determine whether it is hot or not outside. Also uses toupper() function which forces user input char to be uppercase in order to work for the switch statement */ int main() { char choice; cout << "S = Summer, F = Fall, W = Winter, P = Spring" << endl; cout << "Enter a character to represent a season: ";asdasdasdasd cin >> choice; enum Season {SUMMER='S', FALL='F', WINTER='W', SPRING='P'}; switch(toupper(choice)) // This switch statement compares a character entered with values stored inside of an enum { case SUMMER: cout << "It's very hot outside." << endl; break; case FALL: cout << "It's great weather outside." << endl; break; case WINTER: cout << "It's fairly cold outside." << endl; break; case SPRING: cout << "It's rather warm outside." << endl; break; default: cout << "Wrong choice" << endl; break; } return 0; }
1 like • 9 views
#include <iostream> using namespace std; int main() { int arr[5]; for(int i = 0; i < 5; i++) { arr[i] = i; } for(int i = 0; i < 5; i++) { cout << "Outputting array info at position " << i + 1 << ": " << arr[i] << endl; } for(int i=0;i<5;i++) { for(int j=i+1;j<5;j++) { if(arr[i]>arr[j]) { int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } cout << endl; for(int i = 0; i < 5; i++) { cout << "Outputting sorted array info at position " << i + 1 << ": " << arr[i] << endl; } return 0; }
0 likes • 5 views
#include <iostream> using namespace std; /* Function: get_coeff Parameters: double& coeff, int pos passed from bb_4ac Return: type is void so no return, but does ask for user to input data that establishes what a b and c are. */ void get_coeff(double& coeff, int pos) { char position; if(pos == 1) { position = 'a'; } else if(pos == 2) { //a simple system to determine what coefficient the program is asking for. position = 'b'; } else { position = 'c'; } cout << "Enter the co-efficient " << position << ":"; //prompt to input coeff coeff = 5; //input coeff } /* Function: bb_4ac Parameters: no parameters passed from main, but 3 params established in function, double a, b, c. Return: b * b - 4 * a * c */ double bb_4ac() { double a, b, c; //coefficients of a quadratic equation get_coeff(a, 1); // call function 1st time get_coeff(b, 2); // call function 2nd time get_coeff(c, 3); // call function 3rd time return b * b - 4 * a * c; //return b * b - 4 * a * c } int main() { cout << "Function to calculate the discriminant of the equation. . . " << endl; double determinate = bb_4ac(); //assign double determinate to bb_4ac function cout << "The discriminant for given values is: " << determinate << endl; //output the determinate! }