‘C’ LANGUAGE PROGRAMMING PART
PROG – 1 SIMPLE PROG TO DISPLAY YOUR NAME.
#inlcude<stdio.h>
#include<conio.h>
void main()
{
printf(“my name is chetan”);
getch();
}
output : my name is chetan
------------------------------------------------------------------------------------------------------------------------------
PROG 2 –TO FIND OUT THE REDIUS FOR CIRCLE
#include <stdio.h>
#include <conio.h>
#define pi 3.14
void main()
{
float r,a,cir;
clrscr();
printf(" Enter the Redius for circle");
scanf("%f",&r);
printf("\n\nArea of Circle is : %f",pi*r*r);
printf("\n\n Circumference of the Circle is : %f",2*pi*r);
getch();
}
OUTPUT : DEPEND ON THE VALUE YOU ENTER
PROG -3 /* Read an integer to sore hours & convert into days and hrs.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,w,yr,d;
clrscr();
printf(" enter number: ");
scanf("%d",&num);
yr=num/365;
w=(num%365)/7;
d=(num%365)%7;
printf("\nYear is :=%d",yr);
printf("\nWeek is :=%d",w);
printf("\nDay is := %d",d);
getch();
}
OUTPUT : DEPENDS ON THE NUMBER YOU ENTER
------------------------------------------------------------------------------------------------------------------------------
PROG- 4 – TO FIND OUT TOTAL MARKS AND PERCENTAGE
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,n3,n4,n5,tot,per;
clrscr();
printf("enter mark1 ");
scanf("%d", &n1);
printf("enter mark2 ");
scanf("%d", &n2);
printf("enter mark3 ");
scanf("%d", &n3);
printf("enter mark4 ");
scanf("%d", &n4);
printf("enter mark5 ");
scanf("%d", &n5);
tot=n1+n2+n3+n4+n5;
per=tot/5;
printf("the total marks from 500 is= %d", tot);
printf("\n");
printf("percent is= %d", per);
getch();
}
output:
enter mark1 45
enter mark2 46
enter mark3 38
enter mark4 98
enter mark5 74
the total marks from 500 is= 301
percent is= 60
------------------------------------------------------------------------------------------------------------------------------
PROG-5 Prog for factorial recursion
#include<stdio.h>
#include<conio.h>
void main()
{
int res;
res=rec(5);
clrscr();
printf("\n The fact recursion is %d",res);
getch();
}
int rec (int n)
{
int f=1;
if (n==1)
return(1);
else
f=n*rec(n-1);
return (f);
}
output: The fact recursion is 120
------------------------------------------------------------------------------------------------------------------------------
Prog 6 prog for count salary
# include <stdio.h>
# include <conio.h>
void main()
{
int bs,da,hra;
clrscr();
printf("Enter Basic Salary :");
scanf("%d",&bs);
if(bs<=1500)
{
da=bs*0.9;
hra=bs*0.1;
bs=bs+da+hra;
}
else if(bs>1500)
{
hra=500;
da=bs*0.98;
bs=bs+da+hra;
}
printf("TOTAL GROSS SALARY IS : %d",bs);
getch();
}
output:
Enter Basic Salary :2000
TOTAL GROSS SALARY IS : 4459
Prog 7: prog for count persentage
#include<stdio.h>
#include<conio.h>
void main()
{
float n1,n2,n3;
clrscr();
printf("enter n1 ");
scanf("%f", &n1);
printf("enter n2 ");
scanf("%f", &n2);
printf("enter n3 ");
scanf("%f", &n3);
if (n1+n2>n3)
{
printf("valid tringle");
}
else if (n2+n3>n1)
printf("valid tringle");
else if(n3+n1>n2)
printf("valid tringle");
getch();
}
output
enter n1 3
enter n2 4
enter n3 5
valid tringle
------------------------------------------------------------------------------------------------------------------------------
Prog 8 :prog for leap year
#include<stdio.h>
#include<conio.h>
void main()
{
int y,lp;
clrscr();
printf ("enter year ");
scanf("%d",&y);
if (y%4==0)
{
printf("leap year");
}
else
printf("not leap year");
getch();
}
output:
enter year 2004
leap year
------------------------------------------------------------------------------------------------------------------------------
Prog 9 :TO FIND OUT MAXIMUM NUMBER
#include <stdio.h>
#include <conio.h>
void main()
{
int n1,n2,max;
clrscr();
printf("enter n1 ");
scanf("%d", &n1);
printf("enter n2 ");
scanf("%d", &n2);
if (n1 >= n2)
{
max=n1;
printf("the max no is number %d",max);
}
else
{
max=n2;
printf("the max no is number %d", max);
}
getch();
}
output:
enter n1 34
enter n2 32
the max no is number 34
------------------------------------------------------------------------------------------------------------------------------
prog 10: prog for whether the number is odd or even.
# include <stdio.h>
# include <conio.h>
void main()
{
int a;
clrscr();
printf("Enter no. :");
scanf("%d",&a);
if(a%2==0)
{
printf("no is even");
}
else
{
printf("no is odd");
}
getch();
}
OUTPUT : DEPEND ON THE NUMBER YOU ENTER
Prog11 : Prog to find total cost
#include<stdio.h>
#include<conio.h>
void main()
{
int qty;
float price,cost,dis;
clrscr();
printf("enter qty ");
scanf("%d", &qty);
printf("enter price ");
scanf("%f",&price);
cost=price * qty;
if (cost >= 1000)
{
dis= price * qty * 0.1;
cost= (price*qty) - dis;
printf("the total cost is : %f", cost);
}
else
{
cost=price*qty;
printf("%f", cost);
}
getch();
}
OUTPUT : DEPEND ON THE QTY YOU ENTER
------------------------------------------------------------------------------------------------------------------------------
Prog 12 : This programme is to find middle value from given three values using logical operators.
# include <stdio.h>
# include <conio.h>
main()
{
int a,b,c;
clrscr();
printf("\n Enter the value of A : ");
scanf("%d",&a);
printf("\n Enter the value of B : ");
scanf("%d",&b);
printf("\n Enter the value of C : ");
scanf("%d",&c);
if (((a>b) && (a<c)) || ((a<b) && (a>c)))
printf("\n Middle value is %d",a);
if (((b>a) && (b<c)) || ((b<a) && (b>c)))
printf("\n Middle value is %d",b);
if (((c>a) && (c<b)) || ((c<a) && (c>b)))
printf("\n Middle value is %d",c);
getch();
return 0;
}
OUTPUT : DIPLAY THE MIDDLE VALUE
------------------------------------------------------------------------------------------------------------------------------
PROG 13: TO FIND OUT SALARY + HRA +DA
#include<stdio.h>
#include<conio.h>
void main()
{
int sal,da,hra;
clrscr();
printf("enter salary ");
scanf("%d",&sal);
if (sal<=1500)
{
hra=sal*0.1;
da= sal*0.9;
}
else
{
hra=500;
da=sal*0.9;
}
printf("basic salary is = %d", sal,da,hra);
printf("\n the total salary is = %d", sal+da+hra);
getch();
}
OUTPUT : DISPLAY THE BASIC SALARY
Prog14 : prog to count length of string
#include<stdio.h>
#include<conio.h>
void main()
{
char arr[50];
Int len1;
clrscr();
printf("enter the string ",arr);
scanf("%s",arr);
gets(arr);
len1 = strlen (arr);
printf ("\n string = %s length = %d", arr,len1);
getch();
}
output:
enter the string mayur
string = mayur length = 5
------------------------------------------------------------------------------------------------------------------------------
prog 15 :prog for define capital,small or digit
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
clrscr();
printf ("enter any key ");
scanf ("%c", &a);
if (a>=65 && a<=90)
{
Printf("the result is capital alphbet %c", a);
}
else if (a>=97 && a<=122)
printf ("small alpha %c",a);
else if (a>=48 && a<=57)
printf ("digit %c",a);
getch();
}
output
enter any key G
the result is capital alphbet G
------------------------------------------------------------------------------------------------------------------------------
Prog 16 : prog for a counting string
#include<stdio.h>
#include<conio.h>
void main()
{
char str[8];
int j=0;
strlen j();
clrscr();
printf("\n Enter the string ");
scanf("\n %s",str);
j=strlen(str);
printf("The length is %d",j);
getch();
}
output
Enter the string abc
The length is 3
------------------------------------------------------------------------------------------------------------------------------
Prog 17 : prog for whether the insurance is given or not
# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
char st[6];
char s[5];
int a;
clrscr();
printf("Enter status: ");
scanf("%s",&st);
printf("Enter sex: ");
scanf("%s",&s);
printf("Enter age: ");
scanf("%d",&a);
if(strcmp(st,"u")==0 && strcmp(s,"m")==0 && a>=30 || strcmp(s,"f")==0 && a>=25)
{
printf("INSURANCE IS GIVEN");
}
else
{
printf("INSURANCE IS NOT GIVEN");
}
getch();
}
OUTPUT : DEPEND ON THE NUMBER YOU ENTER
------------------------------------------------------------------------------------------------------------------------------
Prog 18 :// This programme is to print the prime numbers.
# include <stdio.h>
# include <conio.h>
void main()
{
int i,j,f=0;
clrscr();
for(i=2; i<=100; i++)
{
f=0;
for(j=2; j<=i/2; j++)
if (i%j==0)
{
f=1;
break;
}
if(f==0)
printf(" %d ",i);
}
getch();
return 0;
------------------------------------------------------------------------------------------------------------------------------
prog 18 :// This programme is to print the series 1,4,9,16,25..... upto 100
# include <stdio.h>
# include <conio.h>
main()
int i;
clrscr();
for(i=1; i<=10; i++)
printf("\t %d",i*i);
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog 20 : // This programme is to print the series 0,3,8,15,24.... upto 99
# include <stdio.h>
# include <conio.h>
void main()
{
int i;
clrscr();
for(i=1; i<=10; i++)
printf("\t %d",i*i-1);
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog21 : // This programme is to print the series 100,98,96,94,92........ upto 2.
# include <stdio.h>
# include <conio.h>
void main()
{
int i;
clrscr();
for(i=100; i>=2; i=i-2)
printf("\t %d",i);
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog22 :// This programme is to print the series 2,4,6,8,10...... upto 100
# include <stdio.h>
# include <conio.h>
void main()
{
int i;
clrscr();
for(i=2; i<=100; i=i+2)
printf("\t %d",i);
getch();
return 0;
}
Prog22 :// This programme is to print 1 to 10 in decrement order
# include <stdio.h>
# include <conio.h>
void main()
{
int i;
clrscr();
for (i=10; i>=1; i--)
printf("\n %d",i);
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog23 : // This programme is to print 1 to 10 in increment order.
# include <stdio.h>
# include <conio.h>
main()
{
int i;
clrscr();
for(i=1; i<=10; i++)
printf("\n %d",i);
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog24 : // This programme is to print the series of Armstrong numbers
# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
int i,j,sum=0;
clrscr();
for(i=1; i<=1000; i++)
{
sum=0;
for(j=i; j!=0;)
{
sum=sum+pow((j%10),3);
j=j/10;
}
if(sum==i)
printf("\t%d",i);
}
getch();
return 0;
Prog25 : // This programme is a chart of ASCII code
# include <stdio.h>
# include <conio.h>
void main()
{
int i;
clrscr();
for(i=0; i<=255; i++)
printf("%d-> %c ",i,i);
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog26 : find the no which div by 13 & 7
#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2,res,i;
clrscr();
printf("Enter Value of Starting Range:->");
scanf("%d",&num1);
printf("Enter Value of Ending Range:->");
scanf("%d",&num2);
printf("\n\nList of Divisable nos. by 13 and 7 both\n\n");
for(i=num1;i<=num2;i++)
{
if(i%91==0) // Because 13 * 7 = 91
printf(" %d ",i);
}
getch();
}
Prog27 :prog for arrange space
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,sp,s=0;
clrscr();
for (i=5; i>=1; i--)
{
for(j=1; j<=i; j++)
printf("%d ",j);
for(sp=1;sp<s;sp=sp+1)
{ printf (" ");
}
s =s+2 ;
for (k=i;k>=1;k--)
if(k!=5)
printf("%d ",k);
printf ("\n");
}
getch();
}
output:
1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1
------------------------------------------------------------------------------------------------------------------------------
Prog28 : prog for numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int n=5;
int i,j;
clrscr();
printf("%d",n);
for (i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
printf("%d", j);
printf ("\n");
}
getch();
}
output
1
12
123
1234
12345
------------------------------------------------------------------------------------------------------------------------------
Prog29 :Prog for displaying 1…10.
# include <stdio.h>
# include <conio.h>
void main()
{
int a[10],i,temp,j;
clrscr();
for(i=0;i<=9;i++)
{
printf("\n enter value one by one :");
scanf("%d",&a[i]);
}
for(i=0;i<=9;i++)
{
for(j=0;j<=i;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<=9;i++)
{
printf("\n %d",a[i]);
}
getch();
}
OUTPUT
1
2
3
4
5
6
7
8
9
10
------------------------------------------------------------------------------------------------------------------------------
Prog30 : prog for numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int n=5;
int i,j;
clrscr();
printf("%d",n);
for (i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
printf("%d", j);
printf ("\n");
}
getch();
}
output
1
12
123
1234
12345
------------------------------------------------------------------------------------------------------------------------------
Prog31 : prog for spiral numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int c=2,i,j,n,k;
clrscr();
printf("enter no= :");
scanf("%d",&n);
for (i=1; i<=n;i++)
for(j=1;j<=n-i;j++)
printf (" ");
for (k=j; k<=n;k++)
{
printf("%3d", c);
}
printf("\n");
}
getch();
}
output
enter no= :3
2
2 2
2 2 2
------------------------------------------------------------------------------------------------------------------------------
Prog32 :prog for arrange space
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,sp,s=0;
clrscr();
for (i=5; i>=1; i--)
{
for(j=1; j<=i; j++)
printf("%d ",j);
for(sp=1;sp<s;sp=sp+1)
{ printf (" ");
}
s =s+2 ;
for (k=i;k>=1;k--)
if(k!=5)
printf("%d ",k);
printf ("\n");
}
getch();
output:
1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1
Prog33 :prog for finding a no whether it is prime or not
#include<stdio.h>
#include<conio.h>
void main()
{
int i=2;
int num;
clrscr();
printf("enter no :-");
scanf ("%d", &num);
while (i<=num-1)
{
if (num%i==0)
{
printf ("not a prime number");
getch();
break;
}
i++;
}
if (i==num)
{
printf ("is a prime number");
getch();
}
}
output
enter no :-17
is a prime number
------------------------------------------------------------------------------------------------------------------------------
Prog34 : Prog for displaying number
#include<stdio.h>
#include<conio.h>
void main()
{
int no=1;
int ans;
clrscr();
while (no<=100)
{
if (no%2==0)
printf ("\t%d", no);
no++;
}
getch();
}
------------------------------------------------------------------------------------------------------------------------------
Prog35 : Prog to display the 1…..99
# include <stdio.h>
# include <conio.h>
void main()
{
int i=1,j=0;
clrscr();
while(j<50)
{
if(i%2!=0)
{
printf("\t %d",i);
j++;
}
i++;
}
printf("\n %d",j);
getch();
}
OUTPUT
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95
97 99
------------------------------------------------------------------------------------------------------------------------------
prog36 : // This programme is to print the series 1,3,5,7,9..... upto 99.
# include "stdio.h"
# include "conio.h"
void main()
{
int i;
clrscr();
i=1;
while(i<=99)
{
printf("\t %d",i);
i=i+2;
}
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog37 : // This programme is to get the number in reverse manner.
# include <stdio.h>
# include <conio.h>
void main()
{
int i,j=0;
clrscr();
printf("Enter the number : ");
scanf("%d",&i);
while(i!=0)
{
j=j*10+(i%10);
i=i/10;
}
printf("%d",j);
getch();
return 0;
}
Prog38 : // This programme is to print the series 1,2,4,7,11..... upto 10 steps.
# include <stdio.h>
# include <conio.h>
void main()
{
int i,v,incr;
clrscr();
i=1;
v=1;
incr=1;
while(i<=10)
{
printf("\t %d",v);
i++;
v=v+incr;
incr=incr+1;
}
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
prog39 : // This programme is to print 1 t0 10 in increment order using Do-while statement.
# include <stdio.h>
# include <conio.h>
void main()
{
int i;
clrscr();
i=1;
do
{
printf("\n %d",i);
i++;
}
while(i<=10);
getch();
return 0;
}
prog 40 : print the reverse no
#incldue<stdio.h>
#include<conio.h>
void main()
{
int no,tmpno=1;
unsigned rev=0;
clrscr();
printf("\nEnter number to reverse it:->");
scanf("%d",&no);
tmpno=no;
while(no>0)
{
rev= rev*10 + no%10;
no /= 10;
}
printf("\n The reverse no is :->%u",rev);
getch();
}
------------------------------------------------------------------------------------------------------------------------------
prog41 : print the multiplication table
#include<stdio.h>
#include<conio.h>
void main()
{
int row,column,y,n;
clrscr();
row=1;
printf("\n Enter any no for multiplication no:->");
scanf("%d",&n);
printf("Multiplication Table\n");
printf("--------------------------------\n");
do
{
column =1;
do
{
y=row*column;
printf("%4d",y);
column=column+1;
}
while(column<=n);
printf("\n");
row=row+1;
}
while(row<=n);
getch();
}
------------------------------------------------------------------------------------------------------------------------------
Prog42 : prog for swith….case statement,
#include<stdio.h>
#include<conio.h>
void main()
{
int i=2;
clrscr();
switch (i)
{
case 1:
printf("this is one \n");
break;
case 2:
printf("this is two \n");
case 3:
printf("this is three \n");
break;
default:
printf("this is default \n");
}
getch();
}
------------------------------------------------------------------------------------------------------------------------------
Prog43 : prog for numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2;
int res;
char op;
clrscr();
printf("Enter the two number :\n");
scanf("%d %d",&n1,&n2);
printf(" Enter the operatpor : ");
fflush(stdin);
scanf("%c",&op);
printf ("%d",calc (n1,n2,op) );
getch();
}
int calc (int i, int j, char ch)
{
switch(ch)
{
case '+' : return(i+j);
case '-' : return(i-j);
case '*' : return(i*j);
case '/' : return(i/j);
}
return (0);
}
------------------------------------------------------------------------------------------------------------------------------
prog 44 : perform add mul sub div using switch
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,res;
char ch;
clrscr();
printf("Enter value of a :->");
scanf("%d",&a);
printf("Enter value of b :->");
scanf("%d",&b);
printf("Enter Operation choice ");
scanf(" %c",&ch);
switch(ch)
{
case '+':
printf("\nAddition is %d", a+b);
break;
case '-':
printf("\nSub is %d", a-b);
break;
case '*':
printf("\nMul is %d", a*b);
break;
case '/':
printf("\nDiv is %d", a/b);
break;
default:
printf("\nSorry ... Pls.. Enter proper choice");
}
getch();
}
------------------------------------------------------------------------------------------------------------------------------
prog 45 :prog for finding a no whether it is prime or not
#include<stdio.h>
#include<conio.h>
void main()
{
int i=2;
int num;
clrscr();
printf("enter no :-");
scanf ("%d", &num);
while (i<=num-1)
{
if (num%i==0)
{ printf ("not a prime number");
getch();
break;
}
i++;
}
if (i==num)
{
printf ("is a prime number");
getch();
}
}
output
enter no :-17
is a prime number
------------------------------------------------------------------------------------------------------------------------------
prog46 : Prog for numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int no=1;
int ans;
clrscr();
while (no<=100)
{
if (no%2==0)
printf ("\t%d", no);
no++;
}
getch();
}
------------------------------------------------------------------------------------------------------------------------------
Prog47 : prog to display 1..3..5 up to 99.
# include <stdio.h>
# include <conio.h>
void main()
{
int i=1,j=0;
clrscr();
while(j<50)
{
if(i%2!=0)
{
printf("\t %d",i);
j++;
}
i++;
}
printf("\n %d",j);
getch();
}
OUTPUT
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95
97 99
------------------------------------------------------------------------------------------------------------------------------
` Prog48 : This programme is to print the series 1,3,5,7,9..... upto 99.
# include "stdio.h"
# include "conio.h"
voidmain()
{
int i;
clrscr();
i=1;
while(i<=99)
{
printf("\t %d",i);
i=i+2;
}
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog49 : // This programme is to get the number in reverse manner.
# include <stdio.h>
# include <conio.h>
main()
{
int i,j=0;
clrscr();
printf("Enter the number : ");
scanf("%d",&i);
while(i!=0)
{
j=j*10+(i%10);
i=i/10;
}
printf("%d",j);
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog50 : This programme is to print the series 1,2,4,7,11..... upto 10 steps
# include <stdio.h>
# include <conio.h>
void main()
{
int i,v,incr;
clrscr();
i=1;
v=1;
incr=1;
while(i<=10)
{
printf("\t %d",v);
i++;
v=v+incr;
incr=incr+1;
}
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog51 : This programme is to print 1 t0 10 in increment order using Do-while statement.
# include <stdio.h>
# include <conio.h>
void main()
{
int i;
clrscr();
i=1;
do
{
printf("\n %d",i);
i++;
}
while(i<=10);
getch();
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
prog52 : print the reverse no
# include <stdio.h>
# include <conio.h>
void main()
{
int no,tmpno=1;
unsigned rev=0;
clrscr();
printf("\nEnter number to reverse it:->");
scanf("%d",&no);
tmpno=no;
while(no>0)
{
rev= rev*10 + no%10;
no /= 10;
}
printf("\n The reverse no is :->%u",rev);
getch();
}
------------------------------------------------------------------------------------------------------------------------------
Prog53 print the multiplication table
#include<stdio.h>
#include<conio.h>
void main()
{
int row,column,y,n;
clrscr();
row=1;
printf("\n Enter any no for multiplication no:->");
scanf("%d",&n);
printf("Multiplication Table\n");
printf("--------------------------------\n");
do
{
column =1;
do
{
y=row*column;
printf("%4d",y);
column=column+1;
}
while(column<=n);
printf("\n");
row=row+1;
}
while(row<=n);
getch();
}
Prog 54 : prog for counting avg of 10 marks
#include<stdio.h>
#include<conio.h>
void main()
{
int marks[10];
int i,sum=0;
float avg;
clrscr();
for (i=0;i<10;i++)
{
printf ("\nEnter marks %d: ",i+1);
scanf ("%d", &marks[i]);
}
for (i=0;i<10;i++)
sum=sum+marks[i];
avg=sum/10.0;
printf("\n\n\n");
printf("avg is %f",avg);
getch();
}
output:
Enter marks 1: 12
Enter marks 2: 13
Enter marks 3: 14
Enter marks 4: 15
Enter marks 5: 16
Enter marks 6: 17
Enter marks 7: 18
Enter marks 8: 19
Enter marks 9: 11
Enter marks 10: 10
avg is 14.500000
prog55 : prog for displaying 10……1 .
# include <stdio.h>
# include <conio.h>
void main()
{
int a[10],i,temp,j;
clrscr();
for(i=0;i<=9;i++)
{
printf("\n enter value one by one :");
scanf("%d",&a[i]);
}
for(i=0;i<=9;i++)
{
for(j=0;j<=i;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<=9;i++)
{
printf("\n %d",a[i]);
}
getch();
}
OUTPUT
10
9
8
7
6
5
4
3
2
1
Prog56 : // program for addition of two matrix
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3];
int i,j,l,m;
clrscr();
printf("Enter the elements in the first matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements in the second matrix\n");
for(l=0;l<3;l++)
{
for(m=0;m<3;m++)
{
scanf("%d",&b[l][m]);
}
}
printf("You have the following numbers into first matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("\nThe Addition of the two matrix are\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
getch();
}
------------------------------------------------------------------------------------------------------------------------------
Prog57 : prog for two dimention array
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[3] [4];
int i,j;
clrscr();
for (i=0; i<3; i++)
{
for(j=0; j<4; j++)
{
printf ("\n Enter a no at[%d] [%d] :", i,j);
scanf ("%d", &arr [i][j]);
}
}
for (i=0; i<3; i++)
{
printf ("\n The no at[%d][%d] is :%d", i,j,arr[i][j]);
}
}
output
Enter a no at[0] [0] :12
Enter a no at[0] [1] :12
Enter a no at[0] [2] :13
Enter a no at[0] [3] :14
Enter a no at[1] [0] :14
Enter a no at[1] [1] :15
Enter a no at[1] [2] :14
Enter a no at[1] [3] :13
Enter a no at[2] [0] :16
Enter a no at[2] [1] :17
Enter a no at[2] [2] :18
Enter a no at[2] [3]
: 12
------------------------------------------------------------------------------------------------------------------------------
Prog58 : DEFINATION:-TO PRINT ARRAY IN THE ASENDING ORDER
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5];
int i,j,temp;
clrscr();
for(i=0;i<5;i++) {
printf("Enter the element [%d]:",i);
scanf("%d",&arr[i]);
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(arr[j]<arr[i])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(i=0;i<5;i++)
{
//printf("the ascending element [%d]:",i);
printf("\n\t %d",arr[i]);
}
getch();
}
OUTPUT
Enter the element [0]:5
Enter the element [1]:4
Enter the element [2]:2
Enter the element [3]:0
Enter the element [4]:1
0
1
2
4
5
PROG 59 :TO PRINT THE AVERAGE OF THE ARRAY ELEMENT
#include<stdio.h>
#include<conio.h>
void main()
{
int stu[5];
int i,n,sum=0;
float Avg;
clrscr();
printf("How many marks are entered");
scanf("%d",&n);
for(i=0;i<5;i++)
{
printf("\n Enter the value of student[i]");
scanf("%d",&stu[i]);
}
for(i=0;i<5;i++)
sum+=stu[i];
printf("%f",sum/5.0);
getch();
}
OUTPUT
Enter the value of student[i]5
Enter the value of student[i]6
Enter the value of student[i]7
Enter the value of student[i]8
Enter the value of student[i]9
7.000000
Prog60 : To find the maximum and minimum number using array.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int num[5];
int i,max,min;
clrscr();
for(i=0;i<5;i++)
{
printf("Enter the value at [%d]:",i);
scanf("%d",&num[i]);
}
max=num[0];
for(i=0;i<5;i++)
{
if(num[i]>max)
max=num[i];
}
min=num[0];
for(i=0;i<5;i++)
{
if(num[i]<min)
min=num[i];
}
printf("\n max value is %d",max);
printf("\n\n min value is %d",min);
getch();
}
OUTPUT
Enter the value at [0]:5
Enter the value at [1]:4
Enter the value at [2]:3
Enter the value at [3]:90
Enter the value at [4]:88
max value is 90
min value is 3
PROG61 : TO SERACH A CHARECTER IN THE ARRAY.
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
void main()
{
char str[15];
char n;
int i=0,c=0;
clrscr();
printf("\n\tEnter the string: ");
gets(str);
printf("\n\tEnter search character: ");
scanf("%c",&n);
while(str[i])
{
if(str[i]==n)
c++;
i++;
}
printf("\n\tIn the string %d times are character are search ",c);
getch();
}
OUTPUT
Enter the string: VIBHAKAR
Enter search character: A
In the string 2 times are character are search
------------------------------------------------------------------------------------------------------------------------------
PROG 62 :Prog for binary search
# include <stdio.h>
# include <conio.h>
int SIZE=10;
void main()
{
int i,j,m,tmp,n,s,a[10],f,l,yn=0;
clrscr();
fflush(stdin);
for (i=0; i<SIZE; i++)
{
printf ("Enter a[%d] element :",i);
scanf("%d",&a[i]);
}
for (i=0; i<SIZE; i++)
{
for (j=i+1; j<SIZE; j++)
{
if (a[i]>a[j])
{
tmp=a[i];
a[i]=a[j];
a[j]=tmp;
}
}
}
printf ("Enter Element to be Found : ");
scanf ("%d",&s);
f=0;
l=SIZE-1;
while (f<=l)
{
m=(f+l)/2;
if (s>a[m])
f=m+1;
else
{
if (s<a[m])
l=m-1;
else
if(s==a[m])
{
yn=1;
break;
}
}
}
if (yn==1)
printf ("\n %d element is Found ",s);
else
printf ("\n %d element is NOT found",s);
getch();
}
OUTPUT
Enter a[0] element :1
Enter a[1] element :2
Enter a[2] element :3
Enter a[3] element :6
Enter a[4] element :4
Enter a[5] element :5
Enter a[6] element :9
Enter a[7] element :5
Enter a[8] element :2
Enter a[9] element :3
Enter Element to be Found : 3
3 element is Found
------------------------------------------------------------------------------------------------------------------------------
Prog 63 :prog for two dimention array
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,*ptr,*ptr1;
clrscr();
ptr = &i;
ptr1 = &j;
printf ("\n Enter number-1 :");
scanf ("%d", &i);
printf ("\n Enter number-2 :");
scanf ("%d", &j);
temp = *ptr;
*ptr = *ptr1;
*ptr1= temp;
printf ("\n Number after swapping ");
printf ("\n The first no is :%d", *ptr);
printf ("\n The second no is :%d", *ptr1);
getch();
}
output
Enter number-1 :13
Enter number-2 :45
Number after swapping
The first no is :45
The second no is :13
------------------------------------------------------------------------------------------------------------------------------
Prog 64 : prog for two dimention array
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,*ptr,*ptr1;
clrscr();
ptr = &i;
ptr1 = &j;
printf ("\n Enter number-1 :");
scanf ("%d", &i);
printf ("\n Enter number-2 :");
scanf ("%d", &j);
temp = *ptr;
*ptr = *ptr1;
*ptr1= temp;
printf ("\n Number after swapping ");
printf ("\n The first no is :%d", *ptr);
printf ("\n The second no is :%d", *ptr1);
getch();
}
output
Enter number-1 :13
Enter number-2 :45
Number after swapping
The first no is :45
The second no is :13
Prog 65 : prog for swaping using pointer
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char i,j,temp,*ptr,*ptr1;
clrscr();
ptr =&i;
ptr1 =&j;
printf ("\n Enter string1 :");
scanf ("%c",&i);
fflush (stdin);
printf ("\n Enter string2 :");
scanf ("%c",&j);
temp =*ptr;
*ptr =*ptr1;
*ptr1=temp;
printf ("\n String after swapping ");
printf ("\n The first string is :%c", *ptr);
printf ("\n The second string is :%c",*ptr1);
getch();
}
output
Enter string1 :qwe
Enter string2 :wer
String after swapping
The first string is :w
The second string is :q
Prog 66 :prog for counting spaces,lines blanks,tabs
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char ch;
int nol=0,not=0,nob=0,noc=0;
fp=fopen("z:\search.c","r");
clrscr();
while(1)
{
ch=fgetc(fp);
if (ch==EOF)
break;
noc++;
if (ch==' ')
nob++;
if (ch=='\n')
nol++;
if(ch=='\t')
not++;
}
fclose(fp);
printf("\n Number of char = %d",noc);
printf("\n Number of blanks = %d",nob);
printf("\n Number of tabs = %d",not);
printf("\n Number of lines = %d", nol);
getch();
return (1);
}
------------------------------------------------------------------------------------------------------------------------------
Prog67 : prog for file handling
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fp,*fc;
char ch;
clrscr();
fp=fopen("z:\\abcd.txt","r");
fc=fopen("z:\\ab.txt","w");
if (fp==NULL) {
puts ("can not find a file please try again");
}
else
{
while((ch=fgetc(fp))!=EOF)
{
fputc(fp);
printf("%c",ch);
}
fclose(fp);
fclose(fc);
}
getch();
}
------------------------------------------------------------------------------------------------------------------------------
Prog 68 : Binary Tree Creation and Traversals
#include <stdio.h>
#include <conio.h>
struct bTreeNode
{
int data;
struct bTreeNode *lChild;
struct bTreeNode *rChild;
};
void main()
{
struct bTreeNode *bt;
int tot,no,i=1;
clrscr();
bt=NULL;
printf("\n Specify no of items : ");
scanf("%d",&tot);
while(i<=tot)
{
printf("\n Enter Data:");
scanf("%d",&no);
insert(&bt,no);
i++;
}
printf("\n Traversing tree in inOrder Traversal :\n");
inOrder(bt);
printf("\n Traversing tree in preOrder Traversal :\n");
preOrder(bt);
printf("\n Traversing tree in postOrder Traversal :\n");
postOrder(bt);
getch();
}
Insert(struct bTreeNode **bRoot,int n){
if (*bRoot == NULL)
{
*bRoot = malloc(sizeof(struct bTreeNode));
(*bRoot)->lChild = NULL;
(*bRoot)->data = n;
(*bRoot)->rChild = NULL;
return;
}
else
{
if (n < (*bRoot)->data)
insert ( &((*bRoot)->lChild),n);
else
insert(&((*bRoot)->rChild),n);
}
return;
}
inOrder(struct bTreeNode *bRoot)
{
if (bRoot!=NULL)
{
inOrder(bRoot->lChild);
printf("%4d",bRoot->data);
inOrder(bRoot->rChild);
}
else
return;
}
preOrder(struct bTreeNode *bRoot)
{
if (bRoot!=NULL)
{
printf("%4d",bRoot->data);
preOrder(bRoot->lChild);
preOrder(bRoot->rChild);
}
else
return;
}
postOrder(struct bTreeNode *bRoot)
{
if (bRoot!=NULL)
{
postOrder(bRoot->lChild);
postOrder(bRoot->rChild);
printf("%4d",bRoot->data);
}
else
return;
}
------------------------------------------------------------------------------------------------------------------------------
prog 69 structure
#include<stdio.h>
#include<conio.h>
#nclude<stdlib.h>
struct raj
{
int code;
char nm[30];
struct raj *r;
};
typedef struct raj node;
nt menu();
oid add();
oid del();
oid view();
ode *fst=NULL,*lst=NULL;
void main()
nt opt=1;
clrscr();
hile(opt!=0)
{
pt=menu();
witch(opt)
case 1: add();
reak;
ase 2: del();
reak;
ase 3: view();
}
int menu()
{
int choice;
lrscr();
printf("\n0...exit");
printf("\n1....add");
printf("\n2....del");
printf("\n3....vie");
rintf("\nwhat is your choice: ");
scanf("%d",&choice);
return(choice);
}
void add()
{
if(fst==NULL) {
fst=lst=(node*)malloc(sizeof(node));
printf("\nenter the node:- ");
scanf("%d",&fst-> code);
printf("enter name:- ");
fflush(stdin);
gets(fst->nm);
fst->r=NULL;
}
else
{
lst->r=(node*)malloc(sizeof(node));
lst=lst->r;
lst->r=NULL;
printf("\nenter the code:- ");
scanf("%d",&lst->code);
printf("\nenter the name :- ");
fflush(stdin);
gets(lst->nm);
}
}
void del()
{
node *dst;
dst=fst;
if(fst==NULL)
{
printf("\nempty queue");
getch();
return;
}
fst=fst->r;
printf("\ndeleted code is = %d",dst->code);
free(dst);
getch();
}
void view()
{
node *vpt;
vpt=fst;
if(vpt==NULL)
{
printf("\n queue is not created ");
getch();
return;
}
while(vpt!=NULL)
{
printf("\ncode:- %d",vpt->code);
printf("\tname:- %s",vpt->nm);
vpt=vpt->r;
}
getch();
}
prog 70 :"program of stack operation"
#include <stdio.h>
#include <conio.h>
struct stack
{
int data;
struct stack *prev;
};
struct stack *node;
void main()
{
int ch,n;
char c;
clrscr();
node=NULL;
printf("\n 1. Push ");
printf("\n 2. Pop ");
printf("\n 3. Display");
printf("\n 4. Exit");
printf("\n Enter your choice (1-4): ");
scanf("%d",&ch);
while(ch>=1&&ch<=4)
{
switch(ch)
{
case 1:
push(node);
break;
case 2:
pop(node);
break;
case 3:
disp(node);
break;
case 4:
exit(0);
}
getch();
clrscr();
printf("\n 1. Push ");
printf("\n 2. Pop ");
printf("\n 3. Display");
printf("\n 4. Exit");
printf("\n Enter your choice (1-4): ");
scanf("%d",&ch);
}
getch();
}
push(struct stack *rec)
{
struct stack *new1;
new1=(struct stack *)malloc(sizeof(struct stack));
printf("\nEnter element to push: ");
scanf("%d",&new1->data);
new1->prev=rec;
node=new1;
return (0);
}
pop(struct stack *rec)
{
node=rec->prev;
free(rec);
return (0);
}
disp(struct stack *rec)
{
while(rec)
{
printf("\n%d",rec->data);
rec=rec->prev;
}
return (0);
}
3 comments:
thanx...
its very helpful to me...
Thank you !
Thank u so much....it is very helpful prog to learn....
Post a Comment