1.
Write a program to find whether the given character is
vowel or consonant
Vowel or Consonant:
#include<stdio.h>
void main()
{
char ch;
clrscr();
printf("\n enter the character:");
scanf("%c",&ch);
if((ch>=65&&ch<=122))
{
if((ch=='a')||(ch=='e')||(ch=='i')||(ch=='o')||(ch=='u'))
printf("\n given is characteris vowel");
else
printf("\n enter character is consonant");
}
else
printf("\n please enter the character:");
}
Output:
Enter the character: a
Given is character is vowel
Enter the character:
Please enter the character:
Enter the character: r
Enter character is consonant
2. Write
a program to implement all arithmetic operations (+ , -, * , / , %). Using
Switch Statement
(+ , -, * , / , %)
#include<stdio.h>
main()
{
int
a,b,opt;
clrscr();
printf(“Enter A
and B valves:”);
scanf(“%d%d”,&a,&b);
printf("1.
Addition\n 2.Subtraction \n 3. Multiplication \n 4. Division \n 5.
modules:");
printf("Enter
ur option:");
scanf("%d",&opt);
switch(opt)
{
case 1:
printf("\n
Addition is %d+%d=%d",a,b,a+b);
break;
case 2:
printf("\n
subtraction is %d-%d=%d",a,b,a-b);
break;
case 3:
printf("\n
multiplication is %d*%d=%d",a,b,a*b);
break;
case 4:
printf("\n
division is %d/%d=%d",a,b,a/b);
break;
case 5:
printf("\n
modules is %d and %d=%d",a,b,(a%b));
default:
printf("Invalid
option");
}
Output:
Enter A and B values: 20 10
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modules
Enter your option:1
Addition of 20 and 10 is: 30
Enter A and B values: 20 10
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modules
Enter your option:2
subtraction of 20 and 10 is: 10
Enter A and B values: 20 10
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modules
Enter your option:3
multiplication of 20 and 10 is:
200
Enter A and B values: 20 10
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modules
Enter your option:4
Division of 20 and 10 is: 2
Enter A and B values: 20 10
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modules
Enter your option:4
Division of 20 and 10 is: 0
3. Program to
check given number is strong or not
#include
<stdio.h>
Main()
{
Int i,n,r,f,d,sum=0;
Printf(“enter n
value”);
Scanf(“%d”,&n);
D=n;
While(n!=0)
{
R=n%10;
For(i=r,f=1;i>=1;i--)
F=f*I;
Sum=sum+f;
N=n/10;
}
If(sum==d)
Printf(“%d is strong”,d);
Else
Printf(“%d is not
strong”);
}
Output:
Enter n value: 145
145strong
4. Program to check given no is
prime or not
Prime or not
#include <stdio.h>
main()
{
int n,i,s=0;
clrscr();
printf("\n enter n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
if(n%i==0)
s=s+1;
if(s==2)
printf("\n prime:");
else
printf("\n not prime:");
getch();
}
Output:
Enter n value
: 23
Given number is prime.
Enter n value :5
Given number is prime
Enter n value :11
Given number is prime
5. program check whether no is
palindrome or not
Palindrome or not
#include<stdio.h>
main()
{
int n,r,sum=0,d;
clrscr();
printf("\n enter n
value:");
scanf("%d",&n);
d=n;
while(n!=0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
if(d==sum)
printf("\n given no is %d is
paliendrome:",d);
else
printf("\n given no is not
pailndrome:",sum);
}
Output:
Enter n value: 121
121 is
palindrome
Enter n value :203
203 is palindrome
Enter n
value: 333
333 is palindrome.
Enter n value : 151
151 is palindrome
6. program to find whether the given number is perfect
or not
perfect or not
#include<stdio.h>
main()
{
int i,n,sum=0;
clrscr();
printf("\n enter n”);
scanf(“%d”,&n);
for(i=1;ni<=n-1;i++)
if(n%i==0)
sum=sum+I;
if(sum==n)
printf(“%d is perfect”,n);
else
printf(“%d is not perfect”,n);
}
Enter n value: 6
6 is perfect
Enter n value
:28
28 is
perfect
Enter n value
:496
496 is
perfect
Enter n value:8
8 is not perfect
7. program print nth multiplication table
#include<stdio.h>
main()
{
int n,i;
clrscr();
printf("\n enter n
value:");
scanf("%d",&n);
for(i=1;i<=10;i++)
printf("\n
%d*%d=%d",n,i,(n*i));
}
Output:
Enter n value: 4
4*1=4
4*2=8
4*3=12
4*4=16
4*5=20
4*6=24
4*7=27
4*8=32
4*9=36
4*10=40
8. print armstrong numbers below
1000
Armstrong numbers
#include<stdio.h>
main()
{
int n,i,r,sum,d;
clrscr();
printf("\n armstrong below
1000:");
for(i=0;i<1000;i++)
{
sum=0;
d=i;
n=i;
while(n!=0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
Output:
1
153
370
371
407
9. Program to print
perfect number below
1000
perfect number
below 1000
#include <stdio.h>
Main()
{
Int I,n,sum;
Printf(“1 to 1000 perfect number”);
For(n=0;n<1000;n++)
{
Sum=0;
For(i=1;i<=n-1;i++)
If(n%i==0)
Sum=sum+I;
If(sum==n)
Printf(“%d\t”,n);
}
}
Output:
6 28 496
10. program to print below 1000
odd numbers
#include<stdio.h>
main()
{
int i;
clrscr();
printf("\n odd no below
1000:");
for(i=1;i<1000;i++)
if(i%2!=0)
printf("%d\t",i);
}
Output:
1 3 5 7 11 13 17 19 21 23 25 29 31
33 35 37 41 43 47 51 53 57 59 61 63 67
69 71 73 75 79 81 83 85 87 91 93 95 97
99 101
11. program print the following
format
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
#include<stdio.h>
main()
{
int n,i,j,sum;
clrscr();
printf("\n how many rows do
u want:");
scanf("%d",&n);
sum=1;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("\t%d",sum++);
printf("\n");
}
}
Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
12. Program to print the following format
A
B C
D E F
G H I J
K L M N O
#include <stdio.h>
Main()
{
Int I,j,n,sum=65;
Printf(“no of rows”);
Scanf(“%d”,&n);
For(i=1;i<=n;i++)
{
For(j=1;j<=I;j++)
Printf(“%c”,sum++);
Printf(“\n”);
}
}
Output:
A
B C
D E F
G H I J
K L M N O
13. Write program to find
factorial of a given number using
recursions
#include<stdio.h>
Void main()
{
Int n;
Printf(“enter n”);
Scanf(“%d”,&n);
Printf(“factorial of %d is
%d”,n,fact(n));
}
Int fact(int n)
{
If((n==0)||(n==1))
Return 1;
Else
Return(n*fact(n-1));
}
Output:
Enter n 5
Factorial of 5 is 120
Enter n 2
Factorial of 2 is 2
14. Write a program to print Fibonacci series using recursions
#include<stdio.h>
void main()
{
int ft=0,st=1,n;
clrscr();
printf("enter n");
scanf("%d",&n);
printf("Fibnocci series\n");
printf("%5d%5d",ft,st);
fibo(ft,st,n);
}
fibo(int ft,int st,int n)
{
int tt=ft+st;
if(tt<=n)
{
printf("%5d",tt);
fibo(st,tt,n);
}
}
Output:
Enter n
5
Fibonacci series:
0 1
1 2 3
5
2.enter n
8
Fibonacci series:
0 1
1 2 3
5 8
15. Write a program to add two
numbers using recursions
#include<stdio.h>
void main()
{
int a,b;
printf("enter a,b");
scanf("%d%d",&a,&b);
printf("sum of %d and %d is
%d",a,b,sum(a,b));
}
int sum(int a,int b)
{
if(b==0)
return a;
else
sum(a+1,b-1) ;
}
OUTPUT:
1.
Enter a,b
231
569
Sum of 231 and
569 is 800
2.
Enter a,b
6
9
Sum of 6 and 9
is 15
3.
enter a,b
6
0
Sum of 6 and 0 is
6
16. Write a program to find
whether the given string is palindrome or not
#include<stdio.h>
void main()
{
char st1[10],st2[10];
printf("enter a string");
gets(st1);
strcpy(st1,st2);
if(strcmp(st1,strrev(st2)==0))
printf("given string is palindrome");
else
printf("given string is not
palindrome");
}
output:
1.enter a string
Malayalam
Given string is
palindrome
2.enter a string
Teacher
Given string is
not palindrome
17. Write a program
to perform all string handling functions
#include<stdio.h>
void main()
{
char st[10],st1[10],st2[10];
clrscr();
printf("enter a string");
gets(st);
printf("enter a string");
gets(st1);
printf("\n string comparision is");
if(strcmp(st,st1)==0)
printf("two strings are equal");
else
if(strcmp(st,st1)>0)
printf("%s is big",st);
else
printf("%s is big",st1);
printf("\n length of string is
%d",strlen(st));
printf("\nucase of string is
%s",strupr(st));
printf("\nlcase of string is
%s",strlwr(st));
strcpy(st2,st);
printf("\n copy of first string is
%s",st2);
printf("\nconcatenation of a stirng is
%s",strcat(st2,st1));
printf("\nreverse of string is
%s",strrev(st));
}
Output:
18. Write a program to
print sum of array
#include <stdio.h>
main()
{
int a[10],i,n,sum=0;
printf("enter array
size");
scanf("%d",&n);
printf("enter elements
into array);
for(i=0;i<=(n-1);i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
printf("sum of given
arrray elements is %d”,sum);
}
1 . Enter array size
5
Enter elements into array
1
2
3
4
5
Sum of given array elements is 15
2. Enter array size
4
Enter elements into array
10
20
30
40
Sum of given array elements is
100
19. Write a to serach an
element in an array using linear search
. #include <stdio.h>
main()
{
int a[10],i,n,sr;
printf("enter array
size");
scanf("%d",&n);
printf("enter elements
in an array");
for(i=0;i<=(n-1);i++)
scanf("%d",&a[i]);
printf("enter element
to be search");
scanf("%d",&sr);
for(i=0;i<=(n-1);i++)
if(a[i]==sr)
{
printf("%d is found at
position",sr,i+1);
break;
}
if(i==n)
printf("%d is not
found",sr);
}_
OUTPUT:
1.Enter
array size
5
Enter
elements into array
10
12
14
16
18
Enter
element to search
16
16
is found at position 4
1. Enter array size
3
Enter elements into array
50
60
40
Enter element to search 80
80 is not found
21. Write program to
perform matrix multiplication using function
#include <stdio.h>
main()
{
int a[10][10],
b[10][10],c[10][10],m,n,p,q;
clrscr();
printf(" enter size of matrix A");
scanf("%d%d",&m,&n);
printf("enter size of
matrix B");
scanf("%d%d",&p,&q);
if(n==p)
{
printf(" enter element into matrix A");
readmatrix(a,m,n);
printf("enter element into matrix B");
readmatrix(b,p,q);
matmul(a,b,c,m,n,q);
printf("elements in
A:\n");
printmatrix(a,m,n);
printf("elements in
B:\n");
printmatrix(b,p,q);
printf(”Multiplication of A
and B is:\n");
printmatrix(c,m,q);
}
else
printf("matrix
multiplication is not possible");
}
readmatrix(int
x[10][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&x[i][j]);
}
matmul(int x[10][10],int
y[10][10],int z[10][10],int m,int n,int q)
{
int i,j,k;
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
z[i][j]=0;
for(k=0;k<n;k++)
z[i][j]=z[i][j]+x[i][k]*y[k][j];
}
}
printmatrix(int
x[10][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%5d",x[i][j]);
printf("\n");
}
}
OUTPUT :
Enter size of matrix A
2
2
Enter
size of matrix B
2
3
Enter
elements into matrix A_
1
2
3
4
Enter
elements into matrix B
5
6
7
8
9
10
Elements
in A:
1
2
2
4
Elements in B:
5 6 7
8 9 10
Multiplication of A and B matrix is:
21 24 27
47 54 61
Enter size of matrix A 2 2
Enter size of matrix B 3 2
Matrix multiplication is not possible
22. program to perform
addition of two matrices using function
#include <stdio.h>
main()
{
int
a[10][10],b[10][10],c[10][10],m,n,p,q;
printf("enter size of
matrix A");
scanf("%d%d",&m,&n);
printf("enter size of
matrix B");
scanf("%d%d",&p,&q);
if((m==p)&&(n==q))
{
printf("enter elements
in A");
readmatrix(a,m,n);
printf("enter elements
in B");
readmatrix(b,p,q);
matadd(a,b,c,m,n);
printf("elements in
A:\n");
printmatrix(a,m,n);
printf("elements in
B:\n");
printmatrix(b,p,q);
printf("Multiplication
of A and B :\n");
printmatrix(c,m,n);
}
else
printf("add is not possible");
}
readmatrix(int
x[10][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&x[i][j]);
}
matadd(int x[10][10],int
y[10][10],int z[10][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
z[i][j]=x[i][j]+y[i][j];
}
}
printmatrix(int
x[10][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%5d",x[i][j]);
printf("\n");
}
}
OUTPUT :
1. Enter size of matrix A 2 2
Enter size of matrix B
2 2
Enter elements in A
1
2
3
4
5
9
2
4
Elements in A:
1
2
2
4
Elements in B:
5 9
3
4
Addition of A and B:
6 11
5 8
23.
Write a program to create student
structure and the members of a student
struct student
{
int sno;
char sname[10];
};
void main()
{
struct student s[10];
int i,n;
clrscr();
printf("enter no.of
students");
scanf("%d",&n);
printf("enter studentnumber and
studentname");
for(i=0;i<n;i++)
scanf("%d%s",&s[i].sno,s[i].sname);
printf("students information
is:\n");
for(i=0;i<n;i++)
printf("\n %d
%s",s[i].sno,s[i].sname);
}
Enter no of
students :3
Enter studentno
and studentname:
101 varun
102 deepthi
103 manoj
Student
information is :
101 varun
102 deepthi
103 manoj
No comments: