You are on page 1of 54

1)

/* write a program to print


0
01
010
0101
01010
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=5;i++)
{
k=0;
for(j=1;j<=i;j++)
{
printf("%d",k);
if(k==1)
k=0;
else
k=1;
}
printf("\n");
}
getch();
}
Output:
0
01
010
0101
01010
2)
/* write a program to print
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,l;
clrscr();
for(i=71;i>=65;i--)
{
for(l=1;l<=4;l++)
{
printf(" ");
}
for(j=65;j<=i;j++)
{
printf("%c",j);
}
printf("\n");
}
getch();
}
Output:
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A

3)
/*write a program to insert 5 numbers using array find its sum and average*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[5],sum=0;
float avg=1;
clrscr();
for(i=0;i<5;i++)
{
printf("no[%d]=",i);
scanf("%d",&a[i]);
sum=sum+a[i];
avg=(float)sum/5;
}
printf("sum=%d\n",sum);
printf("avg=%.2f",avg);

getch();
}
/* output
no[0]=1
no[1]=2
no[2]=3
no[3]=4
no[4]=5
sum=15
avg=3.00
*/

4)
/* write a program to sort numbers using bubbel sort*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,j,temp=0;
clrscr();
for(i=0;i<=4;i++)
{
printf("enter (%d) no=",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
for(j=i+1;j<=4;j++)
{

if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}

for(i=0;i<=4;i++)
{
printf("%d\n",a[i]);
}
getch();
}
/* output
enter (1) no=9
enter (2) no=5
enter (3) no=42
enter (4) no=6
enter (5) no=2
2
5
6
9
42
*/

5)
/* write a program to count odd numbers from entered numbers.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no,n,o=0;
clrscr();
printf("how many nos.you want to enter =");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
printf("no[%d]=",i);
scanf("%d",&n);
if(n%2!=0)
{
o++;
}
}
printf("odd=%d",o);
getch();
}
/* output
how many nos.you want to enter =5
no[1]=1
no[2]=2
no[3]=5
no[4]=6
no[5]=7
odd=3
*/

6)
/* write a program to convert string in lower case to upper case*/
#include<stdio.h>
#include<conio.h>
void main()
{
char a[30];
int i,l;
clrscr();
puts("enter your string in lower case=");
gets(a);
l=strlen(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]>='a'&&a[i]<='z')
{

a[i]=a[i]-32;
}

}
puts(a);
getch();
}
/* output
enter your string in lower case=
i am learning
I AM LEARNING
*/

7)
/*write a program to find gcd(hcf) and lcm of any two numbers
using function */
#include<stdio.h>
#include<conio.h>
void gcd(int,int);
void main()
{
int n1,n2;
clrscr();
puts("enter no1 ==>");
scanf("%d",&n1);
puts("enter no2 ==>");
scanf("%d",&n2);
gcd(n1,n2);
getch();
}

void gcd(int n1,int n2)


{ int product,temp,lcm;
product=n1*n2;
while(n1>0)
{
if(n1<n2)
{
temp=n1;
n1=n2;
n2=temp;
}
n1=n1%n2;
}
printf("gcd=%d",n2);/*greatest common diviser(gcd)/(hcf)*/
lcm=product/n2;
printf("\nlcm=%d",lcm);
}
/* output
enter no1 ==>
12
enter no2 ==>
18
gcd=6
lcm=36
*/

8)
/*write a program to find gcd(hcf) and lcm of any two numbers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,temp,lcm,product;
clrscr();
puts("enter no1 ==>");
scanf("%d",&n1);
puts("enter no2 ==>");
scanf("%d",&n2);
product=n1*n2;
while(n1>0)
{
if(n1<n2)
{
temp=n1;
n1=n2;
n2=temp;
}
n1=n1%n2;
}
printf("gcd=%d",n2);/*greatest common diviser(gcd)/(hcf)*/
lcm=product/n2;
printf("\nlcm=%d",lcm);
getch();
}
/*output
enter no1 ==>
12
enter no2 ==>
18
gcd=6
lcm=36
*/

