| | |
Numbers in Turbo C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2004
Posts: 6
Reputation:
Solved Threads: 0
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.
(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.
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?
Very simple.
I could not really understand your first question.
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?
C++ Syntax (Toggle Plain Text)
while(num > 0) { num = num/10; no_of_digits++ }
Very simple.
I could not really understand your first question.
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?
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?
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);
}
#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);
}
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.
)
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.
) C++ Syntax (Toggle Plain Text)
long square(int n) { if(n=1) return 4; else return ( pow(2*n,2) + square(n-1) ); } void main() { int input = 0; cout<<"Please enter an integer: "; cin>>input; cout<<"The result is "<<square(input)<<endl; }
![]() |
Other Threads in the C++ Forum
- Previous Thread: Error checking help...
- Next Thread: How is *x the same as x[]?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






!!