30
/* Program to illustrate the use of getch and putchar function*/ #include<stdio.h> #include<conio.h> void main() { int a; char ch; clrscr();  printf("\n\n\ a\tProgram to illsutrate the use of getch() & putchar function");  printf("\n\nEnt er a Numberic Value="); a=getch();  printf("\nEnt er a Alphabetic Value="); ch=getch();  printf("\n\nEnt ered the Numberic & Alpahbetic Value=");  putchar(a);  printf("\t");  putchar(ch); getch(); } Page No.1/30

C Language Only Program

Embed Size (px)

Citation preview

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 1/30

/* Program to illustrate the use of getch and putchar function*/

#include<stdio.h>

#include<conio.h>void main()

{

int a;

char ch;

clrscr();

 printf("\n\n\a\tProgram to illsutrate the use of getch() & putchar 

function");

 printf("\n\nEnter a Numberic Value=");a=getch();

 printf("\nEnter a Alphabetic Value=");

ch=getch();

 printf("\n\nEntered the Numberic & Alpahbetic Value=");

 putchar(a);

 printf("\t");

 putchar(ch);

getch();

}

Page No.1/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 2/30

/* Program to illustrate the use of gets and puts function*/

#include<stdio.h>#include<conio.h>

void main()

{

char name[10];

clrscr();

 printf("\n\n\a\tTo explain use of gets() & puts() Function\n");

 printf("\nEnter Your Name\t");

gets(name); printf("\n\n Entered Name is =");

 puts(name);

getch();

}

Page No.2/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 3/30

/* Program to illustrate the use of "#define" function*/

#include<stdio.h>#include<conio.h>

#define pi 3.14

void main()

{

float r,i;

clrscr();

 printf("\n\n\a\tTo explan use of '#define' Function\n");

 printf("\nEnter the radious of circle=\t");scanf("%f",&r);

i=pi*r*r*2;

 printf("\nResult=\t%.2f",i);

getch();

}

Page No.3/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 4/30

/* Program to find the area and circumference of the circle*/

#include<stdio.h>

#include<conio.h>

#define pi 3.14

void main()

{

float r,area,cir;

clrscr();

 printf("\n\n\aProgram to find the area and circumference of circle\t\n");

 printf("\nEnter the radious of circle=\t");

scanf("%f",&r);

area=pi*r*2*r;

cir=2*pi*r;

 printf("\nArea of Circle=%.2f",area);

 printf("\n\nCircumference of Circle=%.2f",cir);

getch();

}

Page No.4/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 5/30

/* To find Average of three Numbers*/

#include<stdio.h>#include<conio.h>

void main()

{

int a,b,c,avg;

clrscr();

 printf("\n\n\aTo find Average of three Numbers\t\n");

 printf("\nEnter the value of a, b & c=");scanf("%d%d%d",&a,&b,&c);

avg=(a+b+c)/3;

 printf("\nAverage of three numbers=%d",avg);

getch();

}

Page No.5/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 6/30

/* To compute simple interest & compound interest */

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

float p,r,t,si,coin,temp,te;

clrscr();

 printf("\n\n\aTo Compute Simple Interest & Compund Interest\n"); printf("\nEnter the Amount=");

scanf("%f",&p);

 printf("\nEnter the Rate of Interest=");

scanf("%f",&r);

 printf("\nEnter the Time=");

scanf("%f",&t);

si=(p*r*t)/100;

temp=(r/100)+1;

te=pow(temp,t);

coin=te*p;

 printf("\nSimple Interest =%.2f",si);

 printf("\n\nCompounde Interest =%.2f",coin);

getch();

}

Page No.6/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 7/30

/* To Swap the Two Value using third variable*/

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,c;

clrscr();

 printf("\n\n\aTo swap two value using third variable\n");

 printf("\nEnter the value of a =");

scanf("%d",&a);

 printf("\nEnter the value of b =");scanf("%d",&b);

c=a;

a=b;

 b=c;

 printf("\nAfter Swapping a & b=%d\t%d",a,b);

getch();

}

Page No.7/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 8/30

/* To Swap the Two Value without using third variable*/

