Skip to main content

Featured

C Program to Solve Two Sum Using Brute Force (With Algorithm & Output)

 Introduction The Two Sum problem is a popular coding interview question where we must find two indices of an array whose values add up to a given target. This program demonstrates a simple brute-force solution in C using nested loops and dynamic memory allocation. Problem Statement Given an integer array and a target value, return the indices of the two numbers such that they add up to the target. Each input has exactly one solution, and the same element cannot be used twice. The result should return the indices, not the values. If no solution exists, return NULL.  Algorithm / Logic Explanation Start the program. Traverse the array using a loop from index 0 to numsSize - 1 . Inside this loop, use another loop starting from i + 1 to numsSize - 1 . For every pair (i, j) , check if nums[i] + nums[j] == target . If condition becomes true: Allocate memory for 2 integers using malloc() . Store indices i and j . Set returnSize = 2 . Return the result poi...

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

๐ŸŒ™