9)
/* write a program to find maximum number
from a matrix */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10][10],m,n,p,q,max=0;
clrscr();
printf("no. of raws==>");
scanf("%d",&m);
printf("no. of columns==>");
scanf("%d",&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}

}
printf("\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",a[i][j]);
}
printf("\n");
}
printf("\n\n");
max=a[0][0];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(max<a[i][j])
{
max=a[i][j];
}
}
}
printf("max=%d",max);
getch();
}
/* output
no. of raws==>3
no. of columns==>3
a[0][0]=54
a[0][1]=65
a[0][2]=32
a[1][0]=52
a[1][1]=65
a[1][2]=68
a[2][0]=95
a[2][1]=42
a[2][2]=32

54 65 32
52 65 68
95 42 32

max=95
*/

10)
/* write a program to find maximum number from array of ten numbers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],max=0,i;
clrscr();
for(i=0;i<=9;i++)
{
printf("enter the number:");
scanf("%d",&a[i]);
}
for(i=0;i<=9;i++)
{
printf("a[%d]=%d\n",i,a[i]);
if(max<a[i])
{
max=a[i];
}

}
printf("the maximum is %d",max);
getch();
}
/* output
enter the number:21
enter the number:45
enter the number:26
enter the number:35
enter the number:44
enter the number:66
enter the number:58
enter the number:12
enter the number:32
enter the number:52
a[0]=21
a[1]=45
a[2]=26
a[3]=35
a[4]=44
a[5]=66
a[6]=58
a[7]=12
a[8]=32
a[9]=52
the maximum is 66
*/

11)
/* write a program for enter two matrix and print its multiplication*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10]={0},i,j,k,m,n,p,q;
clrscr();
printf("enter rows of matrix a=");
scanf("%d",&m);
printf("enter columns of matrix a=");
scanf("%d",&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}

}
printf("\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}

printf("\n\n enter rows of matrix b=");


scanf("%d",&p);
printf("enter columns of matrix b=");
scanf("%d",&q);
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("b[%d][%d]=",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("%3d",b[i][j]);
}
printf("\n");
}
printf("\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for(k=0;k<p;k++)
{
c[i][j]+=a[i][k]*b[k][j];

}
printf("multiplication is\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%5d",c[i][j]);
}
printf("\n");
}
getch();
}
/*
output
enter rows of matrix a=2
enter columns of matrix a=3
a[0][0]=1
a[0][1]=2
a[0][2]=3
a[1][0]=4
a[1][1]=5
a[1][2]=6

1 2 3
4 5 6

enter rows of matrix b=3


enter columns of matrix b=2
b[0][0]=4
b[0][1]=2
b[1][0]=5
b[1][1]=3
b[2][0]=1
b[2][1]=6
4 2
5 3
1 6

multiplication is

17 26
47 59
*/

12)
/* write a program to find NCR using function*/
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int no,r,ncr;
clrscr();
printf("enter your n=");
scanf("%d",&no);
printf("enter your r=");
scanf("%d",&r);
ncr=fact(no)/(fact(no-r)*fact(r));
printf("ncr=%d",ncr);
getch();

}
int fact(int x)
{

int i=1;
while(x>0)
{
i=i*x;
x--;
}
return i;
}
/* output
enter your no=5
enter your r=3
ncr=10
*/

13)
/* write a program to count odd numbers,even numbers
and zeros from 5 numbers using array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n[5],i,j,e=0,o=0,z=0;
clrscr();
for(i=0;i<=4;i++)
{
printf("no[%d]=",i+1);
scanf("%d",&n[i]);

if(n[i]==0)
{
z=z+1;
}
else if(n[i]%2==0)
{
e=e+1;
}
else
{
o=o+1;
}
}
printf("even=%d\n",e);
printf("odd=%d\n",o);
printf("zero=%d\n",z);
getch();
}
/* output
no[1]=1
no[2]=0
no[3]=2
no[4]=3
no[5]=4
even=2
odd=2
zero=1
*/

14)
/*write a program to check wheather the number
is prime or consonunt*/
#include<stdio.h>
#include<conio.h>
void prime(int);

void main()
{

int no;
clrscr();
printf("enter your no=");
scanf("%d",&no);
prime(no);
getch();
}
void prime(int x)
{
int i,g=0;
for(i=2;i<=x-1;i++)
{
if(x%i==0)
{
g=1;
break;
}
}
if (g==1)
{
printf("the no is consonunt");
}
else
{
printf("the no is prime");
}

}
/*output
enter your no=7
the no is prime
enter your no=9
the no is consonunt
*/

