Page No :
Problem statement : 11 .Write a program in C to display the Fibonacci sequence
of first n numbers of first n numbers .
Definition : The Fibonacci sequence is a sequence where the next term is the sum
of the previous two terms. The first two terms of the Fibonacci sequence are 0
followed by 1. The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21.
Algorithm :
Step 1 : start
Step 2 : read the number
Step 3 : print the value of a and b
Step 4 : compute the for loop
Step 5 : print as per condition
Step 6 : stop
Source Code :
#include<stdio.h>
int main(void)
{
int i,n,a=0,b=1,c;
printf("Enter the number : ");
scanf("%d",&n);
printf("%d,%d",a,b);
i=n;
for(i=1;i<=n-2;i++)
{
c=a+b;
printf(",%d",c);
a=b;
b=c;
}
return 0;
of the program for a particular set of inputs.
Output:
Following are the output of the program for a particular set of inputs.
Set 1 :
Set 2 :
Set 3 :
Page No :
Discussions :
Description of functions and variables :
In the main( ) function :
- int n : Here n indicate itself as a variable which contains a number .
-int a,b : Here a and b is ainitialized value.
-int c : Here c is a temporary variable.
Assumptions :
The user gives a value as a inputs to the program.
Limitation :
It doesnot upport any kind of decimal value or any kind of negative value .
Usage :
By using this method we can easily find the nth term of the Fibonacci sequence.
_____________________ _____________________
Teacher’s signature
Page No :
Problem statement : 12 .Write a program in C to print Armstrong number within a
given range. given range.
Definition : A number is called Armstrong number when the sum of the nth power
of each digit is equal to the given number.
Algorithm :
Step 1 : start
Step 2 : read the upper and lower limit
Step 3 : print the statement
Step 4 : compute the for loop
Step 5 : calculate as per instruction
Step 6 : check the condition
Step 7 : print as per condition
Step 8 : stop
Source Code :
#include<stdio.h>
#include<math.h>
int main(void)
{
int n,lower,upper,rem,i,sum=0,count=0;
printf("Enter the lower limit : ");
scanf("%d",&lower);
printf("\nEnter the upper limit : ");
scanf("%d",&upper);
printf("\nThe armstrong numbers between given range are :\n");
for(i=lower;i<=upper;i++)
{
n=i;
sum=0;
count=0;
while(n>0)
{
count++;
n=n/10;
}
n=i;
while(n>0)
{
rem=n%10;
sum=sum+pow(rem,count);
n=n/10;
}
if(i==sum)
{
printf("%d ",i);
Page No :
}
}
return 0;or a particular set of inputs.
Output:
Following are the output of the program for a particular set of inputs.
Set 1 :
Set 2 :
Set 3 :
Discussions :
Description of functions and variables :
In the main( ) function :
- int n,i : Here n,i indicate itself as a variable which contains a number .
-int lower, upper : Here lower and upper is the range value which taken from
the user.
-int rem,count,sum : Here rem represent the remainder, count is count the digit ,and
sum is used to calculate the value .
Assumptions :
The user gives a value as a inputs to the program.
Limitation :
It doesnot upport any kind of decimal value or any kind of negative value .
Usage :
By using this method we can easily find the Armstrong numbers in a given range .
_____________________ _____________________
Teacher’s signature
Page No :
Problem statement :
13 .Write a program in C to print a triangle of numbers as follows (take number of
ccbvbvlines from user):
1
01
101
0101
10101
010101
1010101
Definition : This code is a C program that prints a pattern of 1s and 0s in a triangle
shape, depending on the number of rows specified by the user. The number of rows
is entered by the user and the pattern is printed accordingly. The pattern alternates
between 0s and 1s in each row, depending on whether the row number is even or
odd.
Algorithm :
Step 1 : start
Step 2 : read the numberof lines
Step 3 : compute the for loop
Step 4 : print as per condition
Step 5 : stop
Source Code :
#include<stdio.h>
int main(void)
{
int i,j,r;
printf("Enter number of rows:");
scanf("%d",&r);
for(i=1;i<=r;i++)
{
for(j=1;j<=i;j++)
{
if(i%2==0)
{
if(j%2==0)
printf("1");
else
printf("0");
}
else
{
if(j%2==0)
printf("0");
else
Page No :
printf("1");
}
}
printf("\n");
}
}
of the program for a particular set of inputs.
Output:
Following are the output of the program for a particular set of inputs.
Set 1 : Set 2 :
Set 3 :
Discussions :
Description of functions and variables :
In the main( ) function :
- int r : Here r is the user input value which contains the the number of row .
Assumptions :
The user gives a value as a inputs to the program.
Limitation :
It doesnot upport any kind of decimal or any kind of negative input . This code
didnot execute other patterns.
Usage :
It can also be used to develop a game which requires pattern [Link] code can also
be extended to print the pattern in different shapes like triangle , rectangle etc.
_____________________ _____________________
Teacher’s signature
Page No :
Problem statement :
14 . Write a program in C to print a triangle of stars asfollows (take number of lines
from user):
*
***
*****
*******
*********
Definition : This code is used to print a pattern of asterisks (*) in a pyramid
shape. The user is prompted to enter the number of rows they would like to
print, and the code uses a nested loop structure to generate the pattern.
Algorithm :
Step 1 : start
Step 2 : read the number
Step 3 : compute the for loop
Step 4 : print as per condition
Step 5 : stop
Source Code :
#include<stdio.h>
int main(void)
{
int i,j,rows;
printf("Enter number of rows:");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=i;j<rows;j++)
{
printf(" ");
}
for(j=1;j<=(2*i-1);j++)
{
printf("*");
}
printf("\n");
}
return 0;
}rogram for a particular set of inputs.
Page No :
Output:
Following are the output of the program for a particular set of inputs.
Set 1 : Set 2 :
Set 3 :
Discussions :
Description of functions and variables :
In the main( ) function :
- int n : Here n indicate itself as a variable which contains a number .
Assumptions :
The user gives a value as a inputs to the program.
Limitation :
It doesnot support any kind of decimal value or any kind of negative value . also it
can only print a right angle triangle
Usage :
By using this method we can easily to print a right-angled of stars.
_____________________ _____________________
Teacher’s signature
Page No :
Problem statement :
15 . Write a program in C to print a triangle of stars asfollows (take number of lines
from user):
*
***
*****
*******
*********
Definition : This code is used to print a pattern of asterisks (*) in a pyramid
shape. The user is prompted to enter the number of rows they would like to
print, and the code uses a nested loop structure to generate the pattern.
Algorithm :
Step 1 : start
Step 2 : read the number
Step 3 : compute the for loop
Step 4 : print as per condition
Step 5 : stop
Source Code :
#include<stdio.h>
int main(void)
{
int i,j,rows;
printf("Enter number of rows:");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=i;j<rows;j++)
{
printf(" ");
}
for(j=1;j<=(2*i-1);j++)
{
printf("*");
}
printf("\n");
}
return 0;
}rogram for a particular set of inputs.
Page No :
Output:
Following are the output of the program for a particular set of inputs.
Set 1 : Set 2 :
Set 3 :
Discussions :
Description of functions and variables :
In the main( ) function :
- int n : Here n indicate itself as a variable which contains a number .
Assumptions :
The user gives a value as a inputs to the program.
Limitation :
It doesnot support any kind of decimal value or any kind of negative value . also it
can only print a right angle triangle
Usage :
By using this method we can easily to print a right-angled of stars.
_____________________ _____________________
Teacher’s signature