Skip to content

Instantly share code, notes, and snippets.

View scratchyourbrain's full-sized avatar

scratchyourbrain

View GitHub Profile
@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 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 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 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 Find Factorial of a Number
Created December 17, 2014 08:56
C Program to Find Factorial of a Number
#include <stdio.h>
int main()
{
int n, count;
int factorial=1;
printf("Enter an integer: ");
scanf("%d",&n);
if ( n< 0)
printf("Error!!! Factorial of negative number doesn't exist.");
else
@scratchyourbrain
scratchyourbrain / C Program to Check Whether a Character is an Alphabet or not
Created December 16, 2014 06:07
C Program to Check Whether a Character is an Alphabet or not
#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c",&c);
if( (c>=65 && c<=90) || (c>=97 && c<=122))
printf("%c is an alphabet.",c);
else
printf("%c is not an alphabet.",c);
@scratchyourbrain
scratchyourbrain / C Program to Check Whether a Number is Positive or Negative or Zero.
Created December 16, 2014 04:36
C Program to Check Whether a Number is Positive or Negative or Zero.
#include <stdio.h>
int main()
{
float num;
printf("Enter a number: ");
scanf("%f",&num);
if (num<0) /* Checking whether num is less than 0*/
printf("%.2f is negative.",num);
else if (num>0) /* Checking whether num is greater than zero*/
printf("%.2f is positive.",num);
@scratchyourbrain
scratchyourbrain / C Program to Check Leap Year
Created December 16, 2014 04:13
C Program to Check Leap Year
#include <stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0) /* Checking for a century year */
{
@scratchyourbrain
scratchyourbrain / C Program to Find the Largest Number Among Three Numbers
Created December 15, 2014 13:27
C Program to Find the Largest Number Among Three Numbers
#include <stdio.h>
int main()
{
float a, b, c;
printf("Enter three numbers: ");
scanf("%f %f %f", &a, &b, &c);
if(a>=b && a>=c)
printf("Largest number = %.2f", a);
else if(b>=a && b>=c)
printf("Largest number = %.2f", b);
@scratchyourbrain
scratchyourbrain / C Program to Check Vowel or Consonant
Created December 15, 2014 11:56
C Program to Check Vowel or Consonant
#include <stdio.h>
int main()
{
char c;
printf("Enter an alphabet: ");
scanf("%c",&c);
if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U')
printf("%c is a vowel.",c);
else
printf("%c is a consonant.",c);