Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4.  
  5. int main (void) {
  6.  
  7.     // Loop Variables
  8.     int i;
  9.     int j;
  10.     int k;
  11.     int l;
  12.    
  13.     // Number (String) Inputs
  14.     char str1[100];
  15.     char str2[100];
  16.     char str3[100];
  17.     char str4[100];
  18.    
  19.     // Integer Outputs
  20.     int num1 = 0;
  21.     int num2 = 0;
  22.     int num3 = 0;
  23.     int num4 = 0;
  24.    
  25.     printf("Please enter the first number: \n");
  26.     fgets(str1, 100, stdin);
  27.    
  28.     printf("Please enter the second number: \n");
  29.     fgets(str2, 100, stdin);
  30.    
  31.     printf("Please enter the third number: \n");
  32.     fgets(str3, 100, stdin);
  33.    
  34.     printf("Please enter the fourth number: \n");
  35.     fgets(str4, 100, stdin);
  36.    
  37.     //Length of each number
  38.     int stringLength1 = strlen(str1) - 1; // -1 Removes ending character
  39.     int stringLength2 = strlen(str2) - 1;
  40.     int stringLength3 = strlen(str3) - 1;
  41.     int stringLength4 = strlen(str4) - 1;
  42.    
  43.     //Power Counts
  44.     int powCount1 = stringLength1; // Keeps track of what integer our power is on
  45.     int powCount2 = stringLength2;
  46.     int powCount3 = stringLength3;
  47.     int powCount4 = stringLength4;
  48.    
  49.     //10 raised to power count
  50.     double pow1;
  51.     double pow2;
  52.     double pow3;
  53.     double pow4;
  54.    
  55.    
  56.     for (i=0; i <= stringLength1 -1; i++) { // Not 100% sure why I put a -1 here, but it worked.
  57.         powCount1--;
  58.         printf("Here is the power that the number is going to get: %d \n", powCount1);
  59.         if(powCount1 != 0){
  60.             pow1 = pow(10, powCount1);
  61.         }
  62.         else {
  63.             pow1 = 1;
  64.         }
  65.         printf("Here is the number before power: %d \n", (str1[i] - 48));
  66.         num1 += ((str1[i] - 48) * pow1);
  67.         printf("Here is the total sum: %d \n", num1);
  68.     }
  69.     for (j=0; j < stringLength2; j++) {
  70.         powCount2--;
  71.         printf("Here is the power that the number is going to get: %d \n", powCount2);
  72.         if(powCount2 != 0){
  73.             pow2 = pow(10, powCount2);
  74.         }
  75.         else {
  76.             pow2 = 1;
  77.         }
  78.         printf("Here is the number before power: %d \n", (str2[j] - 48));
  79.         num2 += ((str2[j] - 48) * pow2);
  80.         printf("Here is the total sum: %d \n", num2);
  81.     }
  82.     for (k=0; k < stringLength3; k++) {
  83.         powCount3--;
  84.         printf("Here is the power that the number is going to get: %d \n", powCount3);
  85.         if(powCount3 != 0){
  86.             pow3 = pow(10, powCount3);
  87.         }
  88.         else {
  89.             pow3 = 1;
  90.         }
  91.         printf("Here is the number before power: %d \n", (str3[k] - 48));
  92.         num3 += ((str3[k] - 48) * pow3);
  93.         printf("Here is the total sum: %d \n", num3);
  94.     }
  95.     for (l=0; l < stringLength4; l++) {
  96.         powCount4--;
  97.         printf("Here is the power that the number is going to get: %d \n", powCount4);
  98.         if(powCount4 != 0){
  99.             pow4 = pow(10, powCount4);
  100.         }
  101.         else {
  102.             pow4 = 1;
  103.         }
  104.         printf("Here is the number before power: %d \n", (str4[l] - 48));
  105.         num4 += ((str4[l] - 48) * pow4);
  106.         printf("Here is the total sum: %d \n", num4);
  107.     }
  108.  
  109.     printf("Here is the string: %d \n", num1);
  110.    
  111.     printf("Here is the string: %d \n", num2);
  112.    
  113.     printf("Here is the string: %d \n", num3);
  114.    
  115.     printf("Here is the string: %d \n", num4);
  116.    
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement