Skip to content

Instantly share code, notes, and snippets.

View scratchyourbrain's full-sized avatar

scratchyourbrain

View GitHub Profile
@scratchyourbrain
scratchyourbrain / C Program to implement sizeof operator
Created December 14, 2014 11:41
C Program to implement sizeof operator
#include <stdio.h>
int main()
{
int a;
float b;
double c;
char d;
printf("Size of int: %d bytes\n",sizeof(a));
printf("Size of float: %d bytes\n",sizeof(b));
printf("Size of double: %d bytes\n",sizeof(c));
@scratchyourbrain
scratchyourbrain / C Program to swap two numbers
Created December 14, 2014 12:33
C Program to swap two numbers
#include <stdio.h>
int main()
{
int a, b, temp;
printf("Enter value of a: ");
scanf("%d",&a);
printf("Enter value of b: ");
scanf("%d",&b);
temp = a; /* Value of a is stored in variable temp */
a = b; /* Value of b is stored in variable a */
@scratchyourbrain
scratchyourbrain / C Program to Check Whether a Number is Even or Odd
Created December 15, 2014 11:20
C Program to Check Whether a Number is Even or Odd
#include <stdio.h>
int main()
{
int num;
printf("Enter an integer you want to check: ");
scanf("%d",&num);
if((num%2)==0) /* Checking whether remainder is 0 or not. */
printf("%d is even.",num);
else
printf("%d is odd.",num);
@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);
@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 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 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 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 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)