CP Final Lab
CP Final Lab
Branch – ECE
MIS- 112116032
Question-1
#include <stdio.h>
int main()
{
printf("++ Enter the Order of Fibonacci Sequence: ");
int a, i;
scanf("%d", &a);
printf("++ Enter Initial/Base Terms (space-seperated): ");
// Now making use of while loop to print each number of the Fibonacci
series
printf("\n** The Fibonacci sequence upto %d-th term is:\n", length);
int final[length];
for (i = 0; i < a; i++)
{
final[i] = b[i];
printf("%d ", final[i]);
}
int curr_len = a;
while (curr_len < length)
{
// Using for loop inside the while to calculate each term of series
int sum = 0;
for (i = curr_len - a; i < curr_len; i++)
{
sum += final[i];
}
final[curr_len] = sum;
printf("%d ", final[curr_len]);
curr_len++;
}
return 0;
}
Output
Question 2
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch,
system("pause") or input loop */
--------------------------------
Process exited after 20.25 seconds with return value 0
Press any key to continue . . .
Q_4
For q1
3. Then we use for loop for taking input from the user next we
define the input of length
For q2
2. Then we take the input from the used by using scanf for of all
these above variables
4. Then again using if else block we check and count the days weeks
.