1. The document contains 12 C programming questions and their solutions ranging from calculating factorials and Fibonacci sequences to matrix operations like addition, multiplication, and inverse.
2. The questions cover basic programming concepts like loops, conditionals, functions as well as mathematical concepts like prime numbers, series, and matrix algebra.
3. The solutions provided implement the required logic to solve each problem using standard C syntax and functions.
Practical Class 12th (c++programs+sql queries and output) Aman Deep
Just download this and do some specific changes in the name section and roll no section . and submit it as it is to your teacher this will surely work and help you out your class 12th board practicals exam . no worries ! ENJOY :) !
Practical Class 12th (c++programs+sql queries and output) Aman Deep
Just download this and do some specific changes in the name section and roll no section . and submit it as it is to your teacher this will surely work and help you out your class 12th board practicals exam . no worries ! ENJOY :) !
Immutability and Javascript - Nadia MiętkiewiczVisuality
Visuality talks Y18W11 - Nadia Miętkiewicz is talking about Immutability and Javascript. Enjoy and subscribe to our channel - more is coming:)
Video is available here:
https://www.youtube.com/watch?v=sMYFOky8CIA&feature=youtu.be
Evolutionary Problems In Aspect Oriented Software Developmentkim.mens
Presented at ERCIM Evolution workshop @ ICSM 2007, inspired by and based on:
K. MENS & T. TOURWE.
Evolution Issues in Aspect-Oriented Programming.
Chapter in book on "Software Evolution", edited by T. Mens & S. Demeyer, pp. 197–224. Springer, 2008.
This presentation identifies evolution-related issues and challenges in aspect-oriented programming. It can serve as a guideline for adopters of aspect technology to get a better idea of the evolution issues they may confront sooner or later, of the risks involved, and of the state-of-the-art in the techniques currently available to help them in addressing these issues. We focus in particular on the programming level, although some of the issues and challenges addressed may apply to earlier software development life-cycle phases as well. The discussed issues range from the exploration of crosscutting concerns in legacy code, via the migration of this code to an aspect-oriented solution, to the maintenance and evolution of the final aspect-oriented program over time. We discuss state-of-the-art techniques which address the issues of aspect exploration, extraction and evolution, and point out several issues for which no adequate solutions exist yet. We conclude that, even though some promising techniques are currently being investigated, due to the relative immaturity of the research domain many of the techniques are not out of the lab as yet.
A short introduction to monad which doesn't involve math.
Code samples are written in C# language for demonstration purpose.
The monad concept is generic in any programming language.
References:
https://weblogs.asp.net/dixin/Tags/Category%20Theory
https://davesquared.net/categories/functional-programming/
https://fsharpforfunandprofit.com/posts/elevated-world/
https://www.ahnfelt.net/monads-forget-about-bind/
https://mikhail.io/tags/functional-programming/
http://adit.io/posts/2013-06-10-three-useful-monads.html
http://learnyouahaskell.com/a-fistful-of-monads
https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/
https://fsharpforfunandprofit.com/posts/elevated-world/#series-toc
https://kubuszok.com/2018/different-ways-to-understand-a-monad/
https://mikehadlow.blogspot.com/2011/01/monads-in-c1-introduction.html
Immutability and Javascript - Nadia MiętkiewiczVisuality
Visuality talks Y18W11 - Nadia Miętkiewicz is talking about Immutability and Javascript. Enjoy and subscribe to our channel - more is coming:)
Video is available here:
https://www.youtube.com/watch?v=sMYFOky8CIA&feature=youtu.be
Evolutionary Problems In Aspect Oriented Software Developmentkim.mens
Presented at ERCIM Evolution workshop @ ICSM 2007, inspired by and based on:
K. MENS & T. TOURWE.
Evolution Issues in Aspect-Oriented Programming.
Chapter in book on "Software Evolution", edited by T. Mens & S. Demeyer, pp. 197–224. Springer, 2008.
This presentation identifies evolution-related issues and challenges in aspect-oriented programming. It can serve as a guideline for adopters of aspect technology to get a better idea of the evolution issues they may confront sooner or later, of the risks involved, and of the state-of-the-art in the techniques currently available to help them in addressing these issues. We focus in particular on the programming level, although some of the issues and challenges addressed may apply to earlier software development life-cycle phases as well. The discussed issues range from the exploration of crosscutting concerns in legacy code, via the migration of this code to an aspect-oriented solution, to the maintenance and evolution of the final aspect-oriented program over time. We discuss state-of-the-art techniques which address the issues of aspect exploration, extraction and evolution, and point out several issues for which no adequate solutions exist yet. We conclude that, even though some promising techniques are currently being investigated, due to the relative immaturity of the research domain many of the techniques are not out of the lab as yet.
A short introduction to monad which doesn't involve math.
Code samples are written in C# language for demonstration purpose.
The monad concept is generic in any programming language.
References:
https://weblogs.asp.net/dixin/Tags/Category%20Theory
https://davesquared.net/categories/functional-programming/
https://fsharpforfunandprofit.com/posts/elevated-world/
https://www.ahnfelt.net/monads-forget-about-bind/
https://mikhail.io/tags/functional-programming/
http://adit.io/posts/2013-06-10-three-useful-monads.html
http://learnyouahaskell.com/a-fistful-of-monads
https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/
https://fsharpforfunandprofit.com/posts/elevated-world/#series-toc
https://kubuszok.com/2018/different-ways-to-understand-a-monad/
https://mikehadlow.blogspot.com/2011/01/monads-in-c1-introduction.html
Questions has 4 parts.1st part Program to implement sorting algor.pdfapexelectronices01
Questions has 4 parts.
1st part: Program to implement sorting algorithms:
#include
#include
#include
using namespace std;
void swap(std::vector & data, int i, int j)
{
int tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
void print(std::vector const & data)
{
std::vector::const_iterator iter = data.begin();
for (; iter != data.end(); ++iter)
{
cout << *iter << \" \";
}
if (data.size() > 0)
{
cout << endl;
}
}
int generateRandom(int low, int high);
void Shuffle(std::vector & data)
{
int length = data.size();
for (int i = 0; i < length-1; ++i)
{
swap(data, i, generateRandom(i+1, length-1));
}
print(data);
}
int generateRandom(int low, int high)
{
srand(low);
int gen = 0;
gen = rand() % (high - low + 1) + low;
return gen;
}
//useful for small lists, and for large lists where data is
//already sorted
void BubbleSort(std::vector & data)
{
int length = data.size();
for (int i = 0; i < length; ++i)
{
bool swapped = false;
for (int j = 0; j < length - (i+1); ++j)
{
if (data[j] > data[j+1])
{
swap(data, j, j+1);
swapped = true;
}
}
if (!swapped) break;
}
}
//useful for small lists and where swapping is expensive
// does at most n swaps
void SelectionSort(std::vector & data)
{
int length = data.size();
for (int i = 0; i < length; ++i)
{
int min = i;
for (int j = i+1; j < length; ++j)
{
if (data[j] < data[min])
{
min = j;
}
}
if (min != i)
{
swap(data, i, min);
}
}
}
//useful for small and mostly sorted lists
//expensive to move array elements
void InsertionSort(std::vector & data)
{
int length = data.size();
for (int i = 1; i < length; ++i)
{
bool inplace = true;
int j = 0;
for (; j < i; ++j)
{
if (data[i] < data[j])
{
inplace = false;
break;
}
}
if (!inplace)
{
int save = data[i];
for (int k = i; k > j; --k)
{
data[k] = data[k-1];
}
data[j] = save;
}
}
}
void Merge(std::vector & data, int lowl, int highl, int lowr, int highr);
void MergeSort(std::vector & data, int low, int high)
{
if (low >= high)
{
return;
}
int mid = low + (high-low)/2;
MergeSort(data, low, mid);
MergeSort(data, mid+1, high);
Merge(data, low, mid, mid+1, high);
}
void Merge(std::vector & data, int lowl, int highl, int lowr, int highr)
{
int tmp_low = lowl;
std::vector tmp;
while (lowl <= highl && lowr <= highr)
{
if (data[lowl] < data[lowr])
{
tmp.push_back(data[lowl++]);
}
else if (data[lowr] < data[lowl])
{
tmp.push_back(data[lowr++]);
}
else
{
tmp.push_back(data[lowl++]);
tmp.push_back(data[lowr++]);
}
}
while (lowl <= highl)
{
tmp.push_back(data[lowl++]);
}
while (lowr <= highr)
{
tmp.push_back(data[lowr++]);
}
std::vector::const_iterator iter = tmp.begin();
for(; iter != tmp.end(); ++iter)
{
data[tmp_low++] = *iter;
}
}
int Partition(std::vector & data, int low, int high);
void QuickSort(std::vector & data, int low, int high)
{
if (low >= high) return;
int p = Partition(data, low, high);
QuickSort(data, low, p-1);
QuickSort(data, p+1, high);
}
int Partition(std::vector & data, int low, int high)
{
int p = low;
for (int i = p+1; i <= high; ++i)
{
if (data[i] < data[p])
{
swap.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
1. P a g e | 1
NB : Make necessary corrections if required
1. Find factorial of a number
#include<stdio.h>
int main()
{
int i,n;
unsigned long long int fact=1;
printf("Enter the number whose factorial is to be found:n");
scanf("%d",&n);
if(n<0)
printf("Error!, The factorial of a negative number does not exist:n");
else
{
if(n==0)
fact=1;
else
for(i=1;i<=n;i++)
fact=fact*i;
printf("Factorial of the given number is:%d",fact);
}
}
2. Obtain Fibonacci series
#include<stdio.h>
int main()
{
int n,i,F1=1,F2=1,F;
printf("Enter the number of elements in series:");
scanf("%d",&n);
//show error if the user enters a negative integer
if(n<0)
printf("Error! number of elements cannot be negative");
else
printf("The Fibonacci series is");
printf("%d%d",F1,F2);
{for(i=3;i<=n;++i)
{
F=F1+F2;
F1=F2;
F2=F;
printf("%d",F);
}
}
return 0;
}
2. P a g e | 2
NB : Make necessary corrections if required
3. To check for a prime number
#include<stdio.h>
#include<math.h>
int main()
{
int n,f=0,d=2;
printf("Enter the number to check whether prime or not:n");
scanf("%d",&n);
do
{
if(n%d==0)
f=1;
d++;
}while(d<=n/2 && f==0);
if(n==2)
f=0;
if(f==0)
printf("The given number is prime:n");
else
printf("The given number is not prime:n");
return 0;
}
4. To write and run C programs to sort a set of numbers in ascending & descending order
using bubble sorting algorithm
#include <stdio.h>
void readarray(int a[],int m)
{
int i;
printf("Enter the elements:n");
for(i=0;i<m;i++) scanf("%d",&a[i]);
}
void swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
void ascending(int a[],int m)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<m-1;j++)
3. P a g e | 3
NB : Make necessary corrections if required
if(a[j]>a[j+1])
swap(&a[j],&a[j+1]);
}
for(i=0;i<m;i++)
printf("%dt",a[i]);
}
void descending(int a[],int m)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<m-1;j++)
if(a[j]<a[j+1])
swap(&a[j],&a[j+1]);
}
for(i=0;i<m;i++)
printf("%dt",a[i]);
}
int main()
{
int n,i,asd[100];
printf("Enter the number of elements:n");
scanf("%d",&n);
readarray(asd,n);
printf("Sorted array in ascending order is:n");
ascending(asd,n);
printf("nSorted array in descending order is:n");
descending(asd,n);
}
5. Write C programs to find inverse of a matrix
#include<stdio.h>
void Swaprows(float a[10][10],int r1,int r2,int n)
{
int j;
float temp;
for(j=0;j<n;j++)
{
temp=a[r1][j];
a[r1][j]=a[r2][j];
a[r2][j]=temp;
}
}
float determinant(float matrix[10][10],int n)
{
int i;
float det=1;
for(i=0;i<n;i++)
4. P a g e | 4
NB : Make necessary corrections if required
det=det*matrix[i][i];
printf("nnDeterminant of the Given matrix is %fn",det);
if(det==0)
{
printf("nnInverse can't be find when determinant is zero:n");
}
return det;
}
void uppertriangular(float matrix[10][10],float idnt[10][10],int n)
{
int i,j,k;
float ratio;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
{
ratio = matrix[i][j]/matrix[j][j];
for(k=0;k<n;k++)
{
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
idnt[i][k]=idnt[i][k]-ratio*idnt[j][k];
}
}
}
}
}
void lowertriangular(float matrix[10][10],float idnt[10][10],int n)
{
int i,j,k;
float ratio;
for(i=n-1;i>=0;i--)
{
for(j=n-1;j>=0;j--)
{
if(i<j)
{
ratio = matrix[i][j]/matrix[j][j];
for(k=0;k<n;k++)
{
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
idnt[i][k]=idnt[i][k]-ratio*idnt[j][k];
}
}
}
}
}
void RowDiv(float a[10][10],float b[10][10],int r,int n,float T)
5. P a g e | 5
NB : Make necessary corrections if required
{
int j;
for(j=0;j<n;j++)
{
a[r][j]=a[r][j]/T;
b[r][j]=b[r][j]/T;
}
}
void print_matrix(float matrix[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
{
printf("%ft",matrix[i][j]);
}
}
}
int main()
{
float matrix[10][10],ratio,idnt[10][10];
int i,j,k,n;
printf("Enter the order of matrix:n");
scanf("%d",&n);
printf("Enter the matrix:n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%f",&matrix[i][j]);
}
printf("nthe matrix is n");
print_matrix(matrix,n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(i==j)
idnt[i][j]=1;
else
idnt[i][j]=0;
}
printf("nIdentity matrix is n");
print_matrix(idnt,n);
for(i=0;i<n;i++)
{
if(matrix[i][i]==0)
{
if(i=n-1)
6. P a g e | 6
NB : Make necessary corrections if required
Swaprows(matrix,i,0,n);
else
Swaprows(matrix,i,i+1,n);
}
}
printf("nnAfter Swaping Operation The given Matrix is changed to: n");
print_matrix(matrix,n);
lowertriangular(matrix,idnt,n);
if(determinant(matrix,n)!=0)
{
uppertriangular(matrix,idnt,n);
printf("nThe given Matrix is changed to: n");
print_matrix(matrix,n);
printf("nIdentity matrix is changed to:n");
print_matrix(idnt,n);
for(i=0;i<n;i++)
RowDiv(matrix,idnt,i,n,matrix[i][i]);
printf("nThe given Matrix is changed to: n");
print_matrix(matrix,n);
printf("nIdentity matrix is changed to:n");
print_matrix(idnt,n);
printf("nInverse of the Given matrix is:n");
print_matrix(idnt,n);
}
}
6. Write C programs to find sum of two matrices
#include <stdio.h>
void read_matrices(int mat1[10][10],int mat2[10][10],int r1,int r2,int c1,int c2)
{
int i,j;
printf("Enter the elements of 1st matrix:n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&mat1[i][j]);
}
printf("Enter the elements of 2nd matrix:n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&mat2[i][j]);
}
}
void Addition(int mat1[10][10],int mat2[10][10],int mat3[10][10],int r1,int r2,int c1,int
c2)
{
int i,j;
7. P a g e | 7
NB : Make necessary corrections if required
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
mat3[i][j]=mat1[i][j]+mat2[i][j];
}
}
void print_matrices(int mat1[10][10],int mat2[10][10],int mat3[10][10],int r1,int r2,int
c1,int c2)
{
int i,j;
printf("nThe 1st matrix is:n");
for(i=0;i<r1;i++)
{
printf("n");
for(j=0;j<c1;j++)
printf("%d t",mat1[i][j]);
}
printf("nThe 2nd matrix is:n");
for(i=0;i<r2;i++)
{
printf("n");
for(j=0;j<c2;j++)
printf("%d t",mat2[i][j]);
}
printf("nThe Addition Result is:n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
printf("%d t",mat3[i][j]);
printf("n");
}
}
int main()
{
int r1,r2,c1,c2,mat1[10][10],mat2[10][10],mat3[10][10];
printf("Enter the no.of rows & columns of Matrix 1 n");
scanf("%d %d",&r1,&c1);
printf("Enter the no.of rows & columns of Matrix 2 n");
scanf("%d %d",&r2,&c2);
if(r1==r2 && c1==c2)
{
read_matrices(mat1,mat2,r1,r2,c1,c2);
Addition(mat1,mat2,mat3,r1,r2,c1,c2);
print_matrices(mat1,mat2,mat3,r1,r2,c1,c2);
}
else
printf("Error! nAddition is not possible if both matrices are of same order n");
return 0;
}
8. P a g e | 8
NB : Make necessary corrections if required
7. Write C programs to find product of two matrices
#include <stdio.h>
void read_matrices(int mat1[10][10],int mat2[10][10],int r1,int r2,int c1,int c2)
{
int i,j;
printf("Enter the elements of 1st matrix:n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&mat1[i][j]);
}
printf("Enter the elements of 2nd matrix:n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&mat2[i][j]);
}
}
void multiplication(int mat1[10][10],int mat2[10][10],int mat3[10][10],int r1,int r2,int
c1,int c2)
{
int i,j,k,sum;
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
mat3[i][j]=0;
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
for(k=0;k<c1;k++)
mat3[i][j]=mat3[i][j]+mat1[i][k]*mat2[k][j];
}
void print_matrices(int mat1[10][10],int mat2[10][10],int mat3[10][10],int r1,int r2,int
c1,int c2)
{
int i,j;
printf("nThe 1st matrix is:n");
for(i=0;i<r1;i++)
{
printf("n");
for(j=0;j<c1;j++)
printf("%d t",mat1[i][j]);
}
printf("nThe 2nd matrix is:n");
for(i=0;i<r2;i++)
{
printf("n");
for(j=0;j<c2;j++)
printf("%d t",mat2[i][j]);
9. P a g e | 9
NB : Make necessary corrections if required
}
printf("nThe multiplication Result is:n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
printf("%d t",mat3[i][j]);
printf("n");
}
}
int main()
{
int r1,r2,c1,c2,mat1[10][10],mat2[10][10],mat3[10][10];
printf("Enter the no.of rows & columns of Matrix 1 n");
scanf("%d %d",&r1,&c1);
printf("Enter the no.of rows & columns of Matrix 2 n");
scanf("%d %d",&r2,&c2);
if(r2==c1)
{
read_matrices(mat1,mat2,r1,r2,c1,c2);
multiplication(mat1,mat2,mat3,r1,r2,c1,c2);
print_matrices(mat1,mat2,mat3,r1,r2,c1,c2);
}
else
printf("Error! nMultiplication is not possiblen");
return 0;
}
8. Write C programs to find determinant of a matrix
#include<stdio.h>
int main()
{
float matrix[10][10],ratio,det=1;
int i,j,k,n;
printf("Enter the order of matrix:");
scanf("%d",&n);
printf("Enter the matrix: n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%f",&matrix[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
{
ratio = matrix[i][j]/matrix[j][j];
10. P a g e | 10
NB : Make necessary corrections if required
for(k=0;k<n;k++)
{
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
}
}
}
}
printf("the upper triangular matrix is ");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
{
printf("%ft",matrix[i][j]);
}
}
for(i=0;i<n;i++)
det=det*matrix[i][i];
printf("nDeterminand of given matrix is:%f",det);
}
9. Using C program find
( )!
, where m and n are integers.
#include <stdio.h>
int main()
{
int n,fact=1,i,m,r;
printf("Enter the number 'n':n");
scanf("%d",&n);
printf("Enter the number 'm':n");
scanf("%d",&m);
for(i=1;i<n;i++)
fact=fact*i;
r=fact/m;
printf("The result is:%d",r);
}
10. Write a c program to obtain the series 7 7 14 21 35 up to n terms
#include <stdio.h>
int main()
{
int f1=7,f2=7,f,n;
printf("Enter the number of elements in the fibonacci series:t");
scanf("%d",&n);
if(n<=0)
printf("Error! Number of elements can not be zero or negative:n");
else
11. P a g e | 11
NB : Make necessary corrections if required
{
printf("nFibonacci series is:");
printf("n%dt%d",f1,f2);
for(int i=3;i<=n;i++)
{
f=f1+f2;
printf("t%d",f);
f1=f2;
f2=f;
}
}
}
11. Write a C program to list all prime numbers between 10 and 20
#include<stdio.h>
int main()
{
int n,f,d;
for(n=10;n<=20;n++)
{
f=0;
for(d=2;d<n/2;d++)
{
if(n%d==0)
f=1;
}
if(f==0)
printf("%dn",n);
}
}
12. A number is given. Check whether it is prime or not ? If so, get next even number. Else,
get next odd number.
#include<stdio.h>
int main()
{
int n,f=0,d=2;
printf("Enter the number : n");
scanf("%d",&n);
for(d=2;d<n/2;d++)
{
if(n%d==0)
f=1;
}
if(f==0)
{
printf("The Number %d is primen",n);
12. P a g e | 12
NB : Make necessary corrections if required
if(n%2==0)
printf("The next even number is %d n",n+2);
else
printf("The next even number is %d n",n+1);
}
if(f==1)
{
printf("The Number %d is not primen",n);
if(n%2==1)
printf("The next odd number is %d n",n+2);
else
printf("The next odd number is %d n",n+1);
}
}
13. Write a program to interchange second and fourth numbers of an array
#include <stdio.h>
int main()
{
int array[10],i,n,temp;
printf("Enter size of arrayn");
scanf("%d",&n);
printf("Enter elements of arrayn");
for(i=0;i<n;i++)
scanf("%d",&array[i]);
printf("The elements of given array aren");
for(i=0;i<n;i++)
printf("array[%d]=%dn",i,array[i]);
temp=array[1];
array[1]=array[3];
array[3]=temp;
printf("The elements of array after swaping aren");
for(i=0;i<n;i++)
printf("array[%d]=%dn",i,array[i]);
}
14. Using C program to find largest number from an array
#include<stdio.h>
int main()
{
int n,i,a[100],lr;
printf("Enter the number of elements:n ");
scanf("%d",&n);
printf("Enter the number of elements:n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
lr=a[0];
13. P a g e | 13
NB : Make necessary corrections if required
for(i=0;i<n-1;i++)
{
if(a[i+1]>lr)
lr=a[i+1];
}
printf("nLargest number is %d",lr);
return 0;
}
15. Write C program to interchange first and third rows of a matrix
#include <stdio.h>
int main()
{
int n,m[10][10],i,j,temp;
printf("Enter the order of matrix:n");
scanf("%d",&n);
printf("enter the elementsn");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%d",&m[i][j]);
}
printf("given matrix isn");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%dt",m[i][j]);
}
for(j=0;j<n;j++)
{
temp=m[0][j];
m[0][j]=m[2][j];
m[2][j]=temp;
}
printf("nthe result isn");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%dt",m[i][j]);
}
}
16. Write C program to interchange a row and next row of a matrix
#include <stdio.h>
int main()
14. P a g e | 14
NB : Make necessary corrections if required
{
int n,m[10][10],i,j,temp,k;
printf("Enter the order of matrix:n");
scanf("%d",&n);
printf("enter the elementsn");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%d",&m[i][j]);
}
printf("given matrix isn");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%dt",m[i][j]);
}
printf("nEnter the row number you want to interchange:n");
scanf("%d",&k);
for(j=0;j<n;j++)
{
temp=m[k-1][j];
m[k-1][j]=m[k][j];
m[k][j]=temp;
}
printf("nthe result isn");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%dt",m[i][j]);
}
}
17. An nxn matrix is given. Convert it into an upper triangular matrix using C
program
#include<stdio.h>
int main()
{
float matrix[10][10],ratio;
int i,j,k,n;
printf("Enter the order of matrix:n");
scanf("%d",&n);
printf("Enter the elements of matrix: n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%f",&matrix[i][j]);
15. P a g e | 15
NB : Make necessary corrections if required
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
{
ratio = matrix[i][j]/matrix[j][j];
for(k=0;k<n;k++)
{
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
}
}
}
}
printf("the upper triangular matrix is ");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
{
printf("%ft",matrix[i][j]);
}
}
}
18. An nxn matrix is given. Convert it into a lower triangular matrix using C program
#include<stdio.h>
int main()
{
float matrix[10][10],ratio;
int i,j,k,n;
printf("Enter the order of matrix:");
scanf("%d",&n);
printf("Enter the matrix: n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%f",&matrix[i][j]);
}
for(i=n-1;i>=0;i--)
{
for(j=n-1;j>=0;j--)
{
if(i<j)
{
ratio = matrix[i][j]/matrix[j][j];
16. P a g e | 16
NB : Make necessary corrections if required
for(k=0;k<n;k++)
{
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
}
}
}
}
printf("the lower triangular matrix is ");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
{
printf("%ft",matrix[i][j]);
}
}
}
19. Consider the augmented matrix Ab = A/I, where A is an nXn matrix and I is an identity
matrix of order n. Do same elementary operations on both A and I so that A is
transformed into an upper triangular matrix. Write a C program.
#include<stdio.h>
void print_matrix(float matrix[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
{
printf("%ft",matrix[i][j]);
}
}
}
int main()
{
float matrix[10][10],ratio,idnt[10][10];
int i,j,k,n;
printf("Enter the order of matrix:");
scanf("%d",&n);
printf("Enter the matrix: n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%f",&matrix[i][j]);
}
for(i=0;i<n;i++)
17. P a g e | 17
NB : Make necessary corrections if required
{
for(j=0;j<n;j++)
if(i==j)
idnt[i][j]=1;
else
idnt[i][j]=0;
}
printf("nIdentity matrix is n");
print_matrix(idnt,n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
{
ratio = matrix[i][j]/matrix[j][j];
for(k=0;k<n;k++)
{
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
idnt[i][k]=idnt[i][k]-ratio*idnt[j][k];
}
}
}
}
printf("nthe upper triangular matrix is n");
print_matrix(matrix,n);
printf("nIdentity matrix is changed ton");
print_matrix(idnt,n);
}
20. Using C program, find + , where A and B are matrices.
#include <stdio.h>
int main()
{
int i,j,n,a[10][10],b[10][10],c[10][10],d[10][10],k;
printf("Enter the order of matrix :n");
scanf("%d",&n);
printf("Enter the elements of matrix A:n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("Enter the elements of matrix B:n");
for(i=0;i<n;i++)
{
18. P a g e | 18
NB : Make necessary corrections if required
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
c[i][j]=0;
}
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*a[k][j];
}
printf("nThe A^2 matrix is:n");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%d t",c[i][j]);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
d[i][j]=c[i][j]+b[i][j];
printf("nThe Final result is:n");
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%d t",d[i][j]);
}
}
21. Write a C program to find the solution of
= sin
Using Euler method.
#include<stdio.h>
#include<math.h>
float function(float x,float t)
{
float f=sin(x);
return f;
}
void euler(int n,float t0,float tn,float x0,float x[100],float t[100])
{
int k=0;
x[0]=x0;
t[0]=t0;
19. P a g e | 19
NB : Make necessary corrections if required
float h=(tn-t0)/n;
while(t[k]!=tn)
{
x[k+1]=x[k]+h*function(x[k],t[k]);
t[k+1]=t[k]+h;
k++;
}
}
int main()
{
int i,n;
float t0,tn,x0,t[100],x[100];
printf("nEnter the initial & final times nEnter no.of iterations:n");
scanf("%f%f%d",&t0,&tn,&n);
printf("Enter the initial value:x0n");
scanf("%f",&x0);
printf("nsolution using euler's methodnn");
euler(n,t0,tn,x0,x,t);
printf("ttxnn");
for(i=0;i!=n;i++)
printf("%2.4ft%2.4fn",t[i],x[i]);
return 0;
}
22. Write a C program to find the solution of
= cos
using Ranga-Kutta method.
#include<stdio.h>
#include<math.h>
float fnctn(float x,float t)
{
float f;
f=cos(x);
return f;
}
void RK(int n,float t0,float tn,float x0,float x[100],float t[100])
{
float h,K1,K2,K3,K4;
int m;
t[0]=t0;
x[0]=x0;
m=0;
h=(tn-t0)/n;
while(t[m]<=tn)
{
K1=h*fnctn(x[m],t[m]);
20. P a g e | 20
NB : Make necessary corrections if required
K2=h*fnctn(x[m]+K1/2,t[m]+h/2);
K3=h*fnctn(x[m]+K2/2,t[m]+h/2);
K4=h*fnctn(x[m]+K3/2,t[m]+h);
x[m+1]=x[m]+(K1+2*K2+2*K3+K4)/6;
t[m+1]=t[m]+h;
m=m+1;
}
}
int main()
{
int n,i;
float x[100],t[100],t0,tn;
printf("enter initial and final times and number of iterations:n");
scanf("%f%f%d",&t0,&tn,&n);
printf("enter the initial value x0:");
scanf("%f",&x[0]);
printf("n solution using Runge-Kutta methodnn");
RK(n,t0,tn,x[0],x,t);
printf("ttxn");
for(i=0;i!=n;i++)
printf("%ft%fn",t[i],x[i]);
return 0;
}
23. Using C program,find the solution of linear equations. (Use Gauss elimination method)
#include<stdio.h>
int main()
{
int i,j,k,n;
float A[20][20],c,x[10],sum=0.0;
printf("nEnter the order of matrix: ");
scanf("%d",&n);
printf("nEnter the elements of augmented matrix row-wise:nn");
for(i=1; i<=n; i++)
{
for(j=1; j<=(n+1); j++)
{
printf("A[%d][%d] : ", i,j);
scanf("%f",&A[i][j]);
}
}
for(j=1; j<=n; j++) /* loop for the generation of upper triangular matrix*/
{
for(i=1; i<=n; i++)
{
if(i>j)
{
c=A[i][j]/A[j][j];
21. P a g e | 21
NB : Make necessary corrections if required
for(k=1; k<=n+1; k++)
{
A[i][k]=A[i][k]-c*A[j][k];
}
}
}
}
x[n]=A[n][n+1]/A[n][n];
/* this loop is for backward substitution*/
for(i=n-1; i>=1; i--)
{
sum=0;
for(j=i+1; j<=n; j++)
{
sum=sum+A[i][j]*x[j];
}
x[i]=(A[i][n+1]-sum)/A[i][i];
}
printf("nThe solution is: n");
for(i=1; i<=n; i++)
{
printf("nx%d=%ft",i,x[i]); /* x1, x2, x3 are the required solutions*/
}
return(0);
}
24. Using C program,find the solution of linear equations. (Use Gauss siedal method)
#include<stdio.h>
int main()
{
float a[10][10],b[10],x[10],y[10];
intn,m,i,j;
printf("Enter the no. of linear equation n");
scanf("%d",&n);
printf("Enter the coefficients of the equationsn");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("Matrix[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
}
printf("nEnter Values of the right side of equationn");
for(i=0;i<n;i++)
{
printf("b[%d] = ",i);
22. P a g e | 22
NB : Make necessary corrections if required
scanf("%f",&b[i]);
}
printf("Enter initial values of xn");
for(i=0;i<n;i++)
{
printf("x[%d] = ",i);
scanf("%f",&x[i]);
}
printf("nEnter the no. of iteration :");
scanf("%d",&m);
while(m>0)
{
for(i=0;i<n;i++)
{
y[i]=(b[i]/a[i][i]);
for(j=0;j<n;j++)
{
if(j==i)
continue;
y[i]=y[i]-((a[i][j]/a[i][i])*x[j]);
x[i]=y[i];
}
printf("x%d=%6.2f ",i+1,y[i]);
}
printf("n");
m--;
}
return 0;
}
25. Using C program, find the sum of first n Fibonacci numbers
#include<stdio.h>
int main()
{
int n,i,F1=1,F2=1,F,sum=F1+F2;
printf("Enter the number of elements in series:t");
scanf("%d",&n);
if(n<0)
printf("Error! number of elements cannot be negative");
else
{
printf("The Fibonacci series isn");
printf("%dt%dt",F1,F2);
{
for(i=3;i<=n;++i)
{
F=F1+F2;
sum=sum+F;
23. P a g e | 23
NB : Make necessary corrections if required
F1=F2;
F2=F;
printf("%dt",F);
}
printf("nThe sum of the fibonacci series is:t%d",sum);
}
}
return 0;
}
26. Use C program, to get number of Fibonacci numbers between 1 and n, where n is an
integer.
#include<stdio.h>
int main()
{
int n,i=3,F1=1,F2=1,F,sum=F1+F2,j=2;;
printf("Enter the number n :t");
scanf("%d",&n);
if(n<0)
printf("Error! number of elements cannot be negative");
else
{
printf("The Fibonacci series isn");
printf("%dt%dt",F1,F2);
while((F1+F2)<=n)
{
F=F1+F2;
F1=F2;
F2=F;
printf("%dt",F);
i++;
j++;
}
printf("nThe no.of elements in fibonacci series is : t%d",j);
}
return 0;
}
27. Use C program, to get number of odd Fibonacci numbers between 1 and n, where n is
an integer. Using C program list all even Fibonacci numbers between 1 and n, where n
is an integer.
#include<stdio.h>
int main()
{
int n,F1=1,F2=1,F,sum=F1+F2,j=2;;
printf("Enter the number n :t");
24. P a g e | 24
NB : Make necessary corrections if required
scanf("%d",&n);
if(n<0)
printf("Error! number of elements cannot be negative");
else
{
printf("The Even Fibonacci series isn");
while((F1+F2)<=n)
{
F=F1+F2;
F1=F2;
F2=F;
if(F%2==0)
printf("%dt",F);
else
j++;
}
printf("nThe no.of odd elements in fibonacci series is : t%d",j);
}
return 0;
}
28. With a C program, get
!
( − )! !
Use minimum number of codes (use functions).
#include<stdio.h>
long long int factorial(int m)
{
long long int fact=1;
for(int i=1;i<=m;i++)
fact=fact*i;
return fact;
}
int main()
{
int n,r;
long long int k;
printf("Enter the numbers n & r :n");
scanf("%d%d",&n,&r);
k=factorial(n)/(factorial(n-r)*factorial(r));
printf("The %dC%d is :t%d",n,r,k);
}
29. Use C program to list all prime numbers between 1 and n.
#include<stdio.h>
25. P a g e | 25
NB : Make necessary corrections if required
int main()
{
int n,m,f,d;
printf("Enter the upper limit n:n");
scanf("%d",&m);
printf("Prime numbers between 1 & %d isn",m);
for(n=1;n<=m;n++)
{
f=0;
for(d=2;d<=n/2;d++)
{
if(n%d==0)
f=1;
}
if(f==0)
printf("%dn",n);
}
}
30. A set of numbers are given. With a c program, group them to prime and composite
numbers and then arrange each group in descending order.
#include<stdio.h>
void swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
void sorting(int a[50],int m)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<m-1;j++)
if(a[j]<a[j+1])
swap(&a[j],&a[j+1]);
}
}
void print_numbers(int prime[50],int not_prime[50],int k,int j)
{
int i;
printf("The list of prime numbers is:n");
for(i=0;i<j;i++)
printf("%dn",prime[i]);
printf("The list of composite numbers is:n");
for(i=0;i<k;i++)
printf("%dn",not_prime[i]);
}
void prime_numbers(int a[50],int n)
26. P a g e | 26
NB : Make necessary corrections if required
{
int prime[50],not_prime[50];
int f,d,i,j=0,k=0;
for(i=0;i<n;i++)
{
f=0;
for(d=2;d<=n/2;d++)
{
if(a[i]%d==0)
f=1;
}
if(f==0)
{
prime[j]=a[i];
j++;
}
else
{
not_prime[k]=a[i];
k++;
}
}
sorting(prime,j);
sorting(not_prime,k);
print_numbers(prime,not_prime,k,j);
}
int main()
{
int n,f,d,i,a[50],j=0,k=0,prime[50],not_prime[50];
printf("Enter the no.of elements n:n");
scanf("%d",&n);
printf("Enter the elements:n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
prime_numbers(a,n);
}
31. A list of integers are given. Arrange the numbers such that first three numbers are
arranged in descending order and remaining in ascending order. Use minimum number
of codes
#include<stdio.h>
void readarray(int a[],int m)
{
int i;
printf("Enter the elements:n");
for(i=0;i<m;i++)
scanf("%d",&a[i]);
}
27. P a g e | 27
NB : Make necessary corrections if required
void swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
void ascending(int a[],int m)
{
int i,j;
for(i=3;i<m;i++)
{
for(j=3;j<m-1;j++)
if(a[j]>a[j+1])
swap(&a[j],&a[j+1]);
}
}
void descending(int a[],int m)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<m-1;j++)
if(a[j]<a[j+1])
swap(&a[j],&a[j+1]);
}
}
int main()
{
int n,i,asd[100];
printf("Enter the number of elements:n");
scanf("%d",&n);
readarray(asd,n);
printf("Sorted array in which 1st 3 numbers are in descending order & remaining
in ascending order is:n");
descending(asd,3);
ascending(asd,n);
for(i=0;i<n;i++)
printf("%dt",asd[i]);
}
32. Show that ∗ =
#include<stdio.h>
void Swaprows(float a[10][10],int r1,int r2,int n)
{
int j;
float temp;
for(j=0;j<n;j++)
{
28. P a g e | 28
NB : Make necessary corrections if required
temp=a[r1][j];
a[r1][j]=a[r2][j];
a[r2][j]=temp;
}
}
float determinant(float matrix[10][10],int n)
{
int i;
float det=1;
for(i=0;i<n;i++)
det=det*matrix[i][i];
printf("nnDeterminant of the Given matrix is %fn",det);
if(det==0)
{
printf("nnInverse can't be find when determinant is zero:n");
}
return det;
}
void uppertriangular(float matrix[10][10],float idnt[10][10],int n)
{
int i,j,k;
float ratio;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
{
ratio = matrix[i][j]/matrix[j][j];
for(k=0;k<n;k++)
{
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
idnt[i][k]=idnt[i][k]-ratio*idnt[j][k];
}
}
}
}
}
void lowertriangular(float matrix[10][10],float idnt[10][10],int n)
{
int i,j,k;
float ratio;
for(i=n-1;i>=0;i--)
{
for(j=n-1;j>=0;j--)
{
if(i<j)
{
ratio = matrix[i][j]/matrix[j][j];
29. P a g e | 29
NB : Make necessary corrections if required
for(k=0;k<n;k++)
{
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
idnt[i][k]=idnt[i][k]-ratio*idnt[j][k];
}
}
}
}
}
void RowDiv(float a[10][10],float b[10][10],int r,int n,float T)
{
int j;
for(j=0;j<n;j++)
{
a[r][j]=a[r][j]/T;
b[r][j]=b[r][j]/T;
}
}
void print_matrix(float matrix[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%ft",matrix[i][j]);
}
}
void multiplication(float matrix1[10][10],float matrix2[10][10],int n)
{
int i,j,k;
float matrix3[10][10],sum;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
sum=0;
for(k=0;k<n;k++)
sum=sum+matrix1[i][k]*matrix2[k][j];
matrix3[i][j]=sum;
}
print_matrix(matrix3,n);
}
int main()
{
float matrix[10][10],ratio,inverse[10][10],idnt[10][10],matrix2[10][10];
int i,j,k,n;
printf("Enter the order of matrix:n");
scanf("%d",&n);
printf("Enter the matrix:n");
30. P a g e | 30
NB : Make necessary corrections if required
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%f",&matrix[i][j]);
}
printf("nthe matrix is n");
print_matrix(matrix,n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(i==j)
inverse[i][j]=1;
else
inverse[i][j]=0;
}
printf("nIdentity matrix is n");
print_matrix(inverse,n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
matrix2[i][j]=matrix[i][j];
for(i=0;i<n;i++)
{
if(matrix[i][i]==0)
{
if(i=n-1)
Swaprows(matrix,i,0,n);
else
Swaprows(matrix,i,i+1,n);
}
}
printf("nnAfter Swaping Operation The given Matrix is changed to: n");
print_matrix(matrix,n);
lowertriangular(matrix,inverse,n);
if(determinant(matrix,n)!=0)
{
uppertriangular(matrix,inverse,n);
printf("nThe given Matrix is changed to: n");
print_matrix(matrix,n);
printf("nIdentity matrix is changed to:n");
print_matrix(inverse,n);
for(i=0;i<n;i++)
RowDiv(matrix,inverse,i,n,matrix[i][i]);
printf("nThe given Matrix is changed to: n");
print_matrix(matrix,n);
printf("nIdentity matrix is changed to:n");
print_matrix(inverse,n);
printf("nInverse of the Given matrix is:n");
print_matrix(inverse,n);
printf("nThe Given matrix is : n");
31. P a g e | 31
NB : Make necessary corrections if required
print_matrix(matrix2,n);
printf("nThe multiplication result is (A*A^-1) is : n");
multiplication(matrix2,inverse,n);
}
}
33. Use c program to interchange two rows of a matrix with highest and lowest diagonal
elements.
#include <stdio.h>
void swap(int m[10][10],int n,int p,int q)
{
int j,temp;
for(j=0;j<n;j++)
{
temp=m[p][j];
m[p][j]=m[q][j];
m[q][j]=temp;
}
}
void print_matrix(int m[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%dt",m[i][j]);
}
}
int largest(int m[10][10],int n)
{
int i,large=m[0][0];
for(i=0;i<n;i++)
{
if(m[i][i]>=large)
large=m[i][i];
}
for(i=0;i<n;i++)
if(large==m[i][i])
return i;
}
int smallest(int m[10][10],int n)
{
int i,small=m[0][0];
for(i=0;i<n;i++)
{
if(m[i][i]<=small)
small=m[i][i];
32. P a g e | 32
NB : Make necessary corrections if required
}
for(i=0;i<n;i++)
if(small==m[i][i])
return i;
}
int main()
{
int n,m[10][10],i,j,temp,p,q;
printf("Enter the order of matrix:n");
scanf("%d",&n);
printf("enter the elementsn");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%d",&m[i][j]);
}
printf("given matrix isn");
print_matrix(m,n);
p=largest(m,n);
q=smallest(m,n);
swap(m,n,p,q);
printf("nAfter swapping rows with highest & lowest diagonal elements : n");
print_matrix(m,n);
}
34. Use c program to get 2I - A, where A is a square matrix and I is an identity matrix of
order n.
#include <stdio.h>
void print_matrix(int m[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%d t",m[i][j]);
}
}
void subtraction(int mat1[10][10],int mat2[10][10],int n)
{
int i,j,mat3[10][10];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
mat3[i][j]=mat1[i][j]-mat2[i][j];
}
printf("n2I-A matrix is : n");
print_matrix(mat3,n);
33. P a g e | 33
NB : Make necessary corrections if required
}
int main()
{
int n,MatA[10][10],idnt[10][10],i,j;
printf("Enter the order of A matrix:n");
scanf("%d",&n);
printf("Enter the elements of A matrix : n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&MatA[i][j]);
printf("The A matrix is : n");
print_matrix(MatA,n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(i==j)
idnt[i][j]=2;
else
idnt[i][j]=0;
}
printf("nThe 2I matrix is : n");
print_matrix(idnt,n);
subtraction(idnt,MatA,n);
}
35. Use c program to get (2I - A)/det(A), where A is a square matrix and I is an identity
matrix of order n.
#include <stdio.h>
void print_matrix(float m[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%f t",m[i][j]);
}
}
void RowDiv(float a[10][10],int n,float T)
{
int j,r;
for(r=0;r<n;r++)
{
for(j=0;j<n;j++)
a[r][j]=a[r][j]/T;
}
34. P a g e | 34
NB : Make necessary corrections if required
printf("nnThe Result (2I-A)/det(A) is : n");
print_matrix(a,n);
}
void subtraction(float mat1[10][10],float mat2[10][10],int n,float det)
{
int i,j;
float mat3[10][10];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
mat3[i][j]=mat1[i][j]-mat2[i][j];
}
printf("nn2I-A matrix is : n");
print_matrix(mat3,n);
RowDiv(mat3,n,det);
}
float determinant(float matrix[10][10],int n)
{
int i,j,ratio,k;
float det=1;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
{
ratio = matrix[i][j]/matrix[j][j];
for(k=0;k<n;k++)
matrix[i][k]=matrix[i][k]-ratio*matrix[j][k];
}
}
}
for(i=0;i<n;i++)
det=det*matrix[i][i];
return det;
}
int main()
{
int n,i,j;
float MatA[10][10],det,idnt[10][10],MatB[10][10];
printf("Enter the order of A matrix:n");
scanf("%d",&n);
printf("Enter the elements of A matrix : n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%f",&MatA[i][j]);
printf("The A matrix is : n");
print_matrix(MatA,n);
35. P a g e | 35
NB : Make necessary corrections if required
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
MatB[i][j]=MatA[i][j];
if(i==j)
idnt[i][j]=2;
else
idnt[i][j]=0;
}
printf("nnThe 2I matrix is : n");
print_matrix(idnt,n);
det=determinant(MatB,n);
printf("nnDeterminant of the A matrix is : %fn",det);
subtraction(idnt,MatA,n,det);
}
36. Arrange rows of a matrix such that the sum of rows are in ascending order.
#include <stdio.h>
void print_matrix(int m[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%dt",m[i][j]);
}
}
void sum_of_rows(int mat[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
mat[i][n]=0;
for(j=0;j<n;j++)
mat[i][n]=mat[i][n]+mat[i][j];
}
printf("nThe sum of rows are : n");
for(i=0;i<n;i++)
printf("%dn",mat[i][n]);
}
void swap(int a,int b,int mt[10][10],int n)
{
int j,temp;
for(j=0;j<=n;j++)
{
temp=mt[a][j];
mt[a][j]=mt[b][j];
36. P a g e | 36
NB : Make necessary corrections if required
mt[b][j]=temp;
}
}
void ascending(int a[10][10],int m)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<m-1;j++)
if(a[j][m]>a[j+1][m])
swap(j,j+1,a,m);
}
for(i=0;i<m;i++)
printf("%dt",a[i][m]);
}
int main()
{
int mat[10][10],n,sum[10],i,j;
printf("Enter the order of the matrix : n");
scanf("%d",&n);
printf("Enter the elements of matrix :n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&mat[i][j]);
printf("The Given Matrix is : n");
print_matrix(mat,n);
sum_of_rows(mat,n);
printf("nThe sum of rows of matrix in Ascending order is :n");
ascending(mat,n);
printf("nnAfter Arranging rows of a matrix such that the sum of rows are in
ascending order :n");
print_matrix(mat,n);
}
37. Using C program, verify that in general AB ≠ BA
#include<stdio.h>
void multiplication(int mat1[10][10],int mat2[10][10],int mat3[10][10],int n)
{
int i,j,k,sum;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
sum=0;
for(k=0;k<n;k++)
sum=sum+mat1[i][k]*mat2[k][j];
mat3[i][j]=sum;
37. P a g e | 37
NB : Make necessary corrections if required
}
}
void print_matrix(int m[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%dt",m[i][j]);
}
}
void check_equality(int A1[10][10],int A2[10][10],int n)
{
int i,j,f=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(A1[i][j]==A2[i][j])
f++;
}
if(f==n*n)
printf("nFrom the above results AB=BAn");
else
printf("nFrom the above results AB!=BAn");
}
int main()
{
int n,A[10][10],B[10][10],AB[10][10],BA[10][10],i,j;
printf("Enter the order of the Matrix:n");
scanf("%d",&n);
printf("Enter Elements of A matrix :n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&A[i][j]);
printf("nA matrix is : n");
print_matrix(A,n);
printf("nEnter Elements of B matrix :n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&B[i][j]);
printf("nB matrix is : n");
print_matrix(B,n);
multiplication(A,B,AB,n);
printf("nAB matrix is : n");
print_matrix(AB,n);
multiplication(B,A,BA,n);
printf("nBA matrix is : n");
print_matrix(BA,n);
38. P a g e | 38
NB : Make necessary corrections if required
check_equality(AB,BA,n);
}
38. Using c program, find + 2 where A and B are matrices.
#include <stdio.h>
void print_matrix(int d[10][10],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("n");
for(j=0;j<n;j++)
printf("%d t",d[i][j]);
}
}
int main()
{
int i,j,n,a[10][10],b[10][10],c[10][10],d[10][10],k;
printf("Enter the order of matrix :n");
scanf("%d",&n);
printf("Enter the elements of matrix A:n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("Enter the elements of matrix B:n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
c[i][j]=0;
}
}
printf("nThe A Matrix is :n");
print_matrix(a,n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
b[i][j]=2*b[i][j];
}
printf("nThe 2B Matrix is :n");
print_matrix(b,n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
39. P a g e | 39
NB : Make necessary corrections if required
c[i][j]=c[i][j]+a[i][k]*a[k][j];
}
printf("nThe A^2 matrix is:n");
print_matrix(c,n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
d[i][j]=c[i][j]+b[i][j];
printf("nThe Final result A^2+2B is :n");
print_matrix(d,n);
}
39. Using c program, Check whether a number is palindrom or not ?
#include<stdio.h>
int main()
{
int n, reverse=0, temp;
printf("Enter the number to check palindrome or notn");
scanf("%d",&n);
temp=n;
while(temp!=0)
{
reverse=reverse*10;
reverse=reverse+temp%10;
temp=temp/10;
}
if(n==reverse)
printf("The given number %d is palindrome numbern",n);
else
printf("The given number %d is not palindrome numbern",n);
}
40. Using c program, Check whether a string is palindrom or not ?
#include<stdio.h>
#include<string.h>
int main()
{
char a[100], b[100];
printf("Enter the word to check palindromn");
gets(a);
strcpy(b,a);
strrev(b);
if(strcmp(a,b)==0)
printf("Enterd string is a palindromen");
else
printf("Enterd string is not palindromen");
return 0;
40. P a g e | 40
NB : Make necessary corrections if required
}
41. Write C Program to find solution of a Quadratic Equation ?
#include<stdio.h>
#include<math.h>
int main()
{
float a, b, c, determinant,r1,r2,real,imag;
printf("Enter the coefficients a,b and c n");
scanf("n%f n%f n%f",&a,&b,&c);
determinant=b*b-4*a*c;
printf("Determinant is : t %f n",determinant);
if(determinant>0)
{
r1=(-b+sqrt(determinant))/(2*a);
r2=(-b-sqrt(determinant))/(2*a);
printf("Roots are: %f and %f",r1,r2);
}
else if(determinant==0)
{
r1=r2=-b/(2*a);
printf("Roots are: %f and %f",r1,r2);
}
else
{
real=-b/(2*a);
imag=sqrt(-determinant)/(2*a);
printf("Roots are : %f+j%f and t %f-j%f ",real,imag,real,imag);
}
return 0;
}
42. Use c program, to find the matrix[ … ]
#include <stdio.h>
read_matrix(float a[10][10],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%f",&a[i][j]);
41. P a g e | 41
NB : Make necessary corrections if required
}
void print_matrix(float d[10][10],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
printf("n");
for(j=0;j<c;j++)
printf("%f t",d[i][j]);
}
}
void multiplication(float a[10][10],float b[10][10],float c[10][10],int r,int d)
{
int i,j,k;
for(i=0;i<r;i++)
for(j=0;j<d;j++)
{
c[i][j]=0;
for(k=0;k<r;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
void assign(float a[10][10],float b[10][10],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
a[i][j]=b[i][j];
}
void controllability(float a[10][10],float b[10][10],float c[10][10],float con[10][10],int r,int
d)
{
int i,j,k,m=r;
for(k=1;k<m;k++)
{
multiplication(a,b,c,r,d);
assign(b,c,r,d);
for(i=0;i<r;i++)
for(j=0;j<d;j++)
{
con[i][j+d*k]=c[i][j];
}
}
}
int main()
{
int r1,r2,c1,c2,i,k,j;
float a[10][10],b[10][10],c[10][10],con[10][10];
printf("Enter the order of A matrix (no.of rows * no.of columns) :n");
42. P a g e | 42
NB : Make necessary corrections if required
scanf("%d%d",&r1,&c1);
printf("Enter the elements of A matrix:n");
read_matrix(a,r1,c1);
printf("A matrix is : n");
print_matrix(a,r1,c1);
printf("nEnter the order of B matrix (no.of rows * no.of columns) :n");
scanf("%d%d",&r2,&c2);
printf("Enter the elements of B matrix:n");
read_matrix(b,r2,c2);
printf("nB matrix is :n");
print_matrix(b,r2,c2);
assign(con,b,r2,c2);
if(r2==c1)
controllability(a,b,c,con,r1,c2);
printf("nThe controllability matrix is :n");
print_matrix(con,r2,r1*c2);
}
43. Use c program, to find the matrix[ … ]
#include <stdio.h>
void print_matrix(float d[10][10],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
printf("n");
for(j=0;j<c;j++)
printf("%f t",d[i][j]);
}
}
void transpose(float a[10][10],float b[10][10],int r,int c)
{
int i,j,temp;
for(i=0;i<c;i++)
for(j=0;j<r;j++)
b[i][j]=a[j][i];
}
void swap_order(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
read_matrix(float a[10][10],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
43. P a g e | 43
NB : Make necessary corrections if required
for(j=0;j<c;j++)
scanf("%f",&a[i][j]);
}
void multiplication(float a[10][10],float b[10][10],float c[10][10],int r,int d)
{
int i,j,k;
for(i=0;i<r;i++)
for(j=0;j<d;j++)
{
c[i][j]=0;
for(k=0;k<r;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
void assign(float a[10][10],float b[10][10],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
a[i][j]=b[i][j];
}
void observability(float a[10][10],float b[10][10],float c[10][10],float obs[10][10],int r,int
d)
{
int i,j,k,m=r;
for(k=1;k<m;k++)
{
multiplication(a,b,c,r,d);
assign(b,c,r,d);
for(i=0;i<r;i++)
for(j=0;j<d;j++)
{
obs[i][j+d*k]=c[i][j];
}
}
}
int main()
{
int r1,r2,c1,c2,i,k,j;
float a[10][10],b[10][10],c[10][10],obs[10][10],aT[10][10],bT[10][10];
printf("Enter the order of A matrix (no.of rows * no.of columns) :n");
scanf("%d%d",&r1,&c1);
printf("Enter the elements of A matrix:n");
read_matrix(a,r1,c1);
printf("A matrix is : n");
print_matrix(a,r1,c1);
transpose(a,aT,r1,c1);
44. P a g e | 44
NB : Make necessary corrections if required
swap_order(&r1,&c1);
printf("nA Transpose matrix is : n");
print_matrix(aT,r1,c1);
printf("nEnter the order of B matrix (no.of rows * no.of columns) :n");
scanf("%d%d",&r2,&c2);
printf("Enter the elements of B matrix:n");
read_matrix(b,r2,c2);
printf("nB matrix is :n");
print_matrix(b,r2,c2);
transpose(b,bT,r2,c2);
swap_order(&r2,&c2);
printf("nB Transpose matrix is : n");
print_matrix(bT,r2,c2);
assign(obs,bT,r2,c2);
if(r2==c1)
observability(aT,bT,c,obs,r1,c2);
printf("nThe observability matrix is :n");
print_matrix(obs,r2,r1*c2);
}