#include<stdio.h>#include<conio.h>

void main()

{

int a,b;

clrscr();

 printf("\n\n\aTo swap two value without using third variable\n");

 printf("\nEnter the value of a =");scanf("%d",&a);

 printf("\nEnter the value of b =");

scanf("%d",&b);

a=a+b;

 b=a-b;

a=a-b;

 printf("\nAfter Swapping a & b=%d\t%d",a,b);

getch();

}

Page No.8/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 9/30

/* To Find the Prime Number*/

#include<stdio.h>

#include<conio.h>#include<math.h>

void main()

{

int i,num,n,flag=1;

clrscr();

 printf("\n\n\aTo Find the Prime Number\n");

 printf("\nEnter Number U Want to check=");

scanf("%d",&num);n=sqrt(num);

for(i=2;i<=n;++i)

{

if (num%i==0)

{

flag=0;

 break;

}

}

if(flag==1)

 printf("\n%d\t is a prime number",num);

else

 printf("\n%d\tis not a prime number",num);

getch();

}

Page No.9/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 10/30

/* To illustrate the concept of break statement*/

#include<stdio.h>

#include<conio.h>

void main()

{

int i,n;

clrscr();

 printf("\n\n\aTo illustrate the concept of break statement\n");

 printf("\n\nEnter Where u want to Break the loop=");

scanf("%d",&n);for(i=1;i<=100;i++)

{

if (i==n)

 break;

 printf("\n\t%d",i);

}

getch();

}

Page No.10/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 11/30

/* To find the factroial of "n" number */

#include<stdio.h>

#include<conio.h>void main()

{

int i,n,fact=1;

clrscr();

 printf("\n\n\tTo find the Factorial of any number\n");

 printf("\nEnter Number=");

scanf("%d",&n);

for(i=1;i<=n;i++){

fact=fact*i;

}

 printf("\nResult of Factorial=%d",fact);

getch();

}

Page No.11/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 12/30

/* To print the first 'n' table*/

#include<stdio.h>#include<conio.h>

void main()

{

int i,n,table;

clrscr();

 printf("\n\n\tTo Print the first 'n' Table\n");

 printf("\nEnter Which Table U want to Print=");

scanf("%d",&n);for(i=1;i<=10;i++)

{

table=i*n;

 printf("\n\t\t%d\n",table);

}

getch();

}

Page No.12/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 13/30

/* To print sum of given series

1n + 2n +………… + mn 'n' is power and m is limit*/

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

int i,n,m,j,temp=0;

clrscr();

 printf("\n\n\tTo Print sum of given series\n"); printf("\n\n\t\t1n + 2n +..... + mn 'n' is power and m is limit\n");

 printf("\nEnter the value of m=");

scanf("%d",&m);

 printf("\nEnter the value of n=");

scanf("%d",&n);

for(i=1;i<=m;i++)

{

 j=pow(i,n);

temp=temp+j;

}

 printf("\nSum of Given Series=%d",temp);

getch();

}

Page No.13/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 14/30

/* To Print "n" terms of fibonec series*/

#include<stdio.h>#include<conio.h>

void main()

{

int i,a,b,n,sum;

clrscr();

 printf("\n\n\t\t\aTo Print 'N' terms of fibonec series\n");

 printf("\nEnter the Limit =");scanf("%d",&n);

a=0;

 b=1;

 printf("\n\nRequried Fibonec Series is \n\n%d\t%d",a,b);

for(i=1;i<=n-2;i++)

{

sum=a+b;

a=b;

 b=sum;

 printf("\t%d",b);

}

getch();

}

Page No.14/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 15/30

/* To Find the given number is even or odd*/

#include<stdio.h>#include<conio.h>

void main()

{

int a,b,c;

clrscr();

 printf("\n\n\t\t\aTo find the given number is even or odd\n");

 printf("\n\tEnter the Number=");scanf("%d",&a);

if (a%2==0)

 printf("\n\t%d is a Even Number");

else

 printf("\n\t%d is a Odd Number");

getch();

}

Page No.15/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 16/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 17/30

/* To Print the series

1

21

3214321

*/

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,n;

