Professional Documents
Culture Documents
CP I Modified
CP I Modified
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum;
printf(Enter any two numbers\n);
scanf(%d%d,&a,&b);
sum=a+b;
printf(The sum of a and b is :%d,sum);
getch();
OUTPUT:
Enter any two numbers
2
3
The sum of a and b is : 5
int r;
float circle;
printf(Enter the radius of the circle\n);
scanf(%d,&r);
circle=3.14*r*r;
printf(The area of the circle is:%f\n,circle);
getch();
OUTPUT:
Enter the radius of the circle
10
The area of the circle is:314.000000
OUTPUT:
Enter any three numbers: 10
40
30
B is big
int year;
printf(Enter the year);
scanf(%d,&year);
if(year%4==0)
{
printf(Given the year is leap year\n);
}
else
{
printf(Given the year is not a leap year\n);
}
getch();
}
OUTPUT:
Enter the year
2012
Given the year is leap year
Enter the year
2010
Given the year is not a leap year
OUTPUT:
Enter the celius value:28
The fahrenheit value of the given 28.000000 Celsius value is
82.400002
int n;
printf("Enter any numbers\n);
scanf("%d",&n);
if(n%2==0)
{
printf("Given number is Even\n);
}
else
{
printf("Given number is Odd\n);
}
getch();
OUTPUT:
Enter any numbers
5
Given number is Odd
Enter any numbers
6
Given number is Even
#include<stdio.h>
#include<conio.h>
void main()
{
int n,square;
printf("Enter any numbers\n);
scanf("%d",&n);
square=n*n;
printf("The square of the given number is :%d\n,square);
getch();
OUTPUT:
Enter any numbers
4
The square of the given number is: 16
OUTPUT:
Enter the numbers
153
Given number is an Amstrong
OUTPUT:
Enter the numbers:6
The factorial value is:720
OUTPUT:
Enter the value A:5
Enter the value of B:20
Enter the value of C:6
The Root 1 value is:-0.326680
The Root 2 value is:3.673320
Enter the value A:20
Enter the value of B:6
Enter the value of C:5
The Roots are imaginary
Enter the value A:4
Enter the value of B:4
Enter the value of C:1
The Root 1 value is:-0.500000
The Root 2 value is:0.500000
OUTPUT:
Enter the number:345
Reverse of given number is 543
OUTPUT:
Enter the number
12345
The sum of digits of a given number is :15
");
temp=i;
for(j=1;j<=i;j++)
printf("%4d",temp++);
temp=temp-2;
for(j=1;j<i;j++)
printf("%4d",temp--);
printf("\n\n");
}
getch();
}
OUTPUT:
Enter the number of lines to print:5
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
OUTPUT:
Lagest & Smallest of an array
------------------------------In how many numbers do u want to find:5
Enter the elements of the array:12
34
56
87
43
The Elements Of The Array:
12 34 56 87 43
The largest of the given array is 87
The smallest of the given array is 12
OUTPUT:
Enter the no. of elements for the array:5
Enter the numbers:10
30
50
60
20
The ascending order of the given numbers60
50
30
20
10
The descending number of the given numbers10
20
30
50
60
MATRIX ADDITION
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,row,col;
clrscr();
printf("Enter the row Size:");
scanf("%d",&row);
printf("Enter the column Size:");
scanf("%d",&col);
printf("Enter the A matrix:");
for (i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the B matrix:");
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
OUTPUT:
Enter the row Size:3
Enter the column Size:3
Enter the A matrix:1
2
3
4
5
6
7
8
9
Enter the B matrix:1
2
3
4
5
6
7
8
9
A matrix :
1
B matrix :
10
12
14
16
18
MATRIX MULTIPLICATION
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,row,col;
clrscr();
printf("Enter the row Size:");
scanf("%d",&row);
printf("Enter the column Size:");
scanf("%d",&col);
printf("Enter the A matrix:");
for (i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the B matrix:");
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
c[i][j]=0;
for(k=1;k<=row;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\nA matrix-");
for(i=1;i<=row;i++)
{
printf("\t");
for(j=1;j<=col;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\nB matrix-");
for(i=1;i<=row;i++)
{
printf("\t");
for(j=1;j<=col;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("The multiplication of two matrix is:\n");
for(i=1;i<=row;i++)
{
printf("\t");
for(j=1;j<=col;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();}
OUTPUT:
Enter the row Size:3
Enter the column Size:3
Enter the A matrix:1
2
3
4
5
6
7
8
9
Enter the B matrix:1
2
3
4
5
6
7
8
9
A matrix1
B matrix-
36
42
66
81
96
102
126
150
Transpose of a Matrix
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[25][25],row,col;
clrscr();
printf("\nEnter the number of rows and columns for the
matrix:");
scanf("%d%d",&row,&col);
printf("Enter the elements of the matrix:");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
scanf("%d",&a[i][j]);
}
printf("The given matrix-\n");
for(i=0;i<row;i++)
{
printf("\n");
for(j=0;j<col;j++)
printf("\t%d",a[i][j]);
}
printf("\n\nThe transpose of the given matrix-\n");
for(i=0;i<row;i++)
{
printf("\n");
for(j=0;j<col;j++)
printf("\t%d",a[j][i]);
}
getch();
}
OUTPUT:
Enter the number of rows and columns for the matrix:3
3
Enter the elements of the matrix:1
2
3
4
5
6
7
8
9
The given matrix1
printf("Division:%d\n",c);
break;
case 5:
exit(0);
break;
default:
printf("Invalid operation code");
}
getch();
}
OUTPUT:
--MENU-1.ADDITION
2.SUBTRACTION
3.MULTIPLICATION
4.DIVISION
5.EXIT
Enter your choice:1
Enter two numbers:3
4
Addition:7
--MENU-1.ADDITION
2.SUBTRACTION
3.MULTIPLICATION
4.DIVISION
5.EXIT
Enter your choice:
2
Enter two numbers:7
3
Subtraction:4
--MENU-1.ADDITION
2.SUBTRACTION
3.MULTIPLICATION
4.DIVISION
5.EXIT
Enter your choice:3
Enter two numbers:4
5
Multiplication:20
--MENU-1.ADDITION
2.SUBTRACTION
3.MULTIPLICATION
4.DIVISION
5.EXIT
Enter your choice:
4
Enter two numbers:20
4
Division:5
OUTPUT:
Enter the No. of students:4
Enter the student details
Enter the roll no ,name and mark:
Student 1
1
Mani
80
Student 2
2
Shankar
56
Student 3
3
Anu
97
Student 4
4
Deepika
76
Student details are:
Rollno
Name
Marks
mani
80
Shankar
56
anu
97
Deepika
76
IMPLEMENTATION OF UNION
#include<stdio.h>
#include<conio.h>
union marks
{
float perc;
char grade;
};
void main()
{
union marks student;
stud.perc=98.5;
stud.grade='A';
clrscr();
printf("\nMark %f stored in address %lu\n",stud.perc,
&stud.perc);
printf("\nGrade %c is stored in address%lu\n",stud.grade,
&stud.grade);
getch();
}
OUTPUT:
Mark 98.500496 is stored in address 4325362
Grade A is stored in address 4325362
y=
%d\n",x,y);
display(x,y);
getch();
}
display(int a,int b)
{
int t;
t=a;
a=b;
b=t;
printf("\nAfter swapping\n\nThe value of x=%d y=%d",a,b);
}
OUTPUT:
Enter the two numbers:3
5
Before Swapping
The value of x=3 y=5
After swapping
The value of x=5 y=3
OUTPUT:
Enter the two numbers: 3 4
Before Swapping
The value of x=3
y=4
After swapping
The value of x=4
y=3