the programe woks now :)
now i`m trying that the programe could utput the numbers with 2,3,4 etc. digits (it sould wokr like this, "how many digits d you want to uotput") ,
i cant figure out the formule that would work.

>why is it bad??
Because it uses a call to the OS to run the program "Pause". Doing this is a waste of resources, when it's just as easy to use getchar() or cin.get().

Secondly, system("pause") is not portable, so you will need to change the code if you want it to run properly on a *nix system.

So system("pause") isn't really that bad, except it's a poor choice when there are far better alternatives.

> now i`m trying that the programe could utput the numbers with 2,3,4 etc. digits
Hmm... I think I know what you mean. Just raise 10 to the nth power, where n is the number that the user enters.

Then modify your loop so that it keeps going until the result is larger than the value you obtained previoulsy (10 raised to n).

No good reason, just a quick and lazy answer

Salem, and lazy....hmm ;)

> now i`m trying that the programe could utput the numbers with 2,3,4 etc. digits
Hmm... I think I know what you mean. Just raise 10 to the nth power, where n is the number that the user enters.

Then modify your loop so that it keeps going until the result is larger than the value you obtained previoulsy (10 raised to n).

modify my loop?... hm...

>modify my loop?
So it looks sort of like this (pseudocode):

set n to number of digits

loop until 'I' is larger than (10 ^ n)
    do your stuff here
end loop

thats the roblem i cant make a formule or something, norhing works .. the bad thing is that i dont know why..

>thats the roblem i cant make a formule or something
Yes you can. You just need to use functions in place of certain operators. For example, the ^ symbol can be replaced by pow().

#include <cmath>
pow(10, n);    // 10 ^ n

oh, thats the thing with "pow" didnt know. so it will show something like this? <<pow(10,654) ... 65>> ?

>pow(10,654)
If you wanted to to have '10', followed by 653 0s after it, (or in more mathematical terms, 10 ^ 653), yes that would be correct.

oh :) i get it now.
hm.. now whats left it to write that it would uotput onely with 2.3.... diigit numbers... hm...

this sfould work and its in C which u needed....

#include<stdio.h>
main()
{
 int a[128];
 int fN;
 int n,i;
 int a[0]=1;
 int a[1]=1;
printf("How many nos. do u want to add:\n");
scanf("%d",&i);
printf("How many no. of digits u want to output:\n");
scanf("%d",&n);
for(fN=2;fN<=i;fN++)
{
 a[fN]=a[fN-1]+a[fN-2];
 if((a[fN]>(pow(10,n-1)-1))&&(a[fN<(pow(10,n)))
  printf("%d\n",a[fN));
}
getch();
}

you sure it works ? somehow i cant make it work....

well, i modified my programe and it turend out ike this :

#include <stdio.h>
#include <math.h>
int main() {                            
    char buff[BUFSIZ];
    int x1[1000] = {0};
    int x2[1000] = {0};
    int x3[1000] = {0};
    int i, a, b, c, x, n, v, ilgis;
    
    x1[0] = 1;
    x2[0] = 1;

    printf("Enter the value for n:");   
   
    if (fgets(buff, sizeof buff, stdin) != NULL) {
        
        if (sscanf(buff, "%d", &n) == 1) {
       
     printf("Enter the value for ilgis:");
                   
            v=0;     
            x1[i]=0;
            x2[i]=1;
            while (ilgis <= n){
               for (i=0; i <= 1000; i++){
                   if ((x1[i] ==0) & (x2[i] ==0) & (v ==0)){
                              ilgis = i;
                   }
                   if ((x1[i]+x2[i]+v) < 10){
                      x3[i]=x1[i]+x2[i]+v;
                      v=0;
                   }
                   else{
                      x3[i]=(x1[i]+x2[i]+v) %10;
                      v = 1;
                   }                        
               }
               if (ilgis == n) printf("%d", x3[])
            }
               
        }
    }
    getchar();
    return 0;
}

but i cant finish it. could someone help finish it so that it would work? and show how it sould look, please?

>this sfould work
How about you try it out with your compiler before posting it here? You might find it may not actually "sfould work".

>but i cant finish it. could someone help finish it so that it would work? and show how it sould look, please?
Hm? I'm completely confused by what you're trying to do. From the previous posts, I assumed you were trying to write a program that would:

  • Ask how many digits the fibonacci number should have
  • Generate a list of numbers up until the largest fibonacci number that is within the digit limit that the user entered

Perhaps I'm just not understanding what you're trying to do. In any case, please make that clearer.

And by the way, you can't print out entire arrays like this:

if (ilgis == n) printf("%d", x3[])[

You'll have to loop through each digit and use the index variable as an array subscript.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.