Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/ #include<stdio.h> int main() { long long int n, first = 0, second = 1, next, c; int i,j; scanf("%d", &j); for(i=1; i<=j; i++, first = 0, second = 1) { scanf("%lld",&n); n=n+1; for ( c = 0 ; c < n ; c++ ) { if (c <= 1) next = c; else { next = first + second; first = second; second = next; } } printf("Fib(%lld) = %lld\n",n-1,next); } return 0; }
Problem no 1145 , Still trying --But only show me presentation error ,pls help me
ReplyDelete#include
ReplyDeletevoid main()
{
int i,j=0,x,y;
scanf("%d%d",&x,&y);
for(i=1;i<=y;i++)
{
j++;
if(j==x)
{
j=0;
printf("%d\n",i);
}
else
printf("%d ",i);
}
}
#include
Deletevoid main()
{
int i,j=0,x,y;
scanf("%d%d",&x,&y);
for(i=1;i<=y;i++)
{
j++;
if(j==x)
{
j=0;
printf("%d\n",i);
}
else
printf("%d ",i);
}
}
for god sake include header file name or how do you expect the program to run?
Delete#include
ReplyDeleteusing namespace std;
int fibo(int n);
int main (){
unsigned int n,k;
int i,j,t;
cin>>t;
for(j=1; j<=t; j++){
cin>>n;
for(i=0; i<=n; i++)
{
k=fibo(i);
}
cout<<"Fib("<<n<<") = "<<k<<"\n";
}
return 0;
}
int fibo(int n){
if(n==0){
return n;
}
else if(n==1 || n==2){
return 1;
}
else
return fibo(n-1)+fibo(n-2);
}
what's wrong about this code??
#include
ReplyDeleteint main()
{
long long int N[60],pos;
int i,j,n;
N[0]=0;
N[1]=1;
for(i=2;i<60;i++){
N[i]=N[i-1]+N[i-2];
}
scanf("%d",&n);
for(j=1;j<=n;j++){
scanf("%lld",&pos);
printf("Fib(%lld) = %lld\n",pos,N[pos]);
}
return 0;
}
your problem is error to compile
Delete#include
ReplyDelete#include
using namespace std;
int main()
{
int n, t;
long long fst, snd, next;
cin >> t;
while( t-- )
{
cin >> n;
fst = 0;
snd = 1;
if( n <= 1) next = n;
else {
for(int i=2; i<=n; i++)
{
next = fst+snd;
fst = snd;
snd = next;
}
}
printf("Fib(%d) = %lld\n", n, next);
}
}
#include
ReplyDeleteint main()
{
int i,j, n, x,a=0, b=1, c;
long long int arr[61];
scanf("%d", &n);
arr[0]=0;
arr[1]=1;
for(i=2; i<60; i++)
{
c=a+b;
a=b;
b=c;
arr[i]=c;
}
for(i=1; i<=n; i++)
{
scanf("%d", &x);
printf("Fib(%d) = %lld\n", x, arr[x]);
}
return 0;
}
This submission show 5% error
ReplyDelete#include
ReplyDeleteint main(){
int T,i,X,first=0,second=1,sum;
long long int N[61];
N[0]= first;
N[1]= second;
for(i=2;i<=60;i++){
sum = first + second;
first = second;
second = sum;
N[i]=sum;
}
scanf("%d",&T);
for(i=0;i<T;i++){
scanf("%d",&X);
printf("Fib(%d) = %lld\n",X,N[X]);
}
return 0;
}
@ Mamun sir why my above code submission show 5% error??
ReplyDelete