C Important Programs PDF
C Important Programs PDF
Fibonacci series in c programming: c program for Fibonacci series without and with recursion. Using the
code below you can print as many numbers of terms of series as desired. Numbers of Fibonacci
sequence are known as Fibonacci numbers. First few numbers of series are 0, 1, 1, 2, 3, 5, 8 etc, Except
first two terms in sequence every other term is the sum of two previous terms, For example 8 = 3 + 5
(addition of 3, 5). This sequence has many applications in mathematics and Computer Science
Fibonacci series in c using for loop
/* Fibonacci Series c language */
#include<stdio.h>
int main()
{
int n, first = 0, second = 1, next, c;
printf("Enter the number of terms\n");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are :-\n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d\n",next);
}
return 0;
}
------------------------------------------------------------------------------------------------------
printf("Enter %d integers\n",n);
for (c = 1; c <= n; c++)
{
scanf("%d", &value);
sum = sum + value;
}
printf("Sum of entered integers = %d\n",sum);
return 0;
}
-----------------------------------------------------------------------------------------------------C programming code using array
#include <stdio.h>
int main()
{
int n, sum = 0, c, array[100];
scanf("%d", &n);
for (c = 0; c < n; c++)
{
scanf("%d", &array[c]);
sum = sum + array[c];
}
printf("Sum = %d\n",sum);
return 0;
}
The advantage of using array is that we have a record of numbers inputted by user and can use them
further in program if required and obviously storing numbers will require additional memory
------------------------------------------------------------------------------------------------------
#include<stdio.h>
main()
{
int n;
printf("Input an integer\n");
scanf("%d",&n);
n%2 == 0 ? printf("Even\n") : printf("Odd\n");
return 0;
}
C program to check odd or even without using bitwise or modulus operator
#include<stdio.h>
main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
if ( (n/2)*2 == n )
printf("Even\n");
else
printf("Odd\n");
return 0;
}
In c programming language when we divide two integers we get an integer result, For example the result
of 7/3 will be 2.So we can take advantage of this and may use it to find whether the number is odd or
even. Consider an integer n we can first divide by 2 and then multiply it by 2 if the result is the original
number then the number is even otherwise the number is odd. For example 11/2 = 5, 5*2 = 10 ( which is
not equal to eleven), now consider 12/2 = 6 and 6 *2 = 12 ( same as original number). These are some
logic which may help you in finding if a number is odd or not
C program to perform addition, subtraction, multiplication and division
C program to perform basic arithmetic operations which are addition, subtraction, multiplication and
division of two numbers. Numbers are assumed to be integers and will be entered by the user.
C programming code
#include <stdio.h>
int main()
{
int first, second, add, subtract, multiply;
float divide;