clrscr();

 printf("\n\n\t\t\aTo Print this Series\n\t\t1\n\t\t21\n\t\t321\n");

 printf("\n\tEnter Limit=");

scanf("%d",&n);

for(i=1;i<=n;i++)

{

 printf("\n\t");

for(j=i;j>=1;j--)

{

 printf("%d",j);

}

}

getch();

}

Page No.17/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 18/30

/* To illustrate the concept of continue statement*/

#include<stdio.h>

#include<conio.h>

void main()

{

int i,n;

clrscr();

 printf("\n\n\aTo illustrate the concept of Continue statement\n"); printf("\n\nEnter Where u want to Skip the loop=");

scanf("%d",&n);

for(i=1;i<=20;i++)

{

if (i==n)

continue;

 printf("\n\t%d",i);

}

getch();

}

Page No.18/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 19/30

/*To using "Buble sort" Sort the given array*/

#include<stdio.h>#include<conio.h>

void main()

{

int a[40],i,j,n,temp;

clrscr();

 printf("\n\n\tTo using 'Buble sort' Sort the given array");

 printf("\nEnter Limit=");scanf("%d",&n);

for(i=0;i<n;i++)

{

 printf("\n\tEnter Value=");

scanf("%d",&a[i]);

}

for(i=0;i<n-1;i++)

{

for(j=0;j<n-i-1;j++)

{

if(a[j]>a[j+1])

{

temp=a[j+1];

a[j+1]=a[j];

a[j]=temp;

}

}

}

 printf("\n\n\tUsing Bubble sort the sorted Array is =\n\n\t\t");

for(i=0;i<n;i++)

 printf("%d\t",a[i]);

getch();

}

Page No.19/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 20/30

/*To Find the Addition of Two Matrix*/#include<stdio.h>#include<conio.h>

void main(){int a[15][15],n[15][15],r,c,i,j,sum=0;clrscr();

 printf("\n\n\tTo Find the Addition of Two Matrix\n"); printf("\nEnter Number of Row=");scanf("%d",&r);

 printf("\nEnter Number of Column=");

scanf("%d",&c); printf("\nEnter The Value of First Matrix\n");

for(i=0;i<r;i++){

for(j=0;j<c;j++)

{scanf("%d",&a[i][j]);}

 printf("\n");}

 printf("\nEnter The Value of Second Matrix\n");for(i=0;i<r;i++)

{for(j=0;j<c;j++)

{scanf("%d",&n[i][j]);

} printf("\n");}

 printf("\n\nAddition of Two Matrix is\n\n");

for(i=0;i<r;i++){

for(j=0;j<c;j++)

{sum=a[i][j]+n[i][j];

 printf("%d",sum);

 printf("\t");}

 printf("\n");}

getch();}

Page No.20/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 21/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 22/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 23/30

/*To Explain Call by Refrence*/

#include<stdio.h>

#include<conio.h>

void swap (int *a,int *b);

void main()

{

int a,b;

clrscr();

 printf("\n\n\tTo Explain Call by Reference\n");

 printf("\nEnter the value of A=");scanf("%d",&a);

 printf("Enter the value of B=");

scanf("%d",&b);

swap(&a,&b);

 printf("\n\nAfter Calling Value of A is %d and B is %d",a,b);

getch();

}

void swap (int *a, int *b)

{

int c;

c=*a;

*a=*b;

*b=c;

 printf("\nSwapped Value of A=%d and B=%d",*a,*b);

}

Page No.23/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 24/30

/*To Explain No Argument No Return Value*/

#include<stdio.h>#include<conio.h>

void sum(void);

void main()

{

clrscr();

 printf("\n\n\tTo Explain No Argument No Return Value\n");

sum ();

getch();}

void sum()

{

int a,b,c;

 printf("\n\nEnter value of A=");

scanf("%d",&a);

 printf("\nEnter value of B=");

scanf("%d",&b);

c=a+b;

 printf("\nSum=%d",c);

}

Page No.24/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 25/30

/*To Explain No Argument With Return value*/

#include<stdio.h>

#include<conio.h>

int sum();void main()

