wrtie a C program using retrun function which gives the following output: 1,4,9,16,25
C program plzz how?
the trick is simply to find the pattern in the numbers...
it's adding by odd numbers, increasing the number each time.
3,5,7,9,etc...
1+3=4
4+5=9
9+7=16
Reply:It's a simple logic...
The series you got is a square series...
1*1, 2*2, 3*3, 4*4, 5*5, and so on...
So, all you gotta do is have an incremental counter and multiply it with itself and then return the value each time...
say for eg,
int series;
for(int i=1; i%26lt;=n; i++)
{
series=i*i;
printf("%d";series);
}
where n is the number of items to be displayed...
Reply:It looks like a square of x to me, where x : 1 %26lt;= x %26lt;= 5
for (int x = 1; x %26lt;=5; x++)
{
int a = x * x;
printf("%d\n",a);
}
Hope that helps :)
Reply:int n = 1, adder = 3, max = 1000;
void printseries()
{
while (1)
{
cout%26lt;%26lt;n;
n += adder;
adder += 2;
if (n + adder %26lt; max)
{
cout%26lt;%26lt;", ";
}
}
return;
}
Try this program... (^^,)
http://ronaldborla.blogsome.com/
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment