google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Wednesday, April 1, 2015

C program to swap the values of two variables by using call by reference using pointer.

Write a ‘C’ program to swap the values of two variables by using call by reference using pointer.

#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
void main()
{
int a,b;
clrscr();
printf("\nENTER THE VALUE FOR A & B");
scanf("%d%d",&a,&b);
printf("\n\nVALUES BEFORE SWAPPING \n");
printf("%d\t%d",a,b);
swap(&a,&b);
getch();
}
void swap(int *x,int *y)
{
int t;
{
t=*x;
*x=*y;
*y=t;
}
printf("\n\nVALUES AFTER SWAPPING \n");
printf("%d\t%d",*x,*y);
}

C program to write a macro definition

Write a ‘C’ program to write a macro definition for the following.
> To test whether a character is a lower case letter or not.
> To check whether a character is alphabet or not.
> To obtain the largest of two numbers.

#include<stdio.h>
#include<conio.h>
#define LOWER(ch) islower(ch)
#define ALPHA(ch) isalpha(ch)
#define MAX(a,b) a>b?a:b
void main()
{
int n,a,b;
char c;
clrscr();
do
{
printf("\n1.LOWER");
printf("\n2.ALPHABET");
printf("\n3.MAXIMUM");
printf("\n4.EXIT");
printf("\nENTER UR CHOICE");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nENTER THE CHARACTER");
c=getche();
if(LOWER(c))
{
printf("\nCHARACTER IS IN LOWERCASE\n");
}
else
{
printf("\nCHARACTER IS IN UPPERCASE");
}
break;
case 2:
printf("\nENTER THE CHARACTER");
c=getche();
if(ALPHA(c))
{
printf("\nCHARACTER IS ALPHABET");
}
else
{
printf("CHARACTER IS NOT ALPHABET");
}
break;
case 3:
printf("\nENTER THE VALUES FOR A AND B");
scanf("%d%d",&a,&b);
  if(MAX(a,b))
{
printf("A IS MAXIMUM");
}
else
{
printf("B IS MAXIMUM");
}
break;
case 4:
exit(0);
}
}
while(n!=4);
getch();
}

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...