15)
/*write a program to print reverce string of given string*/
#include<stdio.h>
#include<conio.h>
void main()
{
char s[100],temp;
int i,j,len=0;
clrscr();
puts("enter the string");
gets(s);
for(i=0;s[i]!='\0';i++,len++)
len=i;
for(i=0,j=len-1;i<j;i++,j--)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
puts(s);
getch();
}
/* output
enter the string
string
gnirts
*/
16)
/* write a program to print numbers in reverse
order using array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,j,k;
clrscr();
for(i=0;i<=4;i++)
{
printf("enter your no=");
scanf("%d",&a[i]);
}
printf("\n\n reverse \n");
for(i=4;i>=0;i--)
{
printf("\n %d",a[i]);
}
getch();
}
/* output
enter your no=121
enter your no=23
enter your no=21
enter your no=14
enter your no=25

reverse

25
14
21
23
121
*/

17)
/* write a program to count spaces from the entered string*/
#include<stdio.h>
#include<conio.h>
void main()
{
char s[30];
int i,a=0;
clrscr();
puts("enter your string==>");
gets(s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]==' ')
{
a++;
}

}
printf("there are %d spaces in given string\n",a);
getch();
}
/* output
enter your string==>
i am learning c language
there are 4 spaces in given string
*/

18)
/* write a program to print a following design
enter your no=3
*
12
ABC
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,l,j,k,a=1,b=2,c=3,no;
clrscr();
printf("enter your no=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
for(k=1;k<=40-i;k++)
{
printf(" ");
}
l=65;
for(j=1;j<=i;j++)
{
if(i==j)
{
if(a==i)
{
printf("* ");
a=i+3;
}
else if(b==i)
{
printf("%d ",j);
b=i+3;
}
else
{
printf("%c ",l);
c=i+3;
}
}

else
{
if(a==i)
{
printf("* ");
}
else if(b==i)
{
printf("%d ",j);
}
else
{
printf("%c ",l);
l++;
}
}
}
printf("\n\n");
}
getch();
}
/* output
enter your no=5
*
12
ABC
****
12345
*/

19)
/* write a program to find total wovels,a,e,i,o,u,length,spaces,words and
characters from the string */
#include<stdio.h>
#include<conio.h>
void main()
{
char s[30];
int i,l,cv=0,ci=0,ca=0,cu=0,ce=0,co=0,cw=0,cs=0,cc=0;
clrscr();
puts("enter your string ===>");
printf("\n");
gets(s);
l=strlen(s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='a'||s[i]=='A')
{
ca++;
}
if(s[i]=='e'||s[i]=='E')
{
ce++;
}
if(s[i]=='o'||s[i]=='O')
{
co++;
}
if(s[i]=='i'||s[i]=='I')
{
ci++;
}
if(s[i]=='u'||s[i]=='U')
{
cu++;
}
if(s[i]==' ')
{
cs++;
}
cc=l-cs;
cw=cs+1;
cv=ca+ce+ci+co+cu;
}
printf("\ntotal no of wovel=%d\n",cv);
printf("\ntotal no a=%d\n",ca);
printf("\ntotal no e=%d\n",ce);
printf("\ntotal no i=%d\n",ci);
printf("\ntotal no o=%d\n",co);
printf("\ntotal no u=%d\n",cu);
printf("\ntotal length=%d\n",l);
printf("\ntotal no of space=%d\n",cs);
printf("\ntotal no of words=%d\n",cw);
printf("\ntotal no character=%d\n",cc);
getch();
}
/* output
enter your string ===>

i am learning c language

total no of wovel=9

total no a=4

total no e=2

total no i=2

total no o=0

total no u=1

total length=24
total no of space=4

total no of words=5

total no character=20
*/

20)
/* write a program to find length of the string
without using strlen()*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,l=0;
char c[30];
clrscr();
printf("enter your name=");
scanf("%s",c);
for(i=0;c[i]!='\0';i++)
{
l++;
}
printf("the length of %s is =%d",c,l);
getch();
}
/* output
enter your name=asdfghjkl
the length of asdfghjkl is =9
*/

21)
/* write a program to find sum of 10 numbers
using structure */
#include<stdio.h>
#include<conio.h>
struct emp
{
int no,a;
}abs;
void main()
{
int i;
clrscr();

for(i=0;i<10;i++)
{
printf("enter your no[%d]=",i+1);
scanf("%d",&abs.a);
abs.no=abs.no+abs.a;
}
printf("sum=%d",abs.no);
getch();
}
/* output
enter your no[1]=10
enter your no[2]=20
enter your no[3]=30
enter your no[4]=40
enter your no[5]=50
enter your no[6]=60
enter your no[7]=70
enter your no[8]=80
enter your no[9]=90
enter your no[10]=100
sum=550
*/

22)
/* write a program to find sum of odd numbers
between the given range */
#include<stdio.h>
#include<conio.h>
int sum(int,int);
void main()
{
int a,b;
int i;
clrscr();
printf("enter the starting value=");
scanf("%d",&a);
printf("enter the ending value=");
scanf("%d",&b);
printf("sum=%d",sum(a,b));
getch();
}
int sum(int a,int b)
{
int i,s=0;
for(i=a;i<=b;i++)
{
if(i%2!=0)
{
s=s+i;
}
}
return s;
}
/* output
enter the starting value=100
enter the ending value=200
sum=7500
*/

23)
/* write a program to print string as its length's size
eg. entered string= abc then print abc 3 times */

#include<stdio.h>
#include<conio.h>
void main()
{
char n[30],temp;
int i,j,l;
clrscr();
puts("enter your string=");
gets(n);
l=strlen(n);
printf("\n");
for(i=0,j=i+1;i<l;i++,j++)
{
temp=n[j];
n[j]=n[j+1];
n[j]=temp;
puts(n);
}
getch();
}
/* output
enter your string=
abcd

abcd
abcd
abcd
abcd
*/

24)
/* write a program to print string's possible rottetions
like for space
paces
acesp
cespa
espac
space */
#include<stdio.h>
#include<conio.h>
void main()
{
char n[30],temp;
int i,j,l;
clrscr();
puts("enter your string=");
gets(n);
l=strlen(n);
printf("\n");
for(i=0;i<l;i++)
{
temp=n[0];
for(j=0;j<l-1;j++)
{
n[j]=n[j+1];
}
n[j]=temp;
puts(n);
}
getch();
}
/* output
enter your string=
string

trings
ringst
ingstr
ngstri
gstrin
string
/*

25) 1)Write a program to find the sum of the given series Ar+ar2+ar3+
……..NTERMS.

#include<stdio.h>
#include<conio.h>
void main()
{

int i,j,no,x,a,sum=0,mul=0,mul1=0;
clrscr();
printf("enter the value of no=");
scanf("%d",&no);
printf("enter the value of x=");
scanf("%d",&x);
printf("enter the of a=");
scanf("%d",&a);
for(i=1;i<=no;i++)
{
sum=1;

for(j=1;j<=i;j++)
{
sum=sum*x;
}
mul=a*sum;
printf("\t %d",mul);
mul1=mul1+mul;
}

printf("\n the mul1=%d",mul1);

getch();
}
Output:

enter the value of no=5


enter the value of x=2
enter the of a=4
8 16 32 64 128
the mul1=248

26) 2. Write a program to find the SUM OF 5 NO WITH ARRAY:


#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,sum=0;
clrscr();
for(i=0;i<5;i++)
{
printf("no ");
scanf("%d",&a[i]);
sum=sum+a[i];
}
for(i=0;i<5;i++)
{
printf(" \n value %d is %d",i+1,a[i]);
}
printf("\n the total sum is %d",sum);

getch();
}

OUTPUT:
no 3
no 2
no 5
no 6
no 7

value 1 is 3
value 2 is 2
value 3 is 5
value 4 is 6
value 5 is 7
the total sum is 23

27) Write a program to print given TRINGLE:

1
123
12345
123456

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,l,no,x;
clrscr();
printf("enter the no=");
scanf("%d",&no);
for(i=1,x=1;i<=no;i=i+2,x++)
{
for(l=1;l<=40-x;l++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("%d",j);
}

printf("\n");
}
getch();
}
OUTPUT:
enter the no=6
1
123
12345
123456
28) Write a program to find maximum from given n NO’s.

#include<stdio.h>
#include<conio.h>
void main()
{
int count=0,limit=0,i,num,no,max;
clrscr();
printf("enter the value of limit=");
scanf("%d",&limit);
for(i=1;i<=limit;i++)
{
printf("enter the no=");
scanf("\n %d",&no);

if(max<no)
{
max=no;
}
count=count++;

}
printf("the max no=%d",max);

getch();
}
OUTPUT:

enter the value of limit=4


enter the no=5
enter the no=6
enter the no=7
enter the no=4
the max no=7

29) Write a program to print a fibonaci series of the given n terms.


#include<stdio.h>
#include<conio.h>
void main()
{ int a,b,c,no,i;
clrscr();
printf("enter the vlue of no=");
scanf("%d",&no);
a=1;
b=0;
c=0;
for(i=1;i<=no;i++)
{
c=a+b;
printf(" %d\t",c);
a=b;
b=c;
}
getch();
}
Output:
enter the vlue of no=8

1 1 2 3 5 8 13 21

30) Write a program to print following series


11/1! 22/2! 33/3! 44/4!..........nn/n!

#include<stdio.h>
#include<conio.h>
void main()
{
float i,j,no,pow=0,fact=0;
clrscr();
printf("enter the no=");
scanf("%f",&no);
for(i=1;i<=no;i++)
{
pow=1;
fact=1;
for(j=1;j<=i;j++)
{
pow=pow*i;
fact=fact*j;
}
printf("\t %.2f",mul/mul1);

}
getch();
}
Output:
enter the no=5

1.00 2.00 4.50 10.67 26.04

30) Write a program to print following series:


13 23 33 43 53……………n3

#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,a,b,no,x,sum=0;
clrscr();
printf("enter the no=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{ sum=i*i*i;
printf("\t %d",sum);
}
getch();
}

Output:
enter the no=5
1 8 27 64 125
the mul=225

31) enter the name and pint tringle:


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
int i,j,l,k;
clrscr();
printf("enter your name=");
scanf("%s",&a);
l=strlen(a);
printf("length:%d \n ",l);
for(i=0;i<=l;i++)
{
for(k=0;k<=40-i;k++)
{
printf(" ");
}

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

printf("%c ",a[j]);
}
printf("\n");
}
getch();
}

Output:
enter your name=mitesh
length:6

m
m i
mi t
mite
m ites
mitesh

32) write a program to print a following design


1
22
333
4444
55555

#include<stdio.h>
#include<conio.h>
void main()
{
int l,c,no;
clrscr();
printf("enter the no of line to be printed=");
scanf("%d",&no);
for(l=1;l<=no;l++)
{
for(c=1;c<=l;c++)
{
printf("%d",c);
}
printf("\n");
}
getch();
}
Output:
enter the no of line to be printed=5
1
22
333
4444
55555

33) write a program to print a following design


1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

#include<stdio.h>
#include<conio.h>
void main()
{
int l,c,no,co=0;
clrscr();
printf("enter the no of line to be printed=");
scanf("%d",&no);
for(l=1;l<=no;l++)
{
for(c=1;c<=l;c++)
{
co=co+1;
printf("%3d",co);
}

printf("\n");
}
getch();
}
Output:
enter the no of line to be printed=5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

34) write a program to print a following design


1
2 2
3 3 3
2 2
1
#include<stdio.h>
#include<conio.h>
void main()
{
int l,c,no,k;
clrscr();
printf("enter the no of line to be printed=");
scanf("%d",&no);
for(l=1;l<=no;l++)
{
for(k=1;k<=40-l;k++)
{
printf(" ");
}

for(c=1;c<=l;c++)
{
printf("%3d",l);
}
printf("\n");
}
for(l=no-1;l>=1;l--)
{
for(k=1;k<=40-l;k++)
{
printf(" ");
}

for(c=1;c<=l;c++)
{
printf("%3d",l);
}
printf("\n");
}

getch();
}

Output:
enter the no of line to be printed=3
1
2 2
3 3 3
2 2
1
35)write a program to print a following design
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
#include<stdio.h>
#include<conio.h>
void main()
{
int l,c,no,;
clrscr();
printf("enter the no of line to be printed=");
scanf("%d",&no);
for(l=no;l>=1;l--)
{
for(c=l;c>=1;c--)
{

printf("%3d",c);
}

printf("\n");
}
getch();
}
Output:
enter the no of line to be printed=5
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

36) Write a program to find a average of any 10 number


#include<stdio.h>
#include<conio.h>
void main()
{
int n[9],i;
float avg,sum=0.0;
clrscr();
for(i=0;i<=9;i++)
{
printf("enter no (%d)=",i);
scanf("%d",&n[i]);
}
for(i=0;i<=9;i++)
{
sum=sum+n[i];
}
avg=sum/i+1;
printf("\n \n avg of 10 no=%.2f",avg);
getch();
}

Output:
enter no (0)=5
enter no (1)=6
enter no (2)=7
enter no (3)=4
enter no (4)=3
enter no (5)=2
enter no (6)=3
enter no (7)=4
enter no (8)=5
enter no (9)=3

avg of 10 no=5.40

37) print multiplication table for n given nos


#include<stdio.h>
#include<conio.h>
void main()
{
int i,no,j;
clrscr();
printf("enter the no=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
for(j=1;j<=10;j++)
{

printf("\n %3d*%3d=%3d",i,j,i*j);
}
printf("\n");
}
getch();
}
Output:
enter the no=2

1* 1= 1
1* 2= 2
1* 3= 3
1* 4= 4
1* 5= 5
1* 6= 6
1* 7= 7
1* 8= 8
1* 9= 9
1* 10= 10

2* 1= 2
2* 2= 4
2* 3= 6
2* 4= 8
2* 5= 10
2* 6= 12
2* 7= 14
2* 8= 16
2* 9= 18
2* 10= 20

38) write a program to print a following design (Blink effect)


1
12
123
1234
12345
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no,l,color;
clrscr();
textbackground(6);
textcolor(128);
printf("enter the no=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{ for(l=1;l<=40-i;l++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
cprintf("%d ",j);
}
printf("\n");
}
getch();
}
Ouitput:
enter the no=5
1
12
123
1234
12345

39) write a program to find a given no pallindrome or not?


(121=rev of 121=121 its a pallindrome)
#include<stdio.h>
#include<conio.h>
void main()
{
int no,d,sc,rev=0;
clrscr();
printf("\nenter no(chek for pallinrome)=");
scanf("%d",&no);
sc=no; //second copy of no
while(no>0)
{
d=no%10;
rev=rev*10+d;
no=no/10;
}
if(rev==sc)
{
printf("\n \n %d is pallindrome",sc);
}
else
{
printf("\n \n%d is not pallindrome",sc);
}
getch();
}

Output:

enter no(chek for pallinrome)=121


121 is palindrome

enter no(chek for pallinrome)=132

132 is not pallindrome

40) Write a program to count a even and odd no from an array


#include<stdio.h>
#include<conio.h>
void main()
{
int i,n[10],coe=0,coo=0;
clrscr();
for(i=0;i<=9;i++)
{
printf("enter no (%d)=",i);
scanf("%d",&n[i]);
}
for(i=0;i<=9;i++)
{
if(n[i]%2==0)
{
coe=coe+1;
}
else
{
coo=coo+1;
}

}
printf("the total even no=%2d",coe);
printf("\n the total odd no=%2d",coo);
getch();
}

Output:
enter no (0)=3
enter no (1)=2
enter no (2)=5
enter no (3)=6
enter no (4)=7
enter no (5)=8
enter no (6)=5
enter no (7)=9
enter no (8)=6
enter no (9)=3
the total even no= 4
the total odd no= 6

41) write a program to print a following disign

1
11
111
1111
11111

#include<stdio.h>
#include<conio.h>
void main()
{
int l,c,no;
clrscr();
printf("enter the no of line to be printed=");
scanf("%d",&no);
for(l=1;l<=no;l++)
{
for(c=1;c<=l;c++)
{
printf("1");
}
printf("\n");
}
getch();
}
Output:
enter the no of line to be printed=5
1
11
111
1111
11111

42) write a program to find the reverce of a given no?


(153=rev of 351)
#include<stdio.h>
#include<conio.h>
void main()
{
int no,d,sc,rev=0;
clrscr();
printf("\nenter no(find for reverce)=");
scanf("%d",&no);
sc=no; //second copy of no
while(no>0)
{
d=no%10;
rev=rev*10+d;
no=no/10;
}
printf("\n \n %d is rev",rev);

getch();
}

Output:

enter no(find for reverce)=123


321 is rev

43)write a program to print following disign


*
**
***

#include<stdio.h>
#include<conio.h>
void main()
{
int l,c,no;
clrscr();
printf("enter the no of line to be printed=");
scanf("%d",&no);
for(l=1;l<=no;l++)
{
for(c=1;c<=l;c++)
{
printf("*");
}
printf("\n");
}
getch();
}
Output;
enter the no of line to be printed=4
*
**
***
****

44) write a program to find the sum of digit of a given no?


(153= 1 + 5 + 3 = 9)
#include<stdio.h>
#include<conio.h>
void main()
{
int no,d,sum=0;
clrscr();
printf("\nenter no(find for sum of digit)=");
scanf("%d",&no);
while(no>0)
{
d=no%10;
sum=sum+d;
no=no/10;
}
printf("\n \n %d is sum",sum);

getch();
}

Output:

enter no(find for sum of digit)=453

12 is sum

46)
/*reading and writing contents in a file we want to make a
progaram to copy a.dat file into b.dat file the steps involves are
1. opening a both the file. one to read form and another file in write form.
2. reading a one character from a file a.dat and writing in onto b.dat
untill the end of the a.dat file and then closing the both the file*/
#include<stdio.h>
void main()
{ char c;
FILE *p1,*p2;
p1=fopen("a.dat","r");
p2=fopen("b.dat","w");
while((c=fgetc(p1)!=EOF))
{
fputc(c,p2);
}
fclose(p1);
fclose(p2);
getch();
}

47)
/* Write a program to read a file and display its contents along with
line numbers before each line*/
#include<stdio.h>
void main()
{
FILE *fp;
char ch;
char source[67];
int count = 1;
clrscr();
puts("enter the file name:");
gets(source);
fp=fopen(source,"r");// read only mode for the source file
if(fp==NULL)
{
puts("unable to open the file:");
getch();
exit();
}
clrscr();
printf("file name:%s",source);
printf("\n line:-%d\t",count);
while((ch=getc(fp))!=EOF)
{
if(ch=='\n')
{
count++;
printf("\nline:-%d\t",count);
}
else
{
printf("%c",ch);
}
}
printf("\n press any key...");
getch();
fclose(fp);
}

48)
/* write a program to find the size of a text file without traversing
it characterby character*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
struct entry
{
char fname[8];
char ext[3];
char unusual[17];
long int size;
};
struct entry e[16];
int i,j,c;
char yname[8];
char ch=1,len,len1;
clrscr();
absread(0,1,5,e);
for(i=0;i<16;i++)

printf("%s %s %d\n",e[i].fname,e[i].ext,e[i].size);

printf("enter the filename whose size is to be found");


scanf("%s",&yname);
len1=len=strlen(yname);
i=0;
while(i<16)
{
while(len--!=0)
{
if(e[i].fname[len]==yname[len])
ch=0;
else
{
ch=1;
break;
}
}
if(ch==0&&len==-1)
break;
len=len1;
i++;
}
if(ch==0)
{
printf("%s",e[i].fname);
printf("\t%ld bytes",e[i].size);
}
else
printf("h");
getch();
}

49)
/* write a program to copy one file to another.
while doing so replace all lower case characters to
their equivalent uppercase characters*/

