Numbers in Turbo C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2004
Posts: 6
Reputation: Tejas is an unknown quantity at this point 
Solved Threads: 0
Tejas Tejas is offline Offline
Newbie Poster

Numbers in Turbo C++

 
1
  #1
Jun 13th, 2004
I got a question which i cannot do. Pls help me.
(This is using Turbo C++ IDE).
The questions are:

Q1. WAP to print the sum of the following series:
2(square) + {2(square) + 4(square)} + {2(square) + 4(square) + 6(square)} .............. till N terms.

Q2. WAP to find out the no. of digits in the given number.
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Numbers in Turbo C++

 
1
  #2
Jun 14th, 2004
Greetings.
Err, sorry for my ignorance, but what does WAP mean?
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Numbers in Turbo C++

 
0
  #3
Jun 14th, 2004
WAP stands for Write A Program I belive.Teachers commonly use that when they write on a board.

About you second question:
It easy enough if you think logically.How do you find the number of digits in a number,by counting ofcourse.Now how do you get a computer to count?
That can be done by removing digits one by one and that can be done by dividing the number by ten.Simple eh?
  1. while(num > 0)
  2. {
  3. num = num/10;
  4. no_of_digits++
  5. }

Very simple.

I could not really understand your first question.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Numbers in Turbo C++

 
0
  #4
Jun 14th, 2004
Greetings.
I see. I often see my lecturers using shortforms like "hth" & etc. without knowing what it means.

Your suggestion to the second problem was cool.
How about converting the number to String and then using the string length function?

About the first problem. May I rephrase what you were trying to mean.
Let's say if I input n=1, must I get 2^2 = 4 as the result?
Similarly, if I input n=2, the result must be 2^2 + 4^2 = 20.
Is this what you want?
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 6
Reputation: Tejas is an unknown quantity at this point 
Solved Threads: 0
Tejas Tejas is offline Offline
Newbie Poster

Re: Numbers in Turbo C++

 
0
  #5
Jun 14th, 2004
For those who didnt understand the first part of the problem, it simply says:
It sholud print the following series:
2^ + [ 2^ + 4^ ] + [ 2^ + 4^ + 6^ ] + [ 2^ + 4^ + 6^ + 8^ ] and so on.

By the way, WAP is a short form for write a prog. !!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 6
Reputation: Tejas is an unknown quantity at this point 
Solved Threads: 0
Tejas Tejas is offline Offline
Newbie Poster

Re: Numbers in Turbo C++

 
0
  #6
Jun 14th, 2004
I think i have replied to ur doubt.
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Numbers in Turbo C++

 
0
  #7
Jun 16th, 2004
Greetings.
Errr, I still don't really get what you mean.
However, could you check if it's something like this?
int square(int n)
{
int result=0;
for(int i=1; i<=n; i++)
{
result += pow(2*i, 2);
}
return result;
}
where in this case, you have to prompt the user for an input for "n".
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: Numbers in Turbo C++

 
0
  #8
Jun 17th, 2004
Red_evolve... i've written a version for Q1 myself and it's pretty similar to yours (mine's a program---in my opinion you understood pretty good)

#include <stdio.h>
#include <conio.h>
long elemget(int n)
{
long val=0;
for (int j=1;j<=n;j++)
val+=(j*2)*(j*2);
return val;
}
void main()
{
clrscr();
int n;
printf("Numarul de termeni:");scanf("%i",&n);
unsigned long sum=0;
for (int i=1;i<n;i++)
sum+=elemget(i);
printf("Suma obtinuta este:%i",sum);
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 2
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Numbers in Turbo C++

 
1
  #9
Jun 17th, 2004
by the way I am also interested in computing this series, but i want to do it using a recursive function. Can anyone help me out?
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Numbers in Turbo C++

 
1
  #10
Jun 17th, 2004
Greetings.
To Fili:- Hey, thanks.
By the way, what language are you using?
Does "Numarul de termeni" mean "Please input something".
LOL. Just a wild guess.

To Asif_NSU:- I am not sure whether this will work as I've not debugged it.
(This is not a complete program though. )

  1. long square(int n)
  2. {
  3. if(n=1)
  4. return 4;
  5. else
  6. return ( pow(2*n,2) + square(n-1) );
  7. }
  8.  
  9. void main()
  10. {
  11. int input = 0;
  12. cout<<"Please enter an integer: ";
  13. cin>>input;
  14. cout<<"The result is "<<square(input)<<endl;
  15. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC