Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- int main (void) {
- // Loop Variables
- int i;
- int j;
- int k;
- int l;
- // Number (String) Inputs
- char str1[100];
- char str2[100];
- char str3[100];
- char str4[100];
- // Integer Outputs
- int num1 = 0;
- int num2 = 0;
- int num3 = 0;
- int num4 = 0;
- printf("Please enter the first number: \n");
- fgets(str1, 100, stdin);
- printf("Please enter the second number: \n");
- fgets(str2, 100, stdin);
- printf("Please enter the third number: \n");
- fgets(str3, 100, stdin);
- printf("Please enter the fourth number: \n");
- fgets(str4, 100, stdin);
- //Length of each number
- int stringLength1 = strlen(str1) - 1; // -1 Removes ending character
- int stringLength2 = strlen(str2) - 1;
- int stringLength3 = strlen(str3) - 1;
- int stringLength4 = strlen(str4) - 1;
- //Power Counts
- int powCount1 = stringLength1; // Keeps track of what integer our power is on
- int powCount2 = stringLength2;
- int powCount3 = stringLength3;
- int powCount4 = stringLength4;
- //10 raised to power count
- double pow1;
- double pow2;
- double pow3;
- double pow4;
- for (i=0; i <= stringLength1 -1; i++) { // Not 100% sure why I put a -1 here, but it worked.
- powCount1--;
- printf("Here is the power that the number is going to get: %d \n", powCount1);
- if(powCount1 != 0){
- pow1 = pow(10, powCount1);
- }
- else {
- pow1 = 1;
- }
- printf("Here is the number before power: %d \n", (str1[i] - 48));
- num1 += ((str1[i] - 48) * pow1);
- printf("Here is the total sum: %d \n", num1);
- }
- for (j=0; j < stringLength2; j++) {
- powCount2--;
- printf("Here is the power that the number is going to get: %d \n", powCount2);
- if(powCount2 != 0){
- pow2 = pow(10, powCount2);
- }
- else {
- pow2 = 1;
- }
- printf("Here is the number before power: %d \n", (str2[j] - 48));
- num2 += ((str2[j] - 48) * pow2);
- printf("Here is the total sum: %d \n", num2);
- }
- for (k=0; k < stringLength3; k++) {
- powCount3--;
- printf("Here is the power that the number is going to get: %d \n", powCount3);
- if(powCount3 != 0){
- pow3 = pow(10, powCount3);
- }
- else {
- pow3 = 1;
- }
- printf("Here is the number before power: %d \n", (str3[k] - 48));
- num3 += ((str3[k] - 48) * pow3);
- printf("Here is the total sum: %d \n", num3);
- }
- for (l=0; l < stringLength4; l++) {
- powCount4--;
- printf("Here is the power that the number is going to get: %d \n", powCount4);
- if(powCount4 != 0){
- pow4 = pow(10, powCount4);
- }
- else {
- pow4 = 1;
- }
- printf("Here is the number before power: %d \n", (str4[l] - 48));
- num4 += ((str4[l] - 48) * pow4);
- printf("Here is the total sum: %d \n", num4);
- }
- printf("Here is the string: %d \n", num1);
- printf("Here is the string: %d \n", num2);
- printf("Here is the string: %d \n", num3);
- printf("Here is the string: %d \n", num4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement