google-site-verification: googlef8aa845b858144d3.html COMPUTER SCIENCE NOTES: March 2017

Friday, March 3, 2017

Leap Year: (Example 2) This program checks whether year is a leap year ...


/* program to find whether a year is leap or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
printf("Enter year :");
scanf("%d",&year);
if(year%100==0)
{
if(year%400==0)
printf("Leap year \n");
else
printf("Not leap year \n");
}
else
{
if(year%4==0)
printf("Leap year \n");
else
printf("Not leap year \n");
}
getch();
}




Leap Year: (Example 1)C program to check if a given year is leap year or...




/*find a year is lear or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year : ");
scanf("%d",&year);
if(year%4==0 &&(year%100!=0 || year%400==0))
printf("This is leap year ");
else
printf("This is not leap year ");
getch();
}

Largest:(Example 3)C Program to Find the Largest Number Among Three Numb...

/* 3 program of largest number from given 3 numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter 3 number a, b and c :\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b && a>c)
puts("a is the greatest");
else if(b>c)
puts("b is the greatest");
else
puts("c is the greatest");
getch();
}


Largest: (Example 2) C Program to Find the Largest Number Among Three Nu...

/*program to find largest number from three given numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,larger;
clrscr();
printf("Enter three numbers :\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
{
if(a>c)
larger=a;
else
larger=c;
}
else
{
if(b>c)
larger=b;
else
larger=c;
}
printf("Larger number is %d ",larger);
getch();
}





Largest: (Example 1)C Program to Find the Largest Number Among Three Num...

/*find the largest number from give 3 numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter 3 numbers a,b and c:\n");
scanf("%d %d %d",&a,&b,&c);
printf("largest number is : %d",(a>b?(a>c?a:c):(b>c?b:c)));
getch();
}

//thanx



Thursday, March 2, 2017

Swapping: (Example 5) Swapping of two numbers using call by reference

/* 5 program of swap 2 number */
#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
void exchange(int **, int *);
void main()
{
int c,d;
clrscr();
printf("Enter the value of c and d:\n");
scanf("%d %d",&c,&d);
swap(&c,&d);
printf("value of c=%d \nvalue of d=%d",c,d);
getch();

}
void swap(int *cc, int *dd)
{
exchange(&cc,dd);
}
void exchange(int **cc, int *dd)
{
int t;
t=**cc;
**cc=*dd;
*dd=t;
}

Swapping: (Exapmle 4) Algorithm for swapping of two numbers using pointers.

/* 4 program of swap 2 number */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp,*ptr1,*ptr2;
clrscr();
printf("Enter value of a and b:\n");
scanf("%d %d",&a,&b);
ptr1=&a;
ptr2=&b;

temp=*ptr1;
*ptr1=*ptr2;
*ptr2=temp;

printf("value of a is %d and value of  b is %d",a,b);
getch();
}




Swapping: (Example 3) Write C program to swap two numbers using third va...

/* 3 program of swap 2 number */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Enter the value of a:");
scanf("%d",&a);
printf("\nEnter the value of b:");
scanf("%d",&b);

temp=a+b;
b=temp-b;
a=temp-a;

printf("Value of a =%d\nValue of b =%d",a,b);
getch();
}





Swapping: (Example 2) Write a c program to swap two numbers without usin...

/* 2 program of swap 2 number */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter 2 number a and b:\n");
scanf("%d %d",&a,&b);

a=a+b;
b=a-b;
a=a-b;
printf("value of a=%d\nvalue of b=%d ",a,b);
getch();
}


Swapping: (Example 1) C program to swap two numbers using third variable...

/* 1 program of swap 2 number */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,t;
clrscr();
printf("Enter a number for a :");
scanf("%d",&a);
printf("Enter a number for b :");
scanf("%d",&b);
t=a, a=b, b=t;
printf("value of a=%d\nvalue of b=%d",a,b);
getch();
}








Even Odd: (Example 5) Write a program to check whether the given number ...

  1. /* 5 program of even and odd number */
  2. #include<stdio.h>
  3. #include<conio.h>
  4. void main()
  5. {
  6. int n,quotient;
  7. clrscr();
  8. printf("Enter a number :");
  9. scanf("%d",&n);
  10. quotient=n/2;
  11. if(quotient*2==n)
  12. printf("even number ");
  13. else
  14. printf("odd number");
  15. getch();
  16. }

Even Odd: (Example 4) Write a program to check whether the given number ...



/* 4 program of even odd number */

#include<stdio.h>

#include<conio.h>

void main()

{

int n,a;

clrscr();

printf("Enter a number :");

scanf("%d",&n);

a=n<<(8*sizeof(int)-1);

if(a==0)

printf("even number");

else

printf("odd number");

getch();

}

Even Odd: (Example 3) Write a program to check whether the given number ...



 /* 3 program of even and odd number */

 #include<stdio.h>

 #include<conio.h>

 void main()

 {

int n;

clrscr();

printf("Enter a number :");

scanf("%d",&n);

if((n*n)%2==0)

printf("even number");

else

printf("odd number");

getch();

 }

Even Odd: (Example 2) Write a program to check whether the given numbe...

/* 2 program of even and odd */
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter a number :");
scanf("%d",&n);
if((n&1)==1)
printf("odd number");
else
printf("even number");
getch();
}

Even Odd: (Example 1) Write a program to check whether the given number ...


/* 1 program of even and odd */
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter a number :");
scanf("%d",&n);
if(n%2==0)
printf("even number");
else
printf("odd number");
getch();
}