473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

give explanation of given 2 lines: sum=sum+(i*rem); i=i*10;

This is my assignment but I don't know where to start and I need your help... give explanation of given 2 lines sum=sum+(i*rem); i=i*10;
Nov 18 '12 #1
5 2536
donbock
2,426 Expert 2GB
It is one thing to explain what two lines do; it is another entirely to explain what they are trying to accomplish. You need more context to understand the intent of these lines.
Do you have more context for these two lines?
Nov 18 '12 #2
whodgson
542 512MB
Expand|Select|Wrap|Line Numbers
  1. sum=sum+(i*rem); 
  2. i=i*10;
Expand|Select|Wrap|Line Numbers
  1. int a=15;
  2. int b=3;
  3. int rem=a/b;//rem=3
  4. int sum=0;
  5. sum=sum+(i*rem);//is same as sum+=i*rem
  6. for(int i=0;i<3;i++){
  7.     i=i*10;//same as i*=10
  8.     cout<<i;//prints 0 10 20}
  9. for(int i=0;i<3;i++){    
  10.     sum+=i*rem;
  11.     cout<<sum;//prints 0 3 9}
  12. }
Nov 28 '12 #3
donbock
2,426 Expert 2GB
I'm sorry - I don't understand what this program is trying to do. Can you tell us?

Line 5 of the larger snippet doesn't belong: it uses i before that variable has been declared or initialized.

I would have guessed that the variable name rem was short for remainder, but line 3 assigns the quotient of a/b to rem.

The loop in lines 6-8 has nothing to do with a, b, or rem. It just prints the values of 0*10, 1*10, and 2*10. The point of this escapes me.

Knowing that rem is 3, the loop in lines 9-12 prints the values of 0+(0*3), 0+(0*3)+(1*3), and 0+(0*3)+(1*3)+(2*3). The point of this escapes me.
Nov 28 '12 #4
PreethiGowri
126 64KB
i=i*10
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. int main(){
  3. int i=2;
  4. printf("before any operation i = %d",i); // o/p i=2
  5. i=i*10;
  6. printf("after above operation operation i = %d",i);// o/p i=20
  7. }
  8.  
sum = sum+(i*rem);
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include<stdio.h>
  3. int main(){
  4. int i=2,sum=0,rem,a=6,b=5; 
  5. printf("before any operation i = %d",i);
  6. i=i*10;
  7. printf("after above operation operation i = %d",i);
  8. rem = a%b; //a%b yields reminder
  9. sum = sum +(i*rem); // sum = 0+(20 * 1)
  10. printf("after above operation operation sum = %d",sum);}
  11.  
Nov 28 '12 #5
donbock
2,426 Expert 2GB
This is just a wild guess. Perhaps the intent is to demonstrate how the integer division and multiplication instructions (/ and % and *) work in mathematics as well as in C. I'm not sure how to relate this to the original question.

Expand|Select|Wrap|Line Numbers
  1. void divideDemo(int dividend, int division);
  2. int multiplyDemo(int multiplier, int multiplicand);
  3.  
  4. void divideDemo(int dividend, int divisor) {
  5.    int quotient, remainder, checkValue;
  6.    quotient = dividend / divisor;
  7.    remainder = dividend % divisor;
  8.    printf("divide: %d divided by %d = %d remainder %d\n",
  9.           dividend, divisor, quotient, remainder);
  10.    checkValue = multiplyDemo(quotient,divisor) + remainder;
  11.    printf("divide: ((%d * %d) + %d = %d) == %d\n",
  12.           quotient, divisor, remainder, checkValue, dividend);
  13.    }
  14.  
  15. int multiplyDemo(int multiplier, int multiplicand)
  16.    int i, polarity, product;
  17.    polarity = 1;
  18.    if (multiplier < 0) {
  19.       polarity = -polarity;
  20.       multiplier = -multiplier;
  21.       }
  22.    if (multiplicand < 0) {
  23.       polarity = -polarity;
  24.       multiplicand = -multiplicand;
  25.       }
  26.    product = 0;
  27.    for(i=0; i<multiplicand, i++)
  28.       product += multiplier;
  29.    if (polarity < 0)
  30.       product = -product;
  31.    printf("multiply: %d * %d = %d\n",
  32.           multiplier, multiplicand, product);
  33.    return product;
  34.    }
  35.  
Nov 28 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: justme | last post by:
Dears I have created the following page to display my data <head> <style type="text/css"> body, td, th, h1, h2 {font-family: sans-serif;} body, td, th {font-size: 100%;} a:link {...
47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
3
by: Mahmood Ahmad | last post by:
Hello, I have written a program that reads three types of records, validates them acording to certain requirements and writes the valid records into a binary file. The invalid records are...
41
by: Mark R. Dawson | last post by:
I have never used a goto statement in my code, one of the first things I was told in my software classes a number of years ago was "goto statements are evil and lead to spagetti code - do not use...
14
by: Drew | last post by:
Hi All: I know I am missing something easy but I can't find the problem! I have a program which reads an integer as input. The output of the program should be the sum of all the digits in the...
10
by: evolutionccf | last post by:
How do you calculate the sum of the Integers is between 0 to 1000? Examples integer is 945: the sum of all digits is 18. This is my assignment but I don't know where to start and I need your...
14
by: rohitkumar | last post by:
this is my code to calculate the sum of digits in a number for eg. 432567 sum =4+3+2+5+6+7=27 i 'm using turboc++ compiler from borland and i 'm runing my program on DOS. ...
3
kirubagari
by: kirubagari | last post by:
I would like to duplicate the numbers from from excel sheet 1 to excel sheet 2.Kindly help me on this.Sometime its unable to duplicate.. Sub Duplicate Dim oDoc As Object, oSheet As Object,...
1
kirubagari
by: kirubagari | last post by:
Hai experts, How to duplicate the data from 1 excel sheet to another excel sheet 2. Lets say Name Voucher Value Voucher Number lee 300.00 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.