Skip to content

Instantly share code, notes, and snippets.

View scratchyourbrain's full-sized avatar

scratchyourbrain

View GitHub Profile
@scratchyourbrain
scratchyourbrain / C program to Generate Multiplication Table
Created December 18, 2014 06:13
C program to Generate Multiplication Table
#include <stdio.h>
int main()
{
int n, i;
printf("Enter an integer to find multiplication table: ");
scanf("%d",&n);
for(i=1;i<=10;++i)
{
printf("%d * %d = %d\n", n, i, n*i);
}
@scratchyourbrain
scratchyourbrain / C Program to Display Fibonacci Series
Created December 18, 2014 06:54
C Program to Display Fibonacci Series
#include <stdio.h>
int main()
{
int count, n, t1=0, t2=1, display=0;
printf("Enter number of terms: ");
scanf("%d",&n);
printf("Fibonacci Series: %d %d ", t1, t2); /* Displaying first two terms */
count=2; /* count=2 because first two terms are already displayed. */
while (count<n)
{
@scratchyourbrain
scratchyourbrain / C program to find HCF GCD
Created December 18, 2014 07:31
C program to find HCF GCD
#include <stdio.h>
int main()
{
int num1, num2, i, hcf;
printf("Enter two integers: ");
scanf("%d %d", &num1, &num2);
for(i=1; i<=num1 || i<=num2; ++i)
{
if(num1%i==0 && num2%i==0) /* Checking whether i is a factor of both number */
hcf=i;
@scratchyourbrain
scratchyourbrain / C Program to Find LCM of two Numbers
Created December 18, 2014 08:10
C Program to Find LCM of two Numbers
#include <stdio.h>
int main()
{
int num1, num2, max;
printf("Enter two positive integers: ");
scanf("%d %d", &num1, &num2);
max=(num1>num2) ? num1 : num2; /* maximum value is stored in variable max */
while(1) /* Always true. */
{
if(max%num1==0 && max%num2==0)
@scratchyourbrain
scratchyourbrain / C Program to Count Number of Digits of an Integer
Created December 19, 2014 09:22
C Program to Count Number of Digits of an Integer
#include <stdio.h>
int main()
{
int n,count=0;
printf("Enter an integer: ");
scanf("%d", &n);
while(n!=0)
{
n/=10;
++count;
@scratchyourbrain
scratchyourbrain / C Program to Reverse a Number
Created December 19, 2014 09:40
C Program to Reverse a Number
#include <stdio.h>
int main()
{
int n, reverse=0, rem;
printf("Enter an integer: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
@scratchyourbrain
scratchyourbrain / C program to Calculate the Power of a Number
Created December 19, 2014 09:57
C program to Calculate the Power of a Number
#include <stdio.h>
int main()
{
int base, exp;
long long int value=1;
printf("Enter base number and exponent respectively: ");
scanf("%d%d", &base, &exp);
while (exp!=0)
{
value*=base;
@scratchyourbrain
scratchyourbrain / C Program to Check Whether a Number is Palindrome or Not
Created December 21, 2014 14:26
C Program to Check Whether a Number is Palindrome or Not
#include <stdio.h>
int main()
{
int n, reverse=0, rem,temp;
printf("Enter an integer: ");
scanf("%d", &n);
temp=n;
while(temp!=0)
{
rem=temp%10;
@scratchyourbrain
scratchyourbrain / C Program to Check Whether a Number is Prime or Not
Created December 24, 2014 05:39
C Program to Check Whether a Number is Prime or Not
#include <stdio.h>
int main()
{
int n, i, flag=0;
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=2;i<=n/2;++i)
{
if(n%i==0)
{
@scratchyourbrain
scratchyourbrain / C Program to Display Prime Numbers Between Two Intervals
Created December 24, 2014 06:11
C Program to Display Prime Numbers Between Two Intervals
#include <stdio.h>
int main()
{
int n1, n2, i, j, flag;
printf("Enter two numbers(intevals): ");
scanf("%d %d", &n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
for(i=n1+1; i<n2; ++i)
{
flag=0;