/* program to copy one text file to another and


replace all lower case characters to upper case*/
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fs,*ft;
char ch;
char source[67],target[67];
clrscr();
puts("enter source file name:");
gets(source);
puts("enter target file name:");
gets(target);
fs=fopen(source,"r");/* read only mode for source file*/
if(fs==NULL)
{
puts("unable to open file");
getch();
exit();
}
ft=fopen(target,"w+");/* write /modify mode for target file*/
if(ft==NULL)
{
fclose(fs);
puts("unable to open target file");
getch();
exit();
}
while(1)
{
ch=fgetc(fs);
if(ch==EOF)
break;
else
{
/* replace the lower case character
by upper case character*/
if(islower(ch))
fputc(toupper(ch),ft);
else
fputc(ch,ft);
}
}
printf("\n file copied!!");
fclose(fs);
fclose(ft);
getch();
}

50)
/* suppose a file contains students recotrdes with each
records wioth each record containing name and age of a student
write a program to read these records and dispaly them in
sorted order by name*/

/* to read records from a file and display them in


ascending order of names*/
/* note that STUDENT.DAT file is already created
and data written in it using fwrite()*/
#include<stdio.h>
void main()
{
FILE *fp;
struct stud
{
char name[40];
int age;
};
struct stud s, stud[10],temp;
int n,j,k,ii;
clrscr();
fp=fopen("STUDENT.DAT","rb");
n=0;
while(fread(&s,sizeof(s),1,fp)==1)
{
stud[n]=s;
n++;
}
for(j=0;j<n-1;j++)
{
for(k=j+1;k<n;k++)
{
if(strcmp(stud[j].name,stud[k].name)>0)
{
temp=stud[j];
stud[j]=stud[k];
stud[k]=temp;
}
}
}
fclose(fp);
for(j=0;j<n;j++)

printf("\name:%s ,age,:%d",stud[j].name,stud[j].age);
printf("\n\n\n\n\n press any key to exit....");
getch();
}

