C Program to Print 1 3 8 15 27 50 92 Number Series

Ex: Write a C program to print 1 3 8 15 27 50 92 number series. How to write a C program to print 1 3 8 15 27 50 92 number series. C program to print 1 3 8 15 27 50 92 number series.


Input from user:
Enter the number: 8

Expected output:
1 3 8 15 27 50 92




  Quick links:






  Step by step logic of the given program:


1. Declare variables a=1, b=3, c=4, z, i, no.

2. Accept input (limit) from user and store it in variable no.

3. First print value of a and b as it is with one space:

4. After that run loop from 3 to no and inside that store addition of a+b+c in variable z and print value of z.

5. After that swap values of ab and c as follows:
a=b;
b=c;
c=z;







  Program:


#include<stdio.h>
void main()
{
 int a=1,b=3,c=4,z,i,no;

 /*Accept input number*/
 printf("Enter the number:\n");
 scanf("%d",&no);
 /*Print first value of a and b as it is*/
 printf("%d %d ",a,b);
 /*Run for loop from 3 to number*/
 for(i=3;i<=no;i++)
 {
  z=a+b+c;
  printf("%d ",z);
  a=b;
  b=c;
  c=z;
 }
 
}



Above program shows the following output:

C program to print 1 3 8 15 27 50 92 number series


No comments:

Post a Comment

If you have any doubts, please discuss here...👇