Practical Mannual PCT
Practical Mannual PCT
Practical No. 01
Aim: Write algorithm and draw flow chart for following problems:
(a) Addition of two numbers
(b) Exchange value of two variables
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Step 1: Start
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 6: Stop
Step 1: Start
Step 4: C=A
Step 5: A=B
Step 6: B=C
Step 7: Print A
Step 8: Print B
Step 9: Stop
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 1
Government Polytechnic Amravati Practical Manual
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 2
Government Polytechnic Amravati Practical Manual
#include <stdio.h>
void main()
{
int A, B, sum;
sum = A + B;
printf("Sum of Numbers %d + %d = %d", A,B, sum);
return 0;
}
#include<stdio.h>
void main()
{
int a,b,c;
printf("a:");
scanf("%d", &a);
printf("b:");
scanf("%d", &b);
c=a;
a=b;
b=c;
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 3
Government Polytechnic Amravati Practical Manual
Sum of Numbers 20 + 10 = 30
Result:
Thus, we perform the program for Addition of two numbers and Exchange value of two variables.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 4
Government Polytechnic Amravati Practical Manual
Practical No. 02
Aim: Write a „C‟ program to display hexadecimal, decimal, octal format of entered number using
%d, %c, %i, %f, %g, %u, %o, %s, %x
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
#include<stdio.h>
void main()
{
int n;
printf("Enter a number: ");
scanf("%d",&n);
Output:
Enter a number: 45
Decimal value: 45
Octal value: 55
Result:
Thus, we perform the „C‟ program to display hexadecimal, decimal, octal format of entered number
using %d, %c, %i, %f, %g, %u, %o, %s, %x.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 5
Government Polytechnic Amravati Practical Manual
Practical No. 03
Aim: Write a program to perform following operations:
a) First input name, address, date of birth and email_id using scanf() function and then display the
same using printf ( ) function.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
#include <stdio.h>
void main()
{
char name[20], address[20], email[30];
int DOB;
Output:
Daddy
Home
1021950
[email protected]
Result:
Thus, we perform the „C‟ program to display a) First input name, address, date of birth and email_id
using scanf() function and then display the same using printf ( ) function.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 6
Government Polytechnic Amravati Practical Manual
Practical No. 04
Aim: (a) Write a program to calculate Inductive Resistance (FL)
with the help of given formula FL = 2 * π*f L. Where π, f, L are given data.
(b) Write a program to calculate Capacitive Resistance (FC)
with the help of given formula FC = 1/(2 * π*f C). Where π, f, C are given data.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
#include <stdio.h>
void main()
{
float f, L, FL;
FL = 2*3.14*f*L;
printf("The Calculated Inductive Resistance (FL) is %f. ", FL);
return 0;
}
#include <stdio.h>
void main()
{
float f, C, FC;
FC = 1/(2*3.14*f*C);
printf("The Calculated Capacitive Resistance (FC) is %f .", FC);
return 0;
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 7
Government Polytechnic Amravati Practical Manual
Result:
Thus, we perform the „C‟ program to calculate (a) Inductive Resistance (FL) & (b) Capacitive
Resistance (FC).
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 8
Government Polytechnic Amravati Practical Manual
Practical No. 05
Aim: (a) Write a C program to find the sum of individual digits of a positive integer.
(b) Write a C program to find whether entered number is prime or not.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code: (a) Write a C program to find the sum of individual digits of a positive integer.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0;
while(n>0)
{
sum=sum+n%10;
n=n/10;
}
printf("Sum of individual digits of a positive integer is: %d", sum);
}
#include <stdio.h>
void main()
{
int n, i, c = 0;
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 9
Government Polytechnic Amravati Practical Manual
if (c == 2)
{
printf(" „n‟ is a Prime number");
}
else
{
printf(" „n‟ is not a Prime number");
}
return 0;
}
Output: (a) Write a C program to find the sum of individual digits of a positive integer.
Result:
Thus, we perform the „C‟ program to find the sum of individual digits of a positive integer
and to find whether entered number is prime or not.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 10
Government Polytechnic Amravati Practical Manual
Practical No. 06
Aim: (a) Write a program to find the largest among 5 numbers using 'if- else'.
(b) Write a program using If-else to find whether given number is even or odd.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code: (a) Write a program to find the largest among 5 numbers using 'if- else'.
#include <stdio.h>
void main()
{
int a,b,c,d,e;
else
if(b>c && b>d && b>e)
printf("%d is largest number.", b);
else
if(c>d && c>e)
printf("%d is largest number.", c);
else
if(d>e)
printf("%d is largest number.", d);
else
printf("%d is largest number.", e);
return 0;
getch ();
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 11
Government Polytechnic Amravati Practical Manual
(b) Write a program using If-else to find whether given number is even or odd.
#include<stdio.h>
void main()
{
int num;
if(num % 2 == 0)
else
return 0;
}
Output: (a) Write a program to find the largest among 5 numbers using 'if- else'.
10 56 42 89 35
89 is largest number.
(b) Write a program using If-else to find whether given number is even or odd.
Result:
Thus, we perform the „C‟ program to find the largest among 5 numbers using 'if- else' and a
program using If-else to find whether given number is even or odd.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 12
Government Polytechnic Amravati Practical Manual
Practical No. 07
Aim: Determine whether a string is palindrome.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
#include <stdio.h>
#include <string.h>
void main()
{
char s[1000];
int i,n,c=0;
for(i=0;i<n/2;i++)
{
if(s[i]==s[n-i-1])
c++;
if(c==i)
printf("String is palindrome.");
else
printf("String is not palindrome.");
return 0;
}
Output:
String is palindrome.
Result:
Thus, we perform the „C‟ program to find the whether a string is palindrome or not.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 13
Government Polytechnic Amravati Practical Manual
Practical No. 08
Aim: Write a program to perform addition, subtraction; multiplication and division according to
user‟s choice using switch case statement for given data.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
#include<stdio.h>
void main()
{
int a, b;
char choice;
printf("Enter your choice:\n");
switch(choice)
{
case 'a': printf("%d + %d = %d\n", a, b, (a+b));
break;
else
printf("Number can't be divided by 0\n");
break;
default: printf("You entered wrong choice\n");
break;
}
return 0;
getch ();
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 14
Government Polytechnic Amravati Practical Manual
Output:
A. Addition
B. Subtraction
C. Multiplication
D. Division
Result:
Thus, we perform the „C‟ program to perform addition, subtraction; multiplication and
division according to user‟s choice using switch case statement for given data.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 15
Government Polytechnic Amravati Practical Manual
Practical No. 09
Aim: a) Write a C program to construct a pyramid of numbers.
b) Write a program to count the number of digits in a number.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
1]
#include <stdio.h>
int main()
{
int i, j, rows;
2]
#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i)
{
for (j = 1; j <= i; ++j)
{
printf("%d ", j);
}
printf("\n");
}
return 0;
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 16
Government Polytechnic Amravati Practical Manual
#include<stdio.h>
int main()
{
long long n;
int count = 0;
do
{
n /= 10;
++count;
}
while (n != 0);
printf("Number of Digits In Integers Are: %d", count);
}
*
**
***
****
*****
Result:
Thus, we perform the „C‟ program to construct a pyramid of numbers and a program to
count the number of digits in a number.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 17
Government Polytechnic Amravati Practical Manual
Practical No. 10
Aim: (a) Find the greatest of the three numbers using conditional operators.
(b) Find the smallest of the three numbers using conditional operators.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code: (a) Find the greatest of the three numbers using conditional operators.
# include <stdio.h>
void main()
{
int a, b, c, big ;
(b) Find the smallest of the three numbers using conditional operators.
#include<stdio.h>
void main()
{
int a, b, c;
printf("a is smallest.\n"):
(b < c)?
printf("b is smallest.\n"):
printf("c is smallest.\n");
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 18
Government Polytechnic Amravati Practical Manual
Output: (a) Find the greatest of the three numbers using conditional operators.
(b) Find the smallest of the three numbers using conditional operators.
Output 1
Output 2
Output 3
Result:
Thus, we perform the „C‟ program to find the greatest of the three numbers using conditional
operators and smallest of the three numbers using conditional operators.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 19
Government Polytechnic Amravati Practical Manual
Practical No. 11
Aim: Write a program to print the following outputs:
(a) (b)
1 1
2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5
(c) (d)
1 *
222 ***
33333 *****
4444444 *******
555555555 *********
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a)
#include <stdio.h>
void main()
{
int i, j, rows;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; ++i)
{
for (j = 1; j <= i; ++j)
{
printf ("%d ", i); // print the number
}
printf ("\n");
}
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 20
Government Polytechnic Amravati Practical Manual
(b)
#include <stdio.h>
void main()
{
int i,j,spc,rows,k;
printf("Input number of rows : ");
scanf("%d",&rows);
spc=rows+4-1;
for(i=1;i<=rows;i++)
{
for(k=spc;k>=1;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
printf("%d ",i);
printf("\n");
spc--;
}
}
(c)
#include <stdio.h>
void main()
{
int i, j, rows, k = 0;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows); // take a number
for ( i =1; i <= rows; i++)
{
for ( j = 1; j <= rows - i; j++)
{
printf (" "); // print the space
}
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("%d ",i); // print the number
}
printf ("\n");
}
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 21
Government Polytechnic Amravati Practical Manual
(d)
#include <stdio.h>
int main()
{
int i, space, rows, k = 0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i, k = 0) {
for (space = 1; space <= rows - i; ++space) {
printf(" ");
}
while (k != 2 * i - 1) {
printf("* ");
++k;
}
printf("\n");
}
return 0;
}
Output:
(a) (b)
1 1
2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5
(c) (d)
1 *
222 ***
33333 *****
4444444 *******
555555555 *********
Result:
Thus, we perform the „C‟ program to print the above outputs.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 22
Government Polytechnic Amravati Practical Manual
Practical No. 12
Aim: Write a program to declare, modify and print elements of an one dimensional array.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a)
#include<stdio.h>
void main()
{
int n[5]={0, 1, 2, 3, 4};
printf("%d", n[0]);
printf("%d", n[1]);
printf("%d", n[2]);
printf("%d", n[3]);
printf("%d", n[4]);
(b)
#include<stdio.h>
void main ()
{
int a[5], i;
printf ("Enter Array Elements:\n");
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 23
Government Polytechnic Amravati Practical Manual
Output:
(a)
01234
(b)
Result:
Thus, we perform the „C‟ program to declare, modify and print elements of an one
dimensional array.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 24
Government Polytechnic Amravati Practical Manual
Practical No. 13
Aim: a) Write a program to search an element from Array.
b) Write a program to find smallest / largest number from array elements.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a)
#include <stdio.h>
int main()
{
int nbr, i, r, arr[30];
if (i < nbr)
{
printf("The element is found in the position = %d", i + 1);
}
else
{
printf("Element not found!");
}
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 25
Government Polytechnic Amravati Practical Manual
(b)
#include<stdio.h>
void main ()
{
int a[50],i,n,large,small;
for(i=0;i<n;++i)
scanf("%d",&a[i]);
large=small=a[0];
for(i=1;i<n;++i)
{
if(a[i]>large)
large=a[i];
if(a[i]<small)
small=a[i];
}
printf("The largest element is %d",large);
printf("\nThe smallest element is %d",small);
return 0;
}
Output:
(a)
(b)
Result:
Thus, we perform the „C‟ program to search an element from array and to find smallest /
largest number from array elements.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 26
Government Polytechnic Amravati Practical Manual
Practical No. 14
Aim: a) Write a program to calculate addition of 2 dimensional matrix.
b) Write a program to calculate subtraction of 2 dimensional matrix.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a)
#include <stdio.h>
int main()
{
int a[2][3],b[2][3],c[2][3],i,j;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 27
Government Polytechnic Amravati Practical Manual
(b)
#include <stdio.h>
void main()
{
int arr1[50][50],brr1[50][50],crr1[50][50],i,j,n;
printf("\n\nSubtraction of two Matrices :\n");
printf("------------------------------\n");
printf("Input the size of the square matrix (less than 5): ");
scanf("%d", &n);
printf("Input elements in the first matrix :\n"); /* Stored values into the array*/
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("element - [%d],[%d] : ",i,j);
scanf("%d",&arr1[i][j]);
}
}
printf("Input elements in the second matrix :\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("element - [%d],[%d] : ",i,j);
scanf("%d",&brr1[i][j]);
}
}
printf("\nThe First matrix is :\n");
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("%d\t",arr1[i][j]);
}
printf("\nThe Second matrix is :\n");
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("%d\t",brr1[i][j]);
}
for(i=0;i<n;i++) /* calculate the subtraction of the matrix */
for(j=0;j<n;j++)
crr1[i][j]=arr1[i][j]-brr1[i][j];
printf("\nThe Subtraction of two matrix is : \n");
for(i=0;i<n;i++){
printf("\n");
for(j=0;j<n;j++)
printf("%d\t",crr1[i][j]);
}
printf("\n\n"); }
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 28
Government Polytechnic Amravati Practical Manual
Output:
(a)
(b)
1 1
1 1
1 1
1 1
0 0
0 0
Result:
Thus, we perform the „C‟ program to calculate addition and subtraction of 2 dimensional
matrix.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 29
Government Polytechnic Amravati Practical Manual
Practical No. 15
Aim: a) Write a program that accept a string from user and print that string.
b) Write a program that accept a string and compare it with existing string.
c) Write a program to accept and display that string in reverse order.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a)
#include<stdio.h>
int main()
{
char str[20];
printf("Enter your first name: ");
scanf("%s", str);
printf("Hello %s", str);
getch();
return 0;
}
(b-1)
#include <stdio.h>
#include <string.h>
int main()
{
char Str1[100], Str2[100];
int result, i;
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 30
Government Polytechnic Amravati Practical Manual
return 0;
}
(b-2)
#include<stdio.h>
#include<string.h>
int main()
{
char a[100], b[100];
printf("Enter the first string: ");
gets(a);
if( strcmp(a,b) == 0 )
printf("Result: Entered strings are equal.\n");
else
printf("Result: Entered strings are not equal.\n");
return 0;
}
(c)
#include <stdio.h>
#include <string.h>
int main()
{
char str[40]; // declare the size of character string
printf (" \n Enter a string to be reversed: ");
scanf ("%s", str);
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 31
Government Polytechnic Amravati Practical Manual
Output:
(a)
(b-1)
(b-2)
(c)
Result:
Thus, we perform the „C‟ program to accept a string from user and print that string, to accept
a string and compare it with existing string and to accept and display that string in reverse order.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 32
Government Polytechnic Amravati Practical Manual
Practical No. 16
Aim: a) Write a program to accept and concatenate two strings.
b) Write a program to find length of a string.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a)
#include<stdio.h>
#include<string.h>
int main()
{
char str1[50], str2[50];
strcat(str1, str2);
printf("\nString after concatenation is: %s", str1);
return 0;
}
(b)
#include <stdio.h>
#include <string.h>
int main()
{
char a[100];
int length;
length = strlen(a);
return 0;
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 33
Government Polytechnic Amravati Practical Manual
Output:
(a)
(b)
Result:
Thus, we perform the „C‟ program to accept and concatenate two strings and to find length of
a string.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 34
Government Polytechnic Amravati Practical Manual
Practical No. 17
Aim: a) Write a program to convert given string to lower case.
b) Write a program to convert given string to upper case.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a)
#include <stdio.h>
#include <conio.h>
int main ()
{
char upr[50]; // declare character array
return 0;
}
(b)
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100 // Maximum string size
int main()
{
char str[MAX_SIZE];
return 0;
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 35
Government Polytechnic Amravati Practical Manual
Output:
(a)
(b)
Result:
Thus, we perform the „C‟ program to convert given string to lower case and to convert given
string to upper case.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 36
Government Polytechnic Amravati Practical Manual
Practical No. 18
Aim: a) Write a program to add two numbers using user defined function.
b) Write a program to find factorial of number using function for given data.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a)
#include <stdio.h>
int main()
{
int num1, num2, num3;
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
//Calling the function
num3 = sum(num1, num2);
printf("Sum of the entered numbers: %d", num3);
return 0;
}
int sum(int a, int b)
{
return a+b;
}
(b)
#include <stdio.h>
int main()
{
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else
{
for (i = 1; i <= n; ++i)
{
fact *= i;
}
printf("Factorial of %d = %llu", n, fact);
}
return 0;
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 37
Government Polytechnic Amravati Practical Manual
Output:
(a)
(b)
Enter an integer: 7
Factorial of 7 = 5040
Result:
Thus, we perform the „C‟ program to add two numbers using user defined function and to
find factorial of number using function for given data.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 38
Government Polytechnic Amravati Practical Manual
Practical No. 19
Aim: Write a program to interchange given values of two variables using call by value mechanism.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
#include<stdio.h>
void swap(int,int);
void main( )
{
int n1,n2;
printf("\nThe values of n1 and n2 in the main function before calling the swap function are n1=%d
n2=%d",n1,n2);
swap(n1,n2);
printf("\nThe values of n1 and n2 in the main function after calling the swap function are n1=%d
n2=%d",n1,n2);
}
Output:
Result:
Thus, we perform the „C‟ program to interchange given values of two variables using call by
value mechanism.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 39
Government Polytechnic Amravati Practical Manual
Practical No. 20
Aim: Write a program to interchange given values of two variables using call by reference
mechanism.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
#include <stdio.h>
swap (int *, int *);
int main()
{
int a, b;
printf("\nEnter value of a & b: ");
scanf("%d %d", &a, &b);
printf("\nBefore Swapping:\n");
printf("\na = %d\n\nb = %d\n", a, b);
swap(&a, &b);
printf("\nAfter Swapping:\n");
printf("\na = %d\n\nb = %d", a, b);
return 0;
}
swap (int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
Output:
Before Swapping:
a=5
b=7
After Swapping:
a=7
b=5
Result:
Thus, we perform the „C‟ program to interchange given values of two variables using call by
reference mechanism.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 40
Government Polytechnic Amravati Practical Manual
Practical No. 21
Aim: a) Write a program to add two integer numbers using pointer.
b) Write a program to find area of circle using pointer.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a-1)
#include <stdio.h>
int main()
{
int first, second, *p, *q, sum;
printf("Enter two integers to add\n");
scanf("%d%d", &first, &second);
p = &first;
q = &second;
sum = *p + *q;
printf("Sum of entered numbers = %d\n",sum);
return 0;
}
(a-2)
#include<stdio.h>
int main()
{
int num1, num2, sum;
int *ptr1, *ptr2;
printf("Enter any two Number: ");
scanf("%d%d", &num1, &num2);
printf("\nAddress of %d is %p", num1, &num1);
printf("\nAddress of %d is %p", num2, &num2);
ptr1 = &num1;
ptr2 = &num2;
printf("\n\nptr1 = %p", ptr1);
printf("\nptr2 = %p", ptr2);
printf("\n\nValue at %p is %d", ptr1, *ptr1);
printf("\nValue at %p is %d", ptr2, *ptr2);
sum = *ptr1 + *ptr2;
printf("\n\nSum of %d and %d is %d", *ptr1, *ptr2, sum);
return 0;
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 41
Government Polytechnic Amravati Practical Manual
(b)
#include<stdio.h>
void main( )
{
int radius ;
float area, perimeter ;
Output:
(a-1)
Enter two integers to add
64616 6464361
Sum of entered numbers = 6528977
(a-2)
Enter any two Numbers: 454634 84278687
Address of 454634 is 0x7fff2714a51c
Address of 84278687 is 0x7fff2714a520
ptr1 = 0x7fff2714a51c
ptr2 = 0x7fff2714a520
(b)
Enter radius of a circle: 6.18 cm
Area = 113.040001 cm
Perimeter = 37.680000 cm
Result:
Thus, we perform the „C‟ program to add two integer numbers using pointer and to find area
of circle using pointer.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 42
Government Polytechnic Amravati Practical Manual
Practical No. 22
Aim: Write a program to create a structure for employee having data members like emp_name,
emp_id, and emp_salary.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char name[30];
int id;
double salary;
} Employee;
int main()
{
//number of employees
int n=2;
//Name
printf("\nName: ");
scanf("%[^\n]s",employees[i].name);
//ID
printf("Id Code: ");
scanf("%d",&employees[i].id);
//Salary
printf("Salary: Rs. ");
scanf("%lf",&employees[i].salary);
printf("\n\n\n");
}
Output:
Employee 1:-
Name: Mr. Rakesh
Id Code: 100101
Salary: Rs. 50000
Employee 2:-
Name: Mr. Anil
Id Code: 100102
Salary: Rs. 45000
Result:
Thus, we perform the „C‟ program to create a structure for employee having data members
like emp_name, emp_id, and emp_salary.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 44
Government Polytechnic Amravati Practical Manual
Practical No. 23
Aim: a) Write a program to add two integer numbers using pointer.
b) Write a program to find area of circle using pointer.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
(a-1)
#include <stdio.h>
int main()
{
int first, second, *p, *q, sum;
printf("Enter two integers to add\n");
scanf("%d%d", &first, &second);
p = &first;
q = &second;
sum = *p + *q;
printf("Sum of entered numbers = %d\n",sum);
return 0;
}
(a-2)
#include<stdio.h>
int main()
{
int num1, num2, sum;
int *ptr1, *ptr2;
printf("Enter any two Number: ");
scanf("%d%d", &num1, &num2);
printf("\nAddress of %d is %p", num1, &num1);
printf("\nAddress of %d is %p", num2, &num2);
ptr1 = &num1;
ptr2 = &num2;
printf("\n\nptr1 = %p", ptr1);
printf("\nptr2 = %p", ptr2);
printf("\n\nValue at %p is %d", ptr1, *ptr1);
printf("\nValue at %p is %d", ptr2, *ptr2);
sum = *ptr1 + *ptr2;
printf("\n\nSum of %d and %d is %d", *ptr1, *ptr2, sum);
return 0;
}
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 45
Government Polytechnic Amravati Practical Manual
(b)
#include<stdio.h>
void main( )
{
int radius ;
float area, perimeter ;
Output:
(a-1)
Enter two integers to add
64616 6464361
Sum of entered numbers = 6528977
(a-2)
Enter any two Numbers: 454634 84278687
Address of 454634 is 0x7fff2714a51c
Address of 84278687 is 0x7fff2714a520
ptr1 = 0x7fff2714a51c
ptr2 = 0x7fff2714a520
(b)
Enter radius of a circle: 6.18 cm
Area = 113.040001 cm
Perimeter = 37.680000 cm
Result:
Thus, we perform the „C‟ program to add two integer numbers using pointer and to find area
of circle using pointer.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 46
Government Polytechnic Amravati Practical Manual
Practical No. 24
Aim: Write simple Python program to print “Hello World” on the screen.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
print("Hello World")
Output:
Hello World
Result:
Thus, we perform the simple Python program to print “Hello World” on the screen.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 47
Government Polytechnic Amravati Practical Manual
Practical No. 25
Aim: Write a Python program to add two numbers and display result on screen.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
sum = a + b
print("Sum:", sum)
Output:
Result:
Thus, we perform Python program to add two numbers and display result on screen.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 48
Government Polytechnic Amravati Practical Manual
Practical No. 26
Aim: Write a Python program to find out smallest of three numbers using if—elif.
Hardware Requirement‟s: All input & output devices with hardware peripherals.
Software Requirement‟s: System of I5 Generation with OS Windows 7 or newer and Compilers like
Microsoft Visual Studio, Code Blocks Software, Turbo C, Online Compliers, etc.
Program Code:
num1=int(input("Enter the First Number: ")) #Take input from user for first number
num2=int(input("Enter the Second Number: ")) #Take input from user for second number
num3=int(input("Enter the Third Number: ")) #Take input from user for third number
if(num1<=num2 and num1<=num3): #Compare the first number with the second and third number
print(num1,"is the smallest.")
elif(num2<=num1 and num2<=num3): #Compare the second number with the first and third number
print(num2,"is the smallest.")
else:
print(num3,"is the smallest.")
Output:
Result:
Thus, we perform a Python program to find out smallest of three numbers using if—elif.
Course Code & Title: EC 3409 “C & Python Programming” By Prof. H. S. Holey Page 49