51)
/* suppose a file contains students recotrdes with each
records wioth each record containing name and age of a student
write a program to read these records and dispaly them in
sorted order by name*/

/* to read records from a file and display them in


ascending order of names*/
/* note that STUDENT.DAT file is already created
and data written in it using fwrite()*/
#include<stdio.h>
void main()
{
FILE *fp;
struct stud
{
char name[40];
int age;
};
struct stud s, stud[10],temp;
int n,j,k,ii;
clrscr();
fp=fopen("STUDENT.DAT","rb");
n=0;
while(fread(&s,sizeof(s),1,fp)==1)
{
stud[n]=s;
n++;
}
for(j=0;j<n-1;j++)
{
for(k=j+1;k<n;k++)
{
if(strcmp(stud[j].name,stud[k].name)>0)
{
temp=stud[j];
stud[j]=stud[k];
stud[k]=temp;
}
}
}
fclose(fp);
for(j=0;j<n;j++)

printf("\name:%s ,age,:%d",stud[j].name,stud[j].age);
printf("\n\n\n\n\n press any key to exit....");
getch();
}

52)
Write a program to print following series:
enter the no=5
1.00 +0.50 +0.33 +0.25 +0.20 +=5.00

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no;
float sum=0,mul=1;
clrscr();
printf("enter the no=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
mul=1;
for(j=1;j<=i;j++)
{
mul=(float)1/i;
sum=sum+mul;
}
printf("%.2f ",mul);

}
printf("=%.2f",sum);
getch();
}
output:
enter the no=5
1.00 +0.50 +0.33 +0.25 +0.20 +=5.00
53)
Write a program to print following series:
enter the no=5
1 +2 +6 +24 +120 +=153

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no;
int sum=0,mul=1;
clrscr();
printf("enter the no=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
sum=0;
mul=1;
for(j=1;j<=i;j++)
{
mul=mul*j;
sum=sum+mul;
}
printf("%d +",mul);

}
printf("=%d",sum);
getch();
}
output:
enter the no=5
1 +2 +6 +24 +120 +=153

54)
Write a program to print following series:
enter the no=5
1 +11 +111 +1111 +11111 +=12345

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no;
int sum=0,mul=1;
clrscr();
printf("enter the no=");
scanf("%d",&no);

for(i=1;i<=no;i++)
{
sum=0;
mul=0;
for(j=1;j<=i;j++)
{
mul=mul*10+1;
sum=sum+mul;
}
printf("%d +",mul);

}
printf("=%d",sum);
getch();
}
output:
enter the no=5
1 +11 +111 +1111 +11111 +=12345

55)
Write a program to print following series:
enter the no=5
enter the value of x=2
2 +4 +8 +16 +32 +=62

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no,x,sum=0,mul=1;
clrscr();
printf("enter the no=");
scanf("%d",&no);
printf("enter the value of x=");
scanf("%d",&x);
for(i=1;i<=no;i++)
{
sum=0;
mul=1;
for(j=1;j<=i;j++)
{
mul=mul*x;
sum=sum+mul;
}
printf("%d +",mul);

}
printf("=%d",sum);
getch();
}
output:
enter the no=5
enter the value of x=2
2 +4 +8 +16 +32 +=62

56)
Write a program to print following series:
enter the no=5
1 +4 +27 +256 +3125 +=3905

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no,x,sum=0,mul=1;
clrscr();
printf("enter the no=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
sum=0;
mul=1;
for(j=1;j<=i;j++)
{
mul=mul*i;
sum=sum+mul;
}
printf("%d +",mul);
}
printf("=%d",sum);
getch();
}

output:
enter the no=5
1 +4 +27 +256 +3125 +=3905

You might also like