Skip to main content

Featured

C++ Program to Perform Linear Search on a Vector

  C++ Program to Perform Linear Search on a Vector Introduction In this C++ program, we will learn how to perform a Linear Search on a vector. The program first takes the size of the vector and its elements as input. Then it asks the user for the element to search. If the element is found, it displays the index where it is located. Otherwise, it displays a message indicating that the element is not found. C++ Program #include<bits/stdc++.h> using namespace std; int main() { int num, search, found = 0; cout << "Enter the size of the vector:" << endl; cin >> num; vector<int> v(num); cout << "Enter " << num << " elements in vector:" << endl; for(int i = 0; i < num; i++) { cin >> v[i]; } cout << "Enter element that you want to search:" << endl; cin >> search; for(int i = 0; i < num; i++) { ...

C Program to Print Fibonacci Series Up To N

C Program to Print Fibonacci Series Up To N

✅ C Program to Print Fibonacci Series Up To N

#include <stdio.h>
int main()
{
        int num,a=0,b=1,c;
        printf("Enter the limit:\n");
        scanf("%d",&num);
        printf("Fibonacci series upto %d\n",num);
        while(a<=num)
        {
                printf("%d ",a);
                c=a+b;
                a=b;
                b=c;
        }
}
  

๐Ÿ“˜ Explanation:

This program prints the Fibonacci series up to a given limit using a while loop. In Fibonacci series, each number is the sum of the previous two numbers.

  • Initialize first two numbers as a = 0 and b = 1.
  • Print a while it is less than or equal to the limit.
  • Calculate next term using c = a + b.
  • Update values: a = b and b = c.
  • Repeat until a <= num.

๐Ÿงพ Sample Output:

Enter the limit:
20
Fibonacci series upto 20
0 1 1 2 3 5 8 13
  

๐Ÿ”‘ Keywords:

C program Fibonacci series, Fibonacci series in C, C loop programs, while loop example in C, beginner C programs, Fibonacci logic explanation

๐Ÿ“Œ Hashtags:

#CProgramming #Fibonacci #LearnC #CodingForBeginners #WhileLoop #1printf

๐Ÿ” Search Description:

Learn how to print Fibonacci series in C up to a given number using while loop. Simple beginner-friendly program with explanation and sample output.

Comments

Popular Posts

๐ŸŒ™