SlideShare a Scribd company logo
ITP__Practical-File 2019
By AKGandhi Page 1
DELHI TECHNICAL CAMPUS
GREATER NOIDA
LAB PRACTICAL FILE
INTRODUCTION TO PROGRAMMING
LAB
SUBMITTED TO: SUBMITTED BY:
Mr. VIVEK MISRA AMIT KUMAR GANDHI
(43118002818)
Electronics& CommunicationEngineeringDepartment
(AffiliatedtoGuruGobindSinghIndraprasthaUniversity)
28/1,Knowledge Park-III,GreaterNoida-201306(U.P) Tel:8527215687
ITP__Practical-File 2019
By AKGandhi Page 2
PROGRAM 1
AIM : WAP to printwelcome page.
Code:
#include<stdio.h>
#include<conio.h>
Void main()
{
clrscr();
printf("Hello,World!");
getch();
}
Output:
ITP__Practical-File 2019
By AKGandhi Page 3
PROGRAM 2
AIM : WAP to find sum of two numbers.
Code:
#include<stdio.h>
#include<conio.h>
Void main()
{
int num1, num2, sum;
clrscr();
printf("Enter firstnumber: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
sum = num1 + num2;
printf("Sum of the entered numbers: %d", sum);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 4
Output:
ITP__Practical-File 2019
By AKGandhi Page 5
PROGRAM 3
AIM : WAP to find area of triangle.
Code:
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int s,a, b, c, area;
clrscr();
printf("Enter the values of a,b and c n");
scanf("%d %d %d", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area of a triangle= %d n", area);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 6
Output:
ITP__Practical-File 2019
By AKGandhi Page 7
PROGRAM 4
AIM : WAP to swap the value of two variable.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int firstNumber, secondNumber, temporaryVariable;
clrscr();
printf("Enter firstnumber: ");
scanf("%d", &firstNumber);
printf("Enter second number: ");
scanf("%d",&secondNumber);
temporaryVariable= firstNumber;
firstNumber = secondNumber;
secondNumber = temporaryVariable;
printf("nAfter swapping,firstNumber = %dn", firstNumber);
printf("After swapping,secondNumber = %d", secondNumber);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 8
Output:
ITP__Practical-File 2019
By AKGandhi Page 9
PROGRAM 5
AIM : WAP to swap the value of two variable withoutusing third variable.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int firstNumber, secondNumber, temporaryVariable;
clrscr();
printf("Enter firstnumber: ");
scanf("%d", &firstNumber);
printf("Enter second number: ");
scanf("%d",&secondNumber);
firstNumber = firstNumber - secondNumber;
secondNumber = firstNumber + secondNumber;
firstNumber = secondNumber - firstNumber;
printf("nAfter swapping,firstNumber = %dn", firstNumber);
printf("After swapping,secondNumber = %d", secondNumber);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 10
Output:
ITP__Practical-File 2019
By AKGandhi Page 11
PROGRAM 6
AIM : WAP to check leap year.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
ITP__Practical-File 2019
By AKGandhi Page 12
getch();
}
Output:
ITP__Practical-File 2019
By AKGandhi Page 13
PROGRAM 7
AIM : WAP to find largest among 3 numbers.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int num1, num2, num3;
clrscr();
printf("Enter the values of num1, num2 and num3n");
scanf("%d %d %d", &num1, &num2, &num3);
printf("num1 = %dtnum2 = %dtnum3 = %dn", num1, num2, num3);
if (num1 > num2)
{
if (num1 > num3)
{
printf("num1 is the greatest among three n");
}
else
{
printf("num3 is the greatest among three n");
}
}
else if (num2 > num3)
printf("num2 is the greatest among three n");
ITP__Practical-File 2019
By AKGandhi Page 14
else
printf("num3 is the greatest among three n");
getch();
}
Output
ITP__Practical-File 2019
By AKGandhi Page 15
PROGRAM 8
AIM : WAP to find nature of rootof quadratic equations.
Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
floata,b,c;
floatd,root1,root2;
clrscr();
printf("Enter a, b and c of quadratic equation:");
scanf("%f%f%f",&a,&b,&c);
d = b * b - 4 * a * c;
if(d < 0)
{
printf("Roots arecomplex number.n");
printf("Roots of quadratic equation are:");
printf("%.3f%+.3fi",-b/(2*a),sqrt(-d)/(2*a));
printf(", %.3f%+.3fi",-b/(2*a),-sqrt(-d)/(2*a));
return 0;
}
else if(d==0){
printf("Both roots are equal.n");
root1 = -b /(2* a);
ITP__Practical-File 2019
By AKGandhi Page 16
printf("Root of quadratic equation is:%.3f ",root1);
return 0;
}
else
{
printf("Roots arereal numbers.n");
root1 = ( -b + sqrt(d)) / (2* a);
root2 = ( -b - sqrt(d)) / (2* a);
printf("Roots of quadratic equation are:%.3f , %.3f",root1,root2);
}
getch();
}
Output:
ITP__Practical-File 2019
By AKGandhi Page 17
PROGRAM 9
AIM : WAP to simulate calculator using switch.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
char operator;
double firstNumber,secondNumber;
clrscr();
printf("Enter an operator (+, -, *,/) ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%lf %lf",&firstNumber, &secondNumber);
switch(operator)
{
case'+':
printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber + secondNumber);
break;
case'-':
printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber);
break;
case'*':
printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber);
break;
ITP__Practical-File 2019
By AKGandhi Page 18
case'/':
printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber);
break;
default:
printf("Error! operator is notcorrect");
getch();
}
Output:
ITP__Practical-File 2019
By AKGandhi Page 19
PROGRAM 10
AIM : WAP to check that a character is vowelor consonant
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
char c;
int isLowercaseVowel,isUppercaseVowel;
clrscr();
printf("Enter an alphabet: ");
scanf("%c",&c);
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
if (isLowercaseVowel || isUppercaseVowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 20
Output
ITP__Practical-File 2019
By AKGandhi Page 21
PROGRAM 11
AIM : WAP to find sum of digits.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,m;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
printf("Sum is=%d",sum);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 22
Output:
ITP__Practical-File 2019
By AKGandhi Page 23
PROGRAM 12
AIM : WAP to reverse a number.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, reversedNumber = 0, remainder;
clrscr();
printf("Enter an integer: ");
scanf("%d", &n);
while(n != 0)
{
remainder = n%10;
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
}
printf("Reversed Number = %d", reversedNumber);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 24
Output:
ITP__Practical-File 2019
By AKGandhi Page 25
PROGRAM 13
AIM : WAP to check Armstrong number.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
If(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 26
Output:
ITP__Practical-File 2019
By AKGandhi Page 27
PROGRAM 14
AIM : WAP to check palindrome number.
Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, reversedInteger = 0, remainder, originalInteger;
clrscr();
printf("Enter an integer: ");
scanf("%d", &n);
originalInteger = n;
while( n!=0 )
{
remainder = n%10;
reversedInteger = reversedInteger*10 + remainder;
n /= 10;
}
if (originalInteger == reversedInteger)
printf("%d is a palindrome.", originalInteger);
else
printf("%d is not a palindrome.",originalInteger);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 28
Output:
ITP__Practical-File 2019
By AKGandhi Page 29
PROGRAM 15
AIM : WAP to find factorialof a number.
Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, i;
unsigned long longfactorial =1;
clrscr();
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)
{
factorial *=i;
}
printf("Factorial of %d = %llu",n, factorial);
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 30
Output:
ITP__Practical-File 2019
By AKGandhi Page 31
PROGRAM 16
AIM : WAP to printFibonacciseries.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n, t1 = 0, t2 = 1, nextTerm;
clrscr();
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:");
for (i = 1; i <= n; ++i)
{
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 32
Output:
ITP__Practical-File 2019
By AKGandhi Page 33
PROGRAM 17
AIM : WAP to check prime number.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i,flag= 0;
clrscr();
printf("Enter a positiveinteger: ");
scanf("%d", &n);
for(i = 2; i <= n/2; ++i)
{
if(n%i == 0)
{
flag= 1;
break;
}
}
if (n == 1)
{
printf("1 is neither a prime nor a composite number.");
}
else
{
ITP__Practical-File 2019
By AKGandhi Page 34
if (flag== 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}
getch();
}
Output:
ITP__Practical-File 2019
By AKGandhi Page 35
PROGRAM 18
AIM : WAP to calculate X y
.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int base,exponent;
longlong result= 1;
clrscr();
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exponent);
while(exponent != 0)
{
result*= base;
--exponent;
}
printf("Answer = %lld", result);
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 36
Output:
ITP__Practical-File 2019
By AKGandhi Page 37
PROGRAM 19
AIM : WAP to printhalf pyramid using *.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j, rows;
clrscr();
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("n");
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 38
Output:
ITP__Practical-File 2019
By AKGandhi Page 39
PROGRAM 20
AIM : WAP to printhalf pyramid a using numbers.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j, rows;
clrscr();
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("%d ",j);
}
printf("n");
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 40
Output:
ITP__Practical-File 2019
By AKGandhi Page 41
PROGRAM 21
AIM : WAP to printhalf pyramid using alphabets.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
char input, alphabet= 'A';
clrscr();
printf("Enter the uppercasecharacter you want to printin lastrow: ");
scanf("%c",&input);
for(i=1; i <= (input-'A'+1); ++i)
{
for(j=1;j<=i;++j)
{
printf("%c", alphabet);
}
++alphabet;
printf("n");
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 42
Output:
ITP__Practical-File 2019
By AKGandhi Page 43
PROGRAM 22
AIM : WAP to printfull pyramid using *.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,space,rows, k=0;
clrscr();
printf("Enter 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");
}
getch();
ITP__Practical-File 2019
By AKGandhi Page 44
}
Output
ITP__Practical-File 2019
By AKGandhi Page 45
PROGRAM 23
AIM : WAP to print Inverted full pyramid using *.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j, rows;
clrscr();
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("n");
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 46
Output:
ITP__Practical-File 2019
By AKGandhi Page 47
PROGRAM 24
AIM : WAP to print Inverted half pyramid using *.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j, rows;
clrscr();
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("n");
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 48
ITP__Practical-File 2019
By AKGandhi Page 49
PROGRAM 25
AIM : WAP to calculate factorialusing function.[ With Return Type With Argument Type ]
Code:
#include<stdio.h>
#include<conio.h>
floatfact(float) ;
void main( )
{
floatno,m;
clrscr();
printf(“Enter any Value: ”);
scanf(“%f”,&no);
m = fact(no);
printf(“nFactorial of %d = %dn”,no,m);
getch();
}
floatfact(floatno)
{
floati,f=1;
for(i=no;i>=1;i--)
f=f*i;
return (f);
}
ITP__Practical-File 2019
By AKGandhi Page 50
Output:
ITP__Practical-File 2019
By AKGandhi Page 51
PROGRAM 26
AIM : WAP to calculate factorialusing function.[ With No Return Type With Argument Type ]
Code:
#include<stdio.h>
#include<conio.h>
void fact(float) ;
void main( )
{
floatno;
clrscr();
printf(“Enter any Value: ”);
scanf(“%f”,&no);
fact(no);
getch();
}
void fact(floatno)
{
floati,f=1;
for(i=no;i>=1;i--)
f=f*i;
printf(“nFactorial of %d = %dn”,no,f);
}
ITP__Practical-File 2019
By AKGandhi Page 52
Output:
ITP__Practical-File 2019
By AKGandhi Page 53
PROGRAM 27
AIM : WAP to calculate factorialusing function.[With NoReturn Type With NoArgument Type]
Code:
#include<stdio.h>
#include<conio.h>
void fact(void) ;
void main( )
{
clrscr();
fact();
getch();
}
void fact(void)
{
int no,i,f=1;
printf(“Enter any Value: ”);
scanf(“%d”,&no);
for(i=no;i>=1;i--)
f=f*i;
printf(“nFactorial of %d = %dn”,no,f);
}
ITP__Practical-File 2019
By AKGandhi Page 54
Output:
ITP__Practical-File 2019
By AKGandhi Page 55
PROGRAM 28
AIM : WAP to calculate factorialusing function.[ With Return Type With No Argument Type ]
Code:
#include<stdio.h>
#include<conio.h>
floatfact(void) ; // Function prototype
void main( )
{
floatm;
clrscr();
m = fact(); // Function call
printf(“nFactorial =%dn”,m);
getch();
}
floatfact(void) // Function Definition
{
int no,i,f=1;
printf(“Enter any Value: ”);
scanf(“%d”,&no);
for(i=no;i>=1;i--)
f=f*i;
return (f);
}
ITP__Practical-File 2019
By AKGandhi Page 56
Output:
ITP__Practical-File 2019
By AKGandhi Page 57
PROGRAM 29
AIM : WAP to calculate factorialusing recursive function.
Code:
#include<stdio.h>
#include<conio.h>
float factorial (float);
void main( )
{
floatno,m;
clrscr();
printf(“Enter any Valuen”);
scanf(“%f”,&no);
m = factorial (no);
printf(“Factorial of %.f = %.fn”, m );
getch();
}
float factorial (floatno)
{
if(no <= 0)
return 1;
else
return (no * factorial(no-1));
}
ITP__Practical-File 2019
By AKGandhi Page 58
Output:
ITP__Practical-File 2019
By AKGandhi Page 59
PROGRAM 30
AIM : WAP to calculate Fibonacci series using recursive function.
Code:
#include<stdio.h>
#include<conio.h>
int Fibonacci(int);
void main()
{
int n, i = 0, c;
scanf("%d",&n);
printf("Fibonacci seriesn");
for ( c = 1 ; c <= n ; c++ )
{
printf("%dn", Fibonacci(i));
i++;
}
getch();
}
int Fibonacci(intn)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
ITP__Practical-File 2019
By AKGandhi Page 60
return ( Fibonacci(n-1) +Fibonacci(n-2) );
}
Output:
ITP__Practical-File 2019
By AKGandhi Page 61
PROGRAM 31
AIM : WAP to implement linear search.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int array[10];
int i,num, keynum, found = 0;
clrscr();
printf("Enter the valueof num n");
scanf("%d", &num);
printf("Enter the elements one by one n");
for (i = 0; i < num; i++)
{
scanf("%d", &array[i]);
}
printf("Input array is n");
for (i = 0; i < num; i++)
{
printf("%dn", array[i]);
}
printf("Enter the element to be searched n");
scanf("%d", &keynum);
for (i = 0; i < num ; i++)
ITP__Practical-File 2019
By AKGandhi Page 62
{
if (keynum == array[i] )
{
found = 1;
break;
}
}
if (found == 1)
printf("Element is present in the arrayn");
else
printf("Element is not present in the arrayn");
getch();
}
Output:
ITP__Practical-File 2019
By AKGandhi Page 63
PROGRAM 32
AIM : WAP to find transpose of given matrix.
Code:
#include<stdio.h>
#include<conio.h>
# define SIZE 100
void main()
{
int no,a[SIZE][SIZE],i,j,row,col;
clrscr();
printf("nEnter Row numbers : ");
scanf("%d",&row);
printf("nEnter column numbers : ");
scanf("%d",&col);
printf("nEnter %d values.....n ",row*col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("n Enter Value at element [%d][%d]: ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("n Data in Traversal Moden");
for(i=0;i<row;i++)
ITP__Practical-File 2019
By AKGandhi Page 64
{
printf("n|");
for(j=0;j<col;j++)
{
printf("%6d",a[i][j]);
}
printf(" |n");
}
printf("n Data in TransposeModen");
for(i=0;i<row;i++)
{
printf("n|");
for(j=0;j<col;j++)
{
printf("%6d",a[j][i]);
}
printf(" |n");
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 65
Output:
ITP__Practical-File 2019
By AKGandhi Page 66
PROGRAM 33
AIM : WAP to printdiagonaleliment.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int matrix[10][10];
int i,j,r,c;
clrscr();
printf("Enter number of Rows :");
scanf("%d",&r);
printf("Enter number of Cols :");
scanf("%d",&c);
printf("nEnter matrix elements :n");
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
printf("Enter element [%d,%d] : ",i+1,j+1);
scanf("%d",&matrix[i][j]);
}
}
if(r==c)
{
ITP__Practical-File 2019
By AKGandhi Page 67
for(i=0;i< c;i++)
{
for(j=0;j< r;j++)
{
if(i==j)
printf("%dt",matrix[j][i]);
else
printf("t");
}
printf("n");
}
}
else
{
printf("nMatrix is not a Square Matrix.");
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 68
Output:
ITP__Practical-File 2019
By AKGandhi Page 69
PROGRAM 34
AIM : WAP to perform matrixmultiplication.
Code:
#include<stdio.h>
#include<conio.h>
# define R 100
# define C 100
void main()
{
int no,a[R][C],b[R][C],c[R][C],row,col,i,j,k;
clrscr();
printf("nEnter Row numbers : ");
scanf("%d",&row);
printf("nEnter Colom numbers : ");
scanf("%d",&col);
printf("nEnter %d Valueof Mtrix-A",row*col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("nEnter Value in [%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
ITP__Practical-File 2019
By AKGandhi Page 70
printf("nEnter %d Valueof Mtrix-B",row*col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("nEnter Value in [%d][%d]:",i,j);
scanf("%d",&b[i][j]);
}
}
printf("n Product of Two Matrices n");
for(i=0;i<row;i++)
{
printf("n|");
for(j=0;j<col;j++)
{
c[i][j]=0;
for(k=0;k<col;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
printf("%5d",c[i][j]);
}
printf(" |n");
}
getch();
}
ITP__Practical-File 2019
By AKGandhi Page 71
Output:

More Related Content

DOCX
Practical File of C Language
DOCX
C Programming
PDF
C Programming lab
DOCX
B.Com 1year Lab programs
DOCX
Best C Programming Solution
PDF
Common problems solving using c
DOCX
Cd practical file (1) start se
Practical File of C Language
C Programming
C Programming lab
B.Com 1year Lab programs
Best C Programming Solution
Common problems solving using c
Cd practical file (1) start se

What's hot (20)

DOCX
Data Structures Using C Practical File
DOC
C basics
DOCX
DOCX
Practical write a c program to reverse a given number
DOCX
C++ file
PDF
C programms
DOCX
Core programming in c
DOCX
Printing different pyramid patterns of numbers,alphabets and stars using C.
PDF
88 c-programs
DOCX
Let us C (by yashvant Kanetkar) chapter 3 Solution
DOCX
C programs
DOCX
Mech nacp lab
DOCX
Practical write a c program to reverse a given number
PDF
C program
DOCX
C Programming
DOCX
Program flowchart
DOC
C program to check leap year
PPTX
Simple c program
DOCX
Data structure new lab manual
Data Structures Using C Practical File
C basics
Practical write a c program to reverse a given number
C++ file
C programms
Core programming in c
Printing different pyramid patterns of numbers,alphabets and stars using C.
88 c-programs
Let us C (by yashvant Kanetkar) chapter 3 Solution
C programs
Mech nacp lab
Practical write a c program to reverse a given number
C program
C Programming
Program flowchart
C program to check leap year
Simple c program
Data structure new lab manual
Ad

Similar to Itp practical file_1-year (20)

DOCX
C lab manaual
PDF
C in 10 Hours learn programming easily.pdf.pdf
PDF
Loop's definition and practical code in C programming
PDF
C++ in 10 Hours.pdf.pdf
PDF
C programs
DOC
Programming egs
PDF
Programming in C Lab
DOCX
Fuzail_File_C.docx
DOC
'C' language notes (a.p)
PPT
C tutorial
DOC
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
DOCX
Cs291 assignment solution
DOCX
Oops practical file
PDF
9.C Programming
PDF
POP Unit 2.pptx.pdf for your time and gauss with example
PDF
2 1. variables & data types
DOCX
C++ file
PDF
Software testing lab manual
C lab manaual
C in 10 Hours learn programming easily.pdf.pdf
Loop's definition and practical code in C programming
C++ in 10 Hours.pdf.pdf
C programs
Programming egs
Programming in C Lab
Fuzail_File_C.docx
'C' language notes (a.p)
C tutorial
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Cs291 assignment solution
Oops practical file
9.C Programming
POP Unit 2.pptx.pdf for your time and gauss with example
2 1. variables & data types
C++ file
Software testing lab manual
Ad

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Cell Structure & Organelles in detailed.
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Insiders guide to clinical Medicine.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Institutional Correction lecture only . . .
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Types and Its function , kingdom of life
Sports Quiz easy sports quiz sports quiz
Cell Structure & Organelles in detailed.
PPH.pptx obstetrics and gynecology in nursing
Insiders guide to clinical Medicine.pdf
Classroom Observation Tools for Teachers
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
102 student loan defaulters named and shamed – Is someone you know on the list?
O5-L3 Freight Transport Ops (International) V1.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
01-Introduction-to-Information-Management.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Institutional Correction lecture only . . .
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Renaissance Architecture: A Journey from Faith to Humanism
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

Itp practical file_1-year

  • 1. ITP__Practical-File 2019 By AKGandhi Page 1 DELHI TECHNICAL CAMPUS GREATER NOIDA LAB PRACTICAL FILE INTRODUCTION TO PROGRAMMING LAB SUBMITTED TO: SUBMITTED BY: Mr. VIVEK MISRA AMIT KUMAR GANDHI (43118002818) Electronics& CommunicationEngineeringDepartment (AffiliatedtoGuruGobindSinghIndraprasthaUniversity) 28/1,Knowledge Park-III,GreaterNoida-201306(U.P) Tel:8527215687
  • 2. ITP__Practical-File 2019 By AKGandhi Page 2 PROGRAM 1 AIM : WAP to printwelcome page. Code: #include<stdio.h> #include<conio.h> Void main() { clrscr(); printf("Hello,World!"); getch(); } Output:
  • 3. ITP__Practical-File 2019 By AKGandhi Page 3 PROGRAM 2 AIM : WAP to find sum of two numbers. Code: #include<stdio.h> #include<conio.h> Void main() { int num1, num2, sum; clrscr(); printf("Enter firstnumber: "); scanf("%d", &num1); printf("Enter second number: "); scanf("%d", &num2); sum = num1 + num2; printf("Sum of the entered numbers: %d", sum); getch(); }
  • 5. ITP__Practical-File 2019 By AKGandhi Page 5 PROGRAM 3 AIM : WAP to find area of triangle. Code: #include<stdio.h> #include<math.h> #include<conio.h> void main() { int s,a, b, c, area; clrscr(); printf("Enter the values of a,b and c n"); scanf("%d %d %d", &a, &b, &c); s = (a + b + c) / 2; area = sqrt(s * (s - a) * (s - b) * (s - c)); printf("Area of a triangle= %d n", area); getch(); }
  • 7. ITP__Practical-File 2019 By AKGandhi Page 7 PROGRAM 4 AIM : WAP to swap the value of two variable. Code: #include<stdio.h> #include<conio.h> void main() { int firstNumber, secondNumber, temporaryVariable; clrscr(); printf("Enter firstnumber: "); scanf("%d", &firstNumber); printf("Enter second number: "); scanf("%d",&secondNumber); temporaryVariable= firstNumber; firstNumber = secondNumber; secondNumber = temporaryVariable; printf("nAfter swapping,firstNumber = %dn", firstNumber); printf("After swapping,secondNumber = %d", secondNumber); getch(); }
  • 9. ITP__Practical-File 2019 By AKGandhi Page 9 PROGRAM 5 AIM : WAP to swap the value of two variable withoutusing third variable. Code: #include<stdio.h> #include<conio.h> void main() { int firstNumber, secondNumber, temporaryVariable; clrscr(); printf("Enter firstnumber: "); scanf("%d", &firstNumber); printf("Enter second number: "); scanf("%d",&secondNumber); firstNumber = firstNumber - secondNumber; secondNumber = firstNumber + secondNumber; firstNumber = secondNumber - firstNumber; printf("nAfter swapping,firstNumber = %dn", firstNumber); printf("After swapping,secondNumber = %d", secondNumber); getch(); }
  • 11. ITP__Practical-File 2019 By AKGandhi Page 11 PROGRAM 6 AIM : WAP to check leap year. Code: #include<stdio.h> #include<conio.h> void main() { int year; clrscr(); printf("Enter a year: "); scanf("%d",&year); if(year%4 == 0) { if( year%100 == 0) { if ( year%400 == 0) printf("%d is a leap year.", year); else printf("%d is not a leap year.", year); } else printf("%d is a leap year.", year ); } else printf("%d is not a leap year.", year);
  • 12. ITP__Practical-File 2019 By AKGandhi Page 12 getch(); } Output:
  • 13. ITP__Practical-File 2019 By AKGandhi Page 13 PROGRAM 7 AIM : WAP to find largest among 3 numbers. Code: #include<stdio.h> #include<conio.h> void main() { int num1, num2, num3; clrscr(); printf("Enter the values of num1, num2 and num3n"); scanf("%d %d %d", &num1, &num2, &num3); printf("num1 = %dtnum2 = %dtnum3 = %dn", num1, num2, num3); if (num1 > num2) { if (num1 > num3) { printf("num1 is the greatest among three n"); } else { printf("num3 is the greatest among three n"); } } else if (num2 > num3) printf("num2 is the greatest among three n");
  • 14. ITP__Practical-File 2019 By AKGandhi Page 14 else printf("num3 is the greatest among three n"); getch(); } Output
  • 15. ITP__Practical-File 2019 By AKGandhi Page 15 PROGRAM 8 AIM : WAP to find nature of rootof quadratic equations. Code: #include<stdio.h> #include<conio.h> #include<math.h> void main() { floata,b,c; floatd,root1,root2; clrscr(); printf("Enter a, b and c of quadratic equation:"); scanf("%f%f%f",&a,&b,&c); d = b * b - 4 * a * c; if(d < 0) { printf("Roots arecomplex number.n"); printf("Roots of quadratic equation are:"); printf("%.3f%+.3fi",-b/(2*a),sqrt(-d)/(2*a)); printf(", %.3f%+.3fi",-b/(2*a),-sqrt(-d)/(2*a)); return 0; } else if(d==0){ printf("Both roots are equal.n"); root1 = -b /(2* a);
  • 16. ITP__Practical-File 2019 By AKGandhi Page 16 printf("Root of quadratic equation is:%.3f ",root1); return 0; } else { printf("Roots arereal numbers.n"); root1 = ( -b + sqrt(d)) / (2* a); root2 = ( -b - sqrt(d)) / (2* a); printf("Roots of quadratic equation are:%.3f , %.3f",root1,root2); } getch(); } Output:
  • 17. ITP__Practical-File 2019 By AKGandhi Page 17 PROGRAM 9 AIM : WAP to simulate calculator using switch. Code: #include<stdio.h> #include<conio.h> void main() { char operator; double firstNumber,secondNumber; clrscr(); printf("Enter an operator (+, -, *,/) "); scanf("%c", &operator); printf("Enter two operands: "); scanf("%lf %lf",&firstNumber, &secondNumber); switch(operator) { case'+': printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber + secondNumber); break; case'-': printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber); break; case'*': printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber); break;
  • 18. ITP__Practical-File 2019 By AKGandhi Page 18 case'/': printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber); break; default: printf("Error! operator is notcorrect"); getch(); } Output:
  • 19. ITP__Practical-File 2019 By AKGandhi Page 19 PROGRAM 10 AIM : WAP to check that a character is vowelor consonant Code: #include<stdio.h> #include<conio.h> void main() { char c; int isLowercaseVowel,isUppercaseVowel; clrscr(); printf("Enter an alphabet: "); scanf("%c",&c); isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); if (isLowercaseVowel || isUppercaseVowel) printf("%c is a vowel.", c); else printf("%c is a consonant.", c); getch(); }
  • 21. ITP__Practical-File 2019 By AKGandhi Page 21 PROGRAM 11 AIM : WAP to find sum of digits. Code: #include<stdio.h> #include<conio.h> void main() { int n,sum=0,m; clrscr(); printf("Enter a number:"); scanf("%d",&n); while(n>0) { m=n%10; sum=sum+m; n=n/10; } printf("Sum is=%d",sum); getch(); }
  • 23. ITP__Practical-File 2019 By AKGandhi Page 23 PROGRAM 12 AIM : WAP to reverse a number. Code: #include<stdio.h> #include<conio.h> void main() { int n, reversedNumber = 0, remainder; clrscr(); printf("Enter an integer: "); scanf("%d", &n); while(n != 0) { remainder = n%10; reversedNumber = reversedNumber*10 + remainder; n /= 10; } printf("Reversed Number = %d", reversedNumber); getch(); }
  • 25. ITP__Practical-File 2019 By AKGandhi Page 25 PROGRAM 13 AIM : WAP to check Armstrong number. Code: #include<stdio.h> #include<conio.h> void main() { int n,r,sum=0,temp; printf("enter the number="); scanf("%d",&n); temp=n; while(n>0) { r=n%10; sum=sum+(r*r*r); n=n/10; } If(temp==sum) printf("armstrong number "); else printf("not armstrong number"); getch(); }
  • 27. ITP__Practical-File 2019 By AKGandhi Page 27 PROGRAM 14 AIM : WAP to check palindrome number. Code: #include<stdio.h> #include<conio.h> int main() { int n, reversedInteger = 0, remainder, originalInteger; clrscr(); printf("Enter an integer: "); scanf("%d", &n); originalInteger = n; while( n!=0 ) { remainder = n%10; reversedInteger = reversedInteger*10 + remainder; n /= 10; } if (originalInteger == reversedInteger) printf("%d is a palindrome.", originalInteger); else printf("%d is not a palindrome.",originalInteger); getch(); }
  • 29. ITP__Practical-File 2019 By AKGandhi Page 29 PROGRAM 15 AIM : WAP to find factorialof a number. Code: #include<stdio.h> #include<conio.h> int main() { int n, i; unsigned long longfactorial =1; clrscr(); 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) { factorial *=i; } printf("Factorial of %d = %llu",n, factorial); } getch(); }
  • 31. ITP__Practical-File 2019 By AKGandhi Page 31 PROGRAM 16 AIM : WAP to printFibonacciseries. Code: #include<stdio.h> #include<conio.h> void main() { int i,n, t1 = 0, t2 = 1, nextTerm; clrscr(); printf("Enter the number of terms: "); scanf("%d", &n); printf("Fibonacci Series:"); for (i = 1; i <= n; ++i) { printf("%d, ", t1); nextTerm = t1 + t2; t1 = t2; t2 = nextTerm; } getch(); }
  • 33. ITP__Practical-File 2019 By AKGandhi Page 33 PROGRAM 17 AIM : WAP to check prime number. Code: #include<stdio.h> #include<conio.h> void main() { int n, i,flag= 0; clrscr(); printf("Enter a positiveinteger: "); scanf("%d", &n); for(i = 2; i <= n/2; ++i) { if(n%i == 0) { flag= 1; break; } } if (n == 1) { printf("1 is neither a prime nor a composite number."); } else {
  • 34. ITP__Practical-File 2019 By AKGandhi Page 34 if (flag== 0) printf("%d is a prime number.", n); else printf("%d is not a prime number.", n); } getch(); } Output:
  • 35. ITP__Practical-File 2019 By AKGandhi Page 35 PROGRAM 18 AIM : WAP to calculate X y . Code: #include<stdio.h> #include<conio.h> void main() { int base,exponent; longlong result= 1; clrscr(); printf("Enter a base number: "); scanf("%d", &base); printf("Enter an exponent: "); scanf("%d", &exponent); while(exponent != 0) { result*= base; --exponent; } printf("Answer = %lld", result); getch(); }
  • 37. ITP__Practical-File 2019 By AKGandhi Page 37 PROGRAM 19 AIM : WAP to printhalf pyramid using *. Code: #include<stdio.h> #include<conio.h> void main() { int i,j, rows; clrscr(); printf("Enter number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; ++i) { for(j=1; j<=i; ++j) { printf("* "); } printf("n"); } getch(); }
  • 39. ITP__Practical-File 2019 By AKGandhi Page 39 PROGRAM 20 AIM : WAP to printhalf pyramid a using numbers. Code: #include<stdio.h> #include<conio.h> void main() { int i,j, rows; clrscr(); printf("Enter number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; ++i) { for(j=1; j<=i; ++j) { printf("%d ",j); } printf("n"); } getch(); }
  • 41. ITP__Practical-File 2019 By AKGandhi Page 41 PROGRAM 21 AIM : WAP to printhalf pyramid using alphabets. Code: #include<stdio.h> #include<conio.h> void main() { int i,j; char input, alphabet= 'A'; clrscr(); printf("Enter the uppercasecharacter you want to printin lastrow: "); scanf("%c",&input); for(i=1; i <= (input-'A'+1); ++i) { for(j=1;j<=i;++j) { printf("%c", alphabet); } ++alphabet; printf("n"); } getch(); }
  • 43. ITP__Practical-File 2019 By AKGandhi Page 43 PROGRAM 22 AIM : WAP to printfull pyramid using *. Code: #include<stdio.h> #include<conio.h> void main() { int i,space,rows, k=0; clrscr(); printf("Enter 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"); } getch();
  • 45. ITP__Practical-File 2019 By AKGandhi Page 45 PROGRAM 23 AIM : WAP to print Inverted full pyramid using *. Code: #include<stdio.h> #include<conio.h> void main() { int i,j, rows; clrscr(); printf("Enter number of rows: "); scanf("%d",&rows); for(i=rows; i>=1; --i) { for(j=1; j<=i; ++j) { printf("* "); } printf("n"); } getch(); }
  • 47. ITP__Practical-File 2019 By AKGandhi Page 47 PROGRAM 24 AIM : WAP to print Inverted half pyramid using *. Code: #include<stdio.h> #include<conio.h> void main() { int i,j, rows; clrscr(); printf("Enter number of rows: "); scanf("%d",&rows); for(i=rows; i>=1; --i) { for(j=1; j<=i; ++j) { printf("* "); } printf("n"); } getch(); }
  • 49. ITP__Practical-File 2019 By AKGandhi Page 49 PROGRAM 25 AIM : WAP to calculate factorialusing function.[ With Return Type With Argument Type ] Code: #include<stdio.h> #include<conio.h> floatfact(float) ; void main( ) { floatno,m; clrscr(); printf(“Enter any Value: ”); scanf(“%f”,&no); m = fact(no); printf(“nFactorial of %d = %dn”,no,m); getch(); } floatfact(floatno) { floati,f=1; for(i=no;i>=1;i--) f=f*i; return (f); }
  • 51. ITP__Practical-File 2019 By AKGandhi Page 51 PROGRAM 26 AIM : WAP to calculate factorialusing function.[ With No Return Type With Argument Type ] Code: #include<stdio.h> #include<conio.h> void fact(float) ; void main( ) { floatno; clrscr(); printf(“Enter any Value: ”); scanf(“%f”,&no); fact(no); getch(); } void fact(floatno) { floati,f=1; for(i=no;i>=1;i--) f=f*i; printf(“nFactorial of %d = %dn”,no,f); }
  • 53. ITP__Practical-File 2019 By AKGandhi Page 53 PROGRAM 27 AIM : WAP to calculate factorialusing function.[With NoReturn Type With NoArgument Type] Code: #include<stdio.h> #include<conio.h> void fact(void) ; void main( ) { clrscr(); fact(); getch(); } void fact(void) { int no,i,f=1; printf(“Enter any Value: ”); scanf(“%d”,&no); for(i=no;i>=1;i--) f=f*i; printf(“nFactorial of %d = %dn”,no,f); }
  • 55. ITP__Practical-File 2019 By AKGandhi Page 55 PROGRAM 28 AIM : WAP to calculate factorialusing function.[ With Return Type With No Argument Type ] Code: #include<stdio.h> #include<conio.h> floatfact(void) ; // Function prototype void main( ) { floatm; clrscr(); m = fact(); // Function call printf(“nFactorial =%dn”,m); getch(); } floatfact(void) // Function Definition { int no,i,f=1; printf(“Enter any Value: ”); scanf(“%d”,&no); for(i=no;i>=1;i--) f=f*i; return (f); }
  • 57. ITP__Practical-File 2019 By AKGandhi Page 57 PROGRAM 29 AIM : WAP to calculate factorialusing recursive function. Code: #include<stdio.h> #include<conio.h> float factorial (float); void main( ) { floatno,m; clrscr(); printf(“Enter any Valuen”); scanf(“%f”,&no); m = factorial (no); printf(“Factorial of %.f = %.fn”, m ); getch(); } float factorial (floatno) { if(no <= 0) return 1; else return (no * factorial(no-1)); }
  • 59. ITP__Practical-File 2019 By AKGandhi Page 59 PROGRAM 30 AIM : WAP to calculate Fibonacci series using recursive function. Code: #include<stdio.h> #include<conio.h> int Fibonacci(int); void main() { int n, i = 0, c; scanf("%d",&n); printf("Fibonacci seriesn"); for ( c = 1 ; c <= n ; c++ ) { printf("%dn", Fibonacci(i)); i++; } getch(); } int Fibonacci(intn) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else
  • 60. ITP__Practical-File 2019 By AKGandhi Page 60 return ( Fibonacci(n-1) +Fibonacci(n-2) ); } Output:
  • 61. ITP__Practical-File 2019 By AKGandhi Page 61 PROGRAM 31 AIM : WAP to implement linear search. Code: #include<stdio.h> #include<conio.h> void main() { int array[10]; int i,num, keynum, found = 0; clrscr(); printf("Enter the valueof num n"); scanf("%d", &num); printf("Enter the elements one by one n"); for (i = 0; i < num; i++) { scanf("%d", &array[i]); } printf("Input array is n"); for (i = 0; i < num; i++) { printf("%dn", array[i]); } printf("Enter the element to be searched n"); scanf("%d", &keynum); for (i = 0; i < num ; i++)
  • 62. ITP__Practical-File 2019 By AKGandhi Page 62 { if (keynum == array[i] ) { found = 1; break; } } if (found == 1) printf("Element is present in the arrayn"); else printf("Element is not present in the arrayn"); getch(); } Output:
  • 63. ITP__Practical-File 2019 By AKGandhi Page 63 PROGRAM 32 AIM : WAP to find transpose of given matrix. Code: #include<stdio.h> #include<conio.h> # define SIZE 100 void main() { int no,a[SIZE][SIZE],i,j,row,col; clrscr(); printf("nEnter Row numbers : "); scanf("%d",&row); printf("nEnter column numbers : "); scanf("%d",&col); printf("nEnter %d values.....n ",row*col); for(i=0;i<row;i++) { for(j=0;j<col;j++) { printf("n Enter Value at element [%d][%d]: ",i,j); scanf("%d",&a[i][j]); } } printf("n Data in Traversal Moden"); for(i=0;i<row;i++)
  • 64. ITP__Practical-File 2019 By AKGandhi Page 64 { printf("n|"); for(j=0;j<col;j++) { printf("%6d",a[i][j]); } printf(" |n"); } printf("n Data in TransposeModen"); for(i=0;i<row;i++) { printf("n|"); for(j=0;j<col;j++) { printf("%6d",a[j][i]); } printf(" |n"); } getch(); }
  • 66. ITP__Practical-File 2019 By AKGandhi Page 66 PROGRAM 33 AIM : WAP to printdiagonaleliment. Code: #include<stdio.h> #include<conio.h> void main() { int matrix[10][10]; int i,j,r,c; clrscr(); printf("Enter number of Rows :"); scanf("%d",&r); printf("Enter number of Cols :"); scanf("%d",&c); printf("nEnter matrix elements :n"); for(i=0;i< r;i++) { for(j=0;j< c;j++) { printf("Enter element [%d,%d] : ",i+1,j+1); scanf("%d",&matrix[i][j]); } } if(r==c) {
  • 67. ITP__Practical-File 2019 By AKGandhi Page 67 for(i=0;i< c;i++) { for(j=0;j< r;j++) { if(i==j) printf("%dt",matrix[j][i]); else printf("t"); } printf("n"); } } else { printf("nMatrix is not a Square Matrix."); } getch(); }
  • 69. ITP__Practical-File 2019 By AKGandhi Page 69 PROGRAM 34 AIM : WAP to perform matrixmultiplication. Code: #include<stdio.h> #include<conio.h> # define R 100 # define C 100 void main() { int no,a[R][C],b[R][C],c[R][C],row,col,i,j,k; clrscr(); printf("nEnter Row numbers : "); scanf("%d",&row); printf("nEnter Colom numbers : "); scanf("%d",&col); printf("nEnter %d Valueof Mtrix-A",row*col); for(i=0;i<row;i++) { for(j=0;j<col;j++) { printf("nEnter Value in [%d][%d]:",i,j); scanf("%d",&a[i][j]); } }
  • 70. ITP__Practical-File 2019 By AKGandhi Page 70 printf("nEnter %d Valueof Mtrix-B",row*col); for(i=0;i<row;i++) { for(j=0;j<col;j++) { printf("nEnter Value in [%d][%d]:",i,j); scanf("%d",&b[i][j]); } } printf("n Product of Two Matrices n"); for(i=0;i<row;i++) { printf("n|"); for(j=0;j<col;j++) { c[i][j]=0; for(k=0;k<col;k++) { c[i][j]=c[i][j]+(a[i][k]*b[k][j]); } printf("%5d",c[i][j]); } printf(" |n"); } getch(); }