{

int d;

clrscr();

 printf("\n\n\tTo Explain No Argument With Return Value\n");

d=sum ();

 printf("\n\tSum=%d",d);

getch();}

int sum()

{

int a,b,c;

 printf("\n\nEnter value of A=");

scanf("%d",&a);

 printf("\nEnter value of B=");

scanf("%d",&b);

c=a+b;

return(c);

}

Page No.25/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 26/30

/*with argument no return value*/

#include<stdio.h>

#include<conio.h>void sum(int a, int b);

main()

{

int a,b;

clrscr();

 printf("\n\n\tTo Explain With Argument No Return Value\n");

 printf("\n\nEnter value of A=");

scanf("%d",&a); printf("\nEnter value of B=");

scanf("%d",&b);

sum(a,b);

getch();

}

void sum(int a,int b)

{

int c;

c=a+b;

 printf("\n\tSum=%d",c);

}

Page No.26/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 27/30

/*To with argument with return value*/

#include<stdio.h>#include<conio.h>

int sum(int a, int b);

void main()

{

int a,b,d;

clrscr();

 printf("\n\n\tTo Explain With Argument With Return VAlue\n");

 printf("\n\nEnter value of A=");scanf("%d",&a);

 printf("\nEnter value of B=");

scanf("%d",&b);

d=sum(a,b);

 printf("\nSum=%d",d);

getch();

}

int sum(int a,int b)

{

int c;

c=a+b;

return(c);

}

Page No.27/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 28/30

/*To find the Sum of Diagnoal Matrix*/

#include<stdio.h>

#include<conio.h>

void main()

{

int a[15][15],r,c,i,j,sum=0;

clrscr();

 printf("\n\n\tTo find the Sum of Diagnoal Matrix\n");

 printf("\nEnter Number of Row=");

scanf("%d",&r);

 printf("\nEnter Number of Column=");scanf("%d",&c);

 printf("\nEnter The Value of Matrix\n");

for(i=0;i<r;i++)

{

for(j=0;j<c;j++)

{

scanf("%d",&a[i][j]);

}

 printf("\n");

}

for(i=0;i<r;i++)

{

for(j=0;j<c;j++)

{

if(i==j)

sum=sum+a[i][j];

continue;

}

}

 printf("\n\tResult=%d",sum);

getch();

}

Page No.28/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 29/30

/*WAP To find any element with help of Linear Search*/

#include<stdio.h>

#include<conio.h>

void main()

{

int a[10],i,n,ele,count=0;clrscr();

 printf("\n\n\tTo find any element with help of Linear Search\n\n");

 printf("\nEnter Limit=");

scanf("%d",&n);

for(i=0;i<n;i++)

{

 printf("\nEnter Value");

scanf("%d",&a[i]);}

 printf("\nEnter Element Which You Want to Search");

scanf("%d",&ele);

for(i=0;i<n;i++)

{

if (a[i]==ele)

{

 printf("\nElement is Present at Location %d",i+1);

 printf("\nElement is %d",a[i]);

count++;

}

}

if(count==0)

 printf("\nElement not Present");

getch();

}

Page No.29/30

8/8/2019 C Language Only Program

http://slidepdf.com/reader/full/c-language-only-program 30/30

/*WAP To find any element with help of Binary Search*/

#include<stdio.h>

#include<conio.h>

void main(){

int a[10],i,n,ele,mid,beg,end,count=-1;

clrscr();

 printf("\n\n\tTo find any element with help of Binary Search\n\n");

 printf("\nEnter Limit=");

scanf("%d",&n);

for(i=0;i<n;i++)

{  printf("\nEtner Value=");

scanf("%d",&a[i]);

}

 printf("\nEnter Element Which You Want to Search");

scanf("%d",&ele);

 beg=0;

end=n-1;

while(beg<=end && count==-1)

{

mid=(beg+end)/2;

if(ele==a[mid])

{

count=mid+1;

 printf("\nElement Found At Location %d",count);

 printf("\nElement is %d",a[mid]);

}

else if(ele>a[mid])

 beg=mid+1;

else

end=mid-1;

}

if(count==-1)

 printf("\nElement not Present");

getch();

}