C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf

Plese Correct the line where "While" starts.........By

while(k<=r)

Using For loop The programa is..... void main() { int i=0,j=1,k,r,f; clrscr(); printf("Enter the number range:"); scanf("%d",&r); printf("\nFIBONACCI SERIES: "); printf("%d %d",i,j); for (k = 2; k <= r; k++) { f = i + j; i = j; j = f; printf(" %d",j); } getch(); }

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!

void main() { int i,a=0,b=1,c=0,n; clrscr(); printf("\n Enter the lenth of the sequence: "); scanf("%d",&n); if(n==0) { printf("\nPlease enter more than 0 and try again.");

}

else { if(n==1) { printf("\n The fibonacci serice of given length is: "); printf("\n\n %d",a); // getch(); } else if(n==2) { printf("\n The fibonacci serice of given length is: "); printf("\n\n %d\t%d",a,b); } else { printf("\n The fibonacci serice of given length is: "); printf("\n\n %d\t%d",a,b); for(i=3;i<=n;i++) { c=a+b; a=b; b=c; printf("\t%d",c); } } } getch(); }

#include #include #include void main() { int n,i,c; int a=0; int b=1; clrscr(); printf("Enter the number of terms="); scanf("%d",&n); printf("Fibonacci Series"); printf("\n%d\n%d"a,b); for (i=3;i<=n;i++) { c=a=b; a=b; b=c; printf("\n%d",c); } getch(); }

#include main() { int a = 0, b = 1, c; printf("Enter range"); scanf("%d\n",&range); if(range) printf("%d ",a); while(--range) { c = a + b; a = b; b = c; printf("%d ",a); } }

Questions : - Sir please help out on this.? 1.Print the following pattern: A B C D E D C B A A B C D C B A A B C B A A B A A

2. Generate Fibonacci series from 1 to 100 and print it in reverse order.

3. Write an efficient program to reverse characters of each word in a file and write an output file in the same format with all words reversed.

4. Explain the order of complexity in Big-Oh notation, and time taken to process?

5. Work out an algorithm to predict the best times to buy and sell a stock over a 60-day period. Use a suitable data structure so that the “n” th element is the price of the stock on day “n”. ex. 1st element is stock price on day one, 60th element is stock price on day 60.Assume that you start out with 10,000 INR, and value of stock on day 1 is INR 10. Make up any data that you wish for the stock prices. Please provide the input dataset and a working program.

here is a simplest way /* Fibonacci Series c language */ #include #include void main() { int f=0,s=1,ne=0,n,i; clrscr(); printf("Enter any integer value\n"); scanf("%d",&n); printf("%d",f); for (i=0;i<n;i++) { ne=f+s; printf("+%d",ne); s=f; f=ne; } getch(); }

/* Fibonacci Series c language */ #include #include void main() { int n1=0,n2=1,n3=0,n,i; clrscr(); printf("Enter any integer value\n"); scanf("%d",&n); for (i=0;i<n;i++) { n3=n1+n2; printf("+%d",n3); n1=n2; n2=n3; } getch(); }

Sam is a 6th grader, who's got an assignment to check it a number belongs to the Fibonacci series or not. But apparently his friends have called him out to play a game of Cricket. If Sam writes down the series and verifies it all, if would take too long and would probably miss his match. Can you help him solve his problem through a program ?

Input The first line of the input would contain the number of test cases T. Followed by T list of numbers.

Output For a particular test case T, if the number is present in the Fibonacci series, print Y followed by the position of the number in the Fibonacci series. Else print N followed by NOT PRESENT

(Since 1 is present twice in the series, print both the occurrences)

Write a recursive function fast_fib to compute a pair of Fibonacci numbers, F( n + 1) and F( n ). Function fast_fib should make only one recursive call. Algorithm if n is 1 The pair to send back is 1, 1. else Use fast_fib to compute F( n ) and F( n − 1). The pair to send back is [F( n ) + F( n − 1)], F( n ).

Plese Correct the line where "While" starts.........By

ReplyDeletewhile(k<=r)

Using For loop The programa is.....

void main()

{

int i=0,j=1,k,r,f;

clrscr();

printf("Enter the number range:");

scanf("%d",&r);

printf("\nFIBONACCI SERIES: ");

printf("%d %d",i,j);

for (k = 2; k <= r; k++)

{

f = i + j;

i = j;

j = f;

printf(" %d",j);

}

getch();

}

"Thanks everybody for the program"

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!

ReplyDeleteThanks you very much

ReplyDeletevoid main()

ReplyDelete{

int i,a=0,b=1,c=0,n;

clrscr();

printf("\n Enter the lenth of the sequence: ");

scanf("%d",&n);

if(n==0)

{

printf("\nPlease enter more than 0 and try again.");

}

else

{

if(n==1)

{

printf("\n The fibonacci serice of given length is: ");

printf("\n\n %d",a);

// getch();

}

else if(n==2)

{

printf("\n The fibonacci serice of given length is: ");

printf("\n\n %d\t%d",a,b);

}

else

{

printf("\n The fibonacci serice of given length is: ");

printf("\n\n %d\t%d",a,b);

for(i=3;i<=n;i++)

{

c=a+b;

a=b;

b=c;

printf("\t%d",c);

}

}

}

getch();

}

#include

ReplyDelete#include

#include

void main()

{

int n,i,c;

int a=0;

int b=1;

clrscr();

printf("Enter the number of terms=");

scanf("%d",&n);

printf("Fibonacci Series");

printf("\n%d\n%d"a,b);

for (i=3;i<=n;i++)

{

c=a=b;

a=b;

b=c;

printf("\n%d",c);

}

getch();

}

thanks a lot this is great

ReplyDeletewrite a c program to implement the single shorted path problem.

ReplyDeletethank you.

Thank u very much for Fibonacci series post.

ReplyDeleteThank u very much for Fibonacci series post.but i also need wap Fibonacci series using iterative function

ReplyDeleteand cosine series

ReplyDeleteThanks its helped me.

ReplyDelete#include

ReplyDelete#include

void main()

{

int i=0,j=1,k,n,count=1;

printf("No. of elements");

scanf("%d",&n);

while(count<=n)

{

printf("%d\t",i);

k=i;

i=i+j;

j=k;

count++;

}

getch();

}

REPLY

what will b the output

ReplyDeletechar * p="Hello";

?=(*p)*;

A simple way to print fibonacci numbers.

ReplyDelete#include

main()

{

int a = 0, b = 1, c;

printf("Enter range");

scanf("%d\n",&range);

if(range)

printf("%d ",a);

while(--range)

{

c = a + b;

a = b;

b = c;

printf("%d ",a);

}

}

idea ok. but not working properly for range=0;

Deletei corrected it.

#include

#include

main()

{

int a = 0, b = 1, c=0, range=0;

clrscr();

printf("Enter range");

scanf("%d",&range);

printf("range %d", range);

getch();

if(range)

while(--range)

{

c = a + b;

a = b;

b = c;

printf("\n%d ",a);

}

else

printf("%d",a);

getch();

return (0);

}

#include

ReplyDelete#include

void main()

{

clrscr();

int a=0,b=1,c=0,n;

cout<<"Enter the number of terms you wanna see: ";

cin>>n;

cout<<a<<" "<<b<<" ";

for(int i=1;i<=n-2;i++)

{

c=a+b;

a=b;

b=c;

cout<<c<<" ";

}

getch();

}

can you please solve this??

ReplyDeleteWrite a program to calculate the sum of former 40 numbers of series 2/1, 3/2, 5/3, 8/5, 13/8, 21/13,……

How to write a program that will display the sum of the given range.

ReplyDeleteSample output: Enter number of range to be added: 5

The sum of given range is: 15

Everything is very open with a clear description of the issues. Many thanks for sharing!

ReplyDeleteGreetings from Torrent

Questions : - Sir please help out on this.?

ReplyDelete1.Print the following pattern:

A B C D E D C B A

A B C D C B A

A B C B A

A B A

A

2. Generate Fibonacci series from 1 to 100 and print it in reverse order.

3. Write an efficient program to reverse characters of each word in a file and write an output file in the same format with all words reversed.

4. Explain the order of complexity in Big-Oh notation, and time taken to process?

5. Work out an algorithm to predict the best times to buy and sell a stock over a 60-day period. Use a suitable data structure so that the “n” th element is the price of the stock on day “n”.

ex. 1st element is stock price on day one, 60th element is stock price on day 60.Assume that you start out with 10,000 INR, and value of stock on day 1 is INR 10. Make up any data that you wish for the stock prices. Please provide the input dataset and a working program.

Ans 2:

Delete#include

void main()

{

int num=100,i=0,j=1,k=0,n=0;

i=-1;

k=i+j;

//FINDING LAST ELEMENT

while(1)

{

k=i+j;

if(k>num)

break;

i=j;

j=k;

}

//PRINTING OUTPUT

while(j>=1)

{

k=j-i;

printf("%d ",j);

j=i;

i=k;

}

//ADDING LAST 0

printf("0\n");

}

here is a simplest way

ReplyDelete/* Fibonacci Series c language */

#include

#include

void main()

{

int f=0,s=1,ne=0,n,i;

clrscr();

printf("Enter any integer value\n");

scanf("%d",&n);

printf("%d",f);

for (i=0;i<n;i++)

{

ne=f+s;

printf("+%d",ne);

s=f;

f=ne;

}

getch();

}

Fibonacci series

ReplyDelete=============

#include

void main()

{

int num,i=0,j=1,k,n;

printf("Enter the number of elements: \n");

scanf("%d",&num);

i=-1;

for(n=0;n<num;n++)

{

k=i+j;

printf("%d ",k);

i=j;

j=k;

}

}

write a program to find a. surface area (A=apr2)

ReplyDeleteb. volume (v=4/3 p3)

Check out fibonacci series program in c for interviews

ReplyDeleteGreat post... but the fab numbers start at 1 not 0. SHould be a quick fix :)

ReplyDelete/* Fibonacci Series c language */

ReplyDelete#include

#include

void main()

{

int n1=0,n2=1,n3=0,n,i;

clrscr();

printf("Enter any integer value\n");

scanf("%d",&n);

for (i=0;i<n;i++)

{

n3=n1+n2;

printf("+%d",n3);

n1=n2;

n2=n3;

}

getch();

}

can anyone solve this

ReplyDeleteSam is a 6th grader, who's got an assignment to check it a number belongs to the Fibonacci series or not. But apparently his friends have called him out to play a game of Cricket. If Sam writes down the series and verifies it all, if would take too long and would probably miss his match. Can you help him solve his problem through a program ?

Input The first line of the input would contain the number of test cases T. Followed by T list of numbers.

Output For a particular test case T, if the number is present in the Fibonacci series, print Y followed by the position of the number in the Fibonacci series. Else print N followed by NOT PRESENT

(Since 1 is present twice in the series, print both the occurrences)

sample Input (Plaintext Link)

ReplyDelete5

1

8

4

7

21

Sample Output (Plaintext Link)

Y 2 3

Y 7

N NOT PRESENT

N NOT PRESENT

Y 9

sir pls tell me c programme for n even numbers using break and continue

ReplyDeleteWrite a program containing a recursive function that computes and displays the nth Fibonacci number, given the value for n.

ReplyDeleteplease send me this program

This comment has been removed by the author.

ReplyDeleteThis comment has been removed by the author.

ReplyDelete#include

ReplyDeleteint main(){

int k,r;

int i=0,j=1,f;

printf("Enter the number range:");

scanf("%d",&r);

printf("FIBONACCI SERIES: ");

printf("%d %d",i,j);

for(k=2;k<r;k++){

f=i+j;

i=j;

j=f;

printf(" %d",f);

}

return 0;

}

Can anyone help me?

ReplyDeleteWrite a recursive function fast_fib to compute a pair of Fibonacci numbers,

F( n + 1) and F( n ). Function fast_fib should make only one recursive call.

Algorithm

if n is 1

The pair to send back is 1, 1.

else

Use fast_fib to compute F( n ) and F( n − 1).

The pair to send back is [F( n ) + F( n − 1)], F( n ).

thanks for your answers

ReplyDelete