click on this link......

LinkGrand.com

Thursday 12 September 2013

Swapping of two numbers using call by reference

#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
int a,b;
clrscr();
printf("\nEnter two nos: ");
scanf("%d%d",&a,&b);
printf("\nvalues before swapping: %d\t%d",a,b);
swap(&a,&b);
printf("\nvalues after swapping: %d\t%d",a,b);
getch();
}
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}

Output:
Enter two nos: 25 62
values before swapping: 25      62
values after swapping: 62    25

Swapping of two numbers using call by value

#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int a,b;
clrscr();
printf("\nEnter two nos: ");
scanf("%d%d",&a,&b);
printf("\nvalues before swapping: %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 values after swapping: %d\t%d",x,y);
}

Output :
Enter two nos: 5 6
values before swapping:  5      6
values after swapping: 6      5

program for lowercase and uppercase

Ask the user to enter an alphabetic character. If it is an uppercase character, ask for two numbers and calculate the average of them.
If it is a lowercase character, ask for three numbers and calculate the average of them…

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,p,q,r,avg1,avg2;
char ch;
clrscr();
printf("\nEnter a character: ");
scanf("%c",&ch);
printf("\nThe ascii code is %d\n",ch);
if(ch>=65 && ch<=90)
{
printf("\nIt is an uppercase character\n");
printf("\nEnter two nos\n");
scanf("%d%d",&a,&b);
avg1=(a+b)/2;
printf("\nThe average is %d \n",avg1);
}
else if(ch>96 && ch<=122)
{
printf("\nIt is lowercase character\n");
printf("\nEnter three nos: ");
scanf("%d%d%d",&p,&q,&r);
avg2=(p+q+r)/3;
printf("\nThe average is %d",avg2);
}
else
{
printf("\nIt is a special character");
}
getch();

}

Output1:
Enter a character: g
The ascii code is 103
It is lowercase character.
Enter three nos: 25 36 85
The average is 48

Output 2:
Enter a character: G
The ascii code is 71
It is uppercase character.
Enter three nos: 25 36 
The average is 30

Output 3:
Enter a character: @
The ascii code is 64
It is a special character.

Tuesday 10 September 2013

To find whether character entered is capital letter, small case letter,a digit or a special symbol

Any character is entered through the keyboard, write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters.

Characters                     ASCII VAlues
A-Z                                65-90
a-z                                  97-122
0-9                                 48-57
Special symbols               0-47, 58-64, 91-96, 123-127

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Enter a character:");
scanf("%c",&ch);
if(ch>=65 && ch<=90)
{
printf("\n Upper case letter");
}
else if(ch>=97 && ch<=122)
{
printf("\n Lower case letter");
}
else if(ch>=48 && ch<=57)
{
printf("\n Digit");
}
else if((ch>=0 && ch<=47) || (ch>=58&& ch<=64) || (ch>=91 && ch<=96) || (ch>=123 && ch<=127))
{
printf("\n Special symbol");
}
getch();
}

Output1:

Enter a Character: H
Upper case letter

Output2:

Enter a Character: g
Lower case letter

Output3:

Enter a Character: 8
Digit

Output4:

Enter a Character: @
Special symbol


Program to check whether triangle is equilateral, isosceles or scalene triangle

If the three sides of a triangle are entered through the keyboard, write a program to check whether triangle is equilateral, isosceles or scalene triangle.
#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3;
clrscr();
printf("Enter three sides of a traingle");
scanf("%d%d%d",&s1,&s2,&s3);
if(s1==s2 && s2==s3 && s1==s3)
{
printf("\n Equilateral triangle");
}
else if(s1==s2 || s2==s3 || s1==s3)
{
printf("\n Isosceles triangle");
}
else
{
printf("\n Scalene traingle");
}
getch();
 }


Output1:

Enter three sides of a triangle: 25 25 25

Equilateral triangle

Output2:

Enter three sides of a triangle: 25 25 45

Isosceles triangle

Output3:

Enter three sides of a triangle: 25 35 56

Scalene triangle