How do you make addition and multi using "While Loop" in Turbo C?

How do you make multiplication using “While Loop” in Turbo C? I was able to do this: The output should be like this when I run Turbo C:

12345 1234 123 12 1

Using this CODE:

y=5; while(y>=1) { x=1; while(x<=y) { printf(“%d,”x); x++; } printf(“\n”); y–; }

and a multiplication table: 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25

using this CODE:

y=1; while(y<=5) { x=1; while(x<=5) { printf(“%d”,x*y); x++; } printf(“\n”); y++ }

  1. But I couldnt figure this out… and my head is aching already! T__T need help! couldn’t think of anything.

This should be the output. When You run the Turbo C it should show this:

Enter a number: 4 (for example)

The sum is: 10

1234 = 1+2 (equals 3) 3+3 (equals 6) 6+4 (equals 10) or 1+2+3+4=10 1 2 3 4 = 10

Next sem will be my programming subject… And its scary because the prof or instructor wont teach you how to do it… you have to discover it by either asking a friends… let someone teach you… or you figure it on your own… T__T

pls help…

Answer #1

well I don’t know much Turbo C sry, my programming classes where in Java. Try to give you some help here any ways. if I understand the second questions write you need a while loop to add up the numbers (in your example) 1 thru 4?

Ok so if thats the case im going to write this out in kinda sudo code.

you get the input from the user

x = input

set y = x

while (x > 0) { x-1 y = y+x } print y

so that should give you y = 4 before the first loop,

then on the first loop y= 4+3 = 7. so y = 7, x = 3.

Second loop y = 7+2 = 9, x =2

third loop y = 9 + 1 = 10, x=1

fourth loop y = 10 + 0, x=0

Jumps out of while loop. Prints your answer.

that help??

Answer #2

write a program to convert given amount in to coins?

More Like This
Ask an advisor one-on-one!
Advisor

Easy To Use Solutions

Online Marketing, Digital Advertising, E-commerce

Advisor

WebRex Multi Announcement Bar

E-commerce Solutions, Marketing Tools, Web Development

Advisor

Spring Former - Spring Making...

Manufacturing Machinery, Industrial Equipment, Automation Technology

Advisor

Used Robots

used robots, used robots for sale, second hand robots, used industrial robots for sale

Advisor

Think Make Push

Video production, Content creation, Digital marketing