This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docxscroghamtressie
Merge sort in C
Solution
#include<stdio.h>
#define MAX 50
void mergeSort(int arr[],int low,int mid,int high);
void partition(int arr[],int low,int high);
int main(){
int merge[MAX],i,n;
printf(\"Enter the total number of elements: \");
scanf(\"%d\",&n);
printf(\"Enter the elements which to be sort: \");
for(i=0;i<n;i++){
scanf(\"%d\",&merge[i]);
}
partition(merge,0,n-1);
printf(\"After merge sorting elements are: \");
for(i=0;i<n;i++){
printf(\"%d \",merge[i]);
}
return 0;
}
void partition(int arr[],int low,int high){
int mid;
if(low<high){
mid=(low+high)/2;
partition(arr,low,mid);
partition(arr,mid+1,high);
mergeSort(arr,low,mid,high);
}
}
void mergeSort(int arr[],int low,int mid,int high){
int i,m,k,l,temp[MAX];
l=low;
i=low;
m=mid+1;
while((l<=mid)&&(m<=high)){
if(arr[l]<=arr[m]){
temp[i]=arr[l];
l++;
}
else{
temp[i]=arr[m];
m++;
}
i++;
}
if(l>mid){
for(k=m;k<=high;k++){
temp[i]=arr[k];
i++;
}
}
else{
for(k=l;k<=mid;k++){
temp[i]=arr[k];
i++;
}
}
for(k=low;k<=high;k++){
arr[k]=temp[k];
}
}
Sample output:
Enter the total number of elements: 5
Enter the elements which to be sort: 2 5 0 9 1
After merge sorting elements are: 0 1 2 5 9
.
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docxscroghamtressie
Merge sort in C
Solution
#include<stdio.h>
#define MAX 50
void mergeSort(int arr[],int low,int mid,int high);
void partition(int arr[],int low,int high);
int main(){
int merge[MAX],i,n;
printf(\"Enter the total number of elements: \");
scanf(\"%d\",&n);
printf(\"Enter the elements which to be sort: \");
for(i=0;i<n;i++){
scanf(\"%d\",&merge[i]);
}
partition(merge,0,n-1);
printf(\"After merge sorting elements are: \");
for(i=0;i<n;i++){
printf(\"%d \",merge[i]);
}
return 0;
}
void partition(int arr[],int low,int high){
int mid;
if(low<high){
mid=(low+high)/2;
partition(arr,low,mid);
partition(arr,mid+1,high);
mergeSort(arr,low,mid,high);
}
}
void mergeSort(int arr[],int low,int mid,int high){
int i,m,k,l,temp[MAX];
l=low;
i=low;
m=mid+1;
while((l<=mid)&&(m<=high)){
if(arr[l]<=arr[m]){
temp[i]=arr[l];
l++;
}
else{
temp[i]=arr[m];
m++;
}
i++;
}
if(l>mid){
for(k=m;k<=high;k++){
temp[i]=arr[k];
i++;
}
}
else{
for(k=l;k<=mid;k++){
temp[i]=arr[k];
i++;
}
}
for(k=low;k<=high;k++){
arr[k]=temp[k];
}
}
Sample output:
Enter the total number of elements: 5
Enter the elements which to be sort: 2 5 0 9 1
After merge sorting elements are: 0 1 2 5 9
.
These problems are so common that you will find in any C learning curriculum. Either in your college or in any IT institute.
I have provided solutions to these problems as well.
Happy learning...
Ex.1 Write a program to print the following pattern
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ex.2 Write a program to find bigger of three integers.
Ex.3 Write a program to calculate GCD between two numbers.
Ex.4 Write a program to find transpose of matrix.
Ex.5 Write a program which deletes an element from an array & display all other elements.
Ex.6 Write a program to calculate XA+YB where A & B are matrix & X=2, Y=3.
Ex.7 Write a program to calculate the total amount of money in the piggy bank, given that coins of Rs.10, Rs.5, Rs.2, RS.1.
& many more.....
These problems are so common that you will find in any C learning curriculum. Either in your college or in any IT institute.
I have provided solutions to these problems as well.
Happy learning...
Ex.1 Write a program to print the following pattern
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ex.2 Write a program to find bigger of three integers.
Ex.3 Write a program to calculate GCD between two numbers.
Ex.4 Write a program to find transpose of matrix.
Ex.5 Write a program which deletes an element from an array & display all other elements.
Ex.6 Write a program to calculate XA+YB where A & B are matrix & X=2, Y=3.
Ex.7 Write a program to calculate the total amount of money in the piggy bank, given that coins of Rs.10, Rs.5, Rs.2, RS.1.
& many more.....
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSveerababupersonal22
It consists of cw radar and fmcw radar ,range measurement,if amplifier and fmcw altimeterThe CW radar operates using continuous wave transmission, while the FMCW radar employs frequency-modulated continuous wave technology. Range measurement is a crucial aspect of radar systems, providing information about the distance to a target. The IF amplifier plays a key role in signal processing, amplifying intermediate frequency signals for further analysis. The FMCW altimeter utilizes frequency-modulated continuous wave technology to accurately measure altitude above a reference point.
1. Page No. 1
ARRAY 1D
/*Write a C program which calculate and print sum
and average of elements of an array*/
#include<stdio.h>
int main()
{
int arr[50],n,i,sum=0;
float avg;
printf("enter the no. of elementn");
scanf("%d",&n);
printf("enter elementn");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<n;i++)
sum=arr[i]+sum;
avg=(float)sum/n;
printf("nElement sum is = %d",sum);
printf("nElement average is = %f",avg);
return 0;
}
/*Write a C Program to print the elements of array
in reverse order*/
#include<stdio.h>
int main()
{
int arr[50],i,n;
printf("Enter size of array : ");
scanf("%d",&n);
printf("Enter elements of array : n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Array in Reverse Order : ");
for(i=n-1;i>=0;i--)
{
printf("%d ",arr[i]);
}
return 0;
}
/*Write a C program to print elements of an array
greater than average*/
#include<stdio.h>
int main()
{
int ar[10],i,n,s=0,c=0;
float avg;
printf("enter the limit:n");
scanf("%d",&n);
printf("enter the elementsn");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
s=s+ar[i];
}
avg=(float)s/n;
printf("average is %.2f",avg);
for(i=0;i<n;i++)
{
if(ar[i]>avg)
{
printf("n%d is grater than avg",ar[i]);
c++;
}
}
printf("nTotal Elements greater than avg are %d",c);
return 0;
}
/*Write a C Program to store the elements of array
into another array in reverse order*/
#include<stdio.h>
int main()
{
int arr[50],rev[50],i,n,j;
printf("Enter size of array : ");
scanf("%d",&n);
printf("Enter elements of array : n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
j=n-1;
for(i=0;i<n;i++)
{
rev[i]=arr[j--];
}
printf("Array in Reverse Order : ");
for(i=0;i<n;i++)
{
printf("%dt",rev[i]);
}
return 0;
}
/*Write a c Program to search an element in a 1D
array*/
#include<stdio.h>
int main()
{
int arr[50],i,n,key,c=0;
2. Page No. 2
printf("Enter size of array : ");
scanf("%d",&n);
printf("Enter elements of array : n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
printf("Enter Element to Be Searched : ");
scanf("%d",&key);
for(i=0;i<n;i++)
{
if(arr[i]==key)
{
printf("Element found at %d
indexn",i);
c++;
}
}
if(c==0)
printf("Element Not Found");
return 0;
}
/*Write a c program to find maximum and minimum
element in 1-D array */
#include<stdio.h>
int main()
{
int arr[50],n,i,min,max;
printf("Enter no. of elements:");
scanf("%d",&n);
printf("Enter %d elements in array",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
min=max=arr[0];
for(i=0;i<n;i++)
{
if(arr[i]>max)
max=arr[i];
else if(arr[i]<min)
min=arr[i];
}
printf("nThe max element is:%d",min);
printf("nThe min element is:%d",max);
return 0;
}
/*Write a c program to perform sorting on 1-D array
*/
#include<stdio.h>
int main()
{
int arr[50],n,i,j,temp;
printf("Enter no. of elements:");
scanf("%d",&n);
printf("Enter %d elements in array",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<n;i++)
{ for(j=0;j<n-1;j++)
{
if(arr[j]>arr[j+1])
{ temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("Array Elements after Sorting");
for(i=0;i<n;i++)
{
printf("n%d",arr[i]);
}
return 0;
}
/* Write a c program to find maximum and minimum
element in 1-D array by sorting technique */
#include<stdio.h>
int main()
{
int arr[50],n,i,j,temp;
printf("Enter no. of elements:");
scanf("%d",&n);
printf("Enter %d elements in array",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
//sorting array in ascending order
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
printf("nThe maximum element is:%d",arr[n-1]);
3. Page No. 3
printf("nThe minimum element is:%d",arr[0]);
printf("nThe second maximum element
is:%d",arr[n-2]);
printf("nThe second minimum element
is:%d",arr[1]);
return 0;
}
4. Page No. 4
ARRAY-2D
#include<stdio.h>
int main()
{
int row,col, ar[100][100],i,j;
printf("Enter row and column of array : ");
scanf("%d%d",&row,&col);
printf("Enter the elements of arrayn");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf("The elements of arrayn");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{ if(i==j)
printf(" %d ",ar[i][j]);
sum=sum+ ar[i][j];
}
printf("n");
}
return 0;
}
/*Write a c Program to find addition of two 2d
array*/
#include<stdio.h>
int main()
{
int arr1[50][50],arr2[50][50],sum[50][50];
int i,j,r1,r2,c1,c2;
printf("Enter row and column of 1st array : ");
scanf("%d%d",&r1,&c1);
printf("Enter elements of array 1st array: n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&arr1[i][j]);
}
}
printf("Enter row and column of 2nd array : ");
scanf("%d%d",&r2,&c2);
printf("Enter elements of array 2nd array: n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&arr2[i][j]);
}
}
if(r1==r2&&c1==c2)
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
sum[i][j]=arr1[i][j]+arr2[i][j];
}
}
printf("Sum Of Two Matrices : n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%dt",sum[i][j]);
}
printf("n");
}
}
else
printf("Addition Not Possible");
return 0;
}
/*Write a C Program to print the upper and lower
triangle in a matrix*/
#include<conio.h>
#include<stdio.h>
#define row 3
#define col 3
int main()
{
int ar[row][col],i,j,n;
printf("Enter the elements of arrayn");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf("The elements of arrayn");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf(" %d ",ar[i][j]);
}
printf("n");
}
if(row==col)
{
printf("The lower triangular matrixn");
for(i=0;i<row;i++)
5. Page No. 5
{
for(j=0;j<col;j++)
{
if(j<=i)
{
printf(" %d
",ar[i][j]);
}
}
printf("n");
}
printf("The upper triangular matrixn");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(j>=i)
{
printf(" %d ",ar[i][j]);
}
else
{
printf(" ");
}
}
printf("n");
}
}
else
printf("Can't calculate the upper/lower triangle in
matrix");
return 0;
}
/*Write a C Program to find row sum & column sum
*/
#include<stdio.h>
int main()
{
int mat[50][50];
int i,j,r,c,rsum,csum,d1=0,d2=0;
printf("Enter row and column of an array : ");
scanf("%d%d",&r,&c);
printf("Enter elements of array an array: n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&mat[i][j]);
}
}
//Code to print elements
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf(" %d",mat[i][j]);
}
printf("n");
}
//Row sum
for(i=0;i<r;i++)
{
rsum=0;
for(j=0;j<c;j++)
{
rsum=rsum+mat[i][j];
}
printf("Row Sum %dn", rsum);
}
//Column Sum
for(i=0;i<c;i++)
{
csum=0;
for(j=0;j<r;j++)
{
csum=csum+mat[j][i];
}
printf("Column Sum %dn",csum);
}
return 0;
}
//logic for individual right diagonal
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{ if(i==j)
{
printf(" %d ",ar[i][j]);
}
Else
{
Printf(“ “);
}
}
printf("n");
}
//logic for individual left diagonal
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{ if(i+j=row-1)
{
printf(" %d ",ar[i][j]);
}
6. Page No. 6
Else
{
Printf(“ “);
}
}
printf("n");
}
Write a C Program to add the elements of both
diagonals of a user defined matrix (method 1)
#include<stdio.h>
int main()
{
int n,i,j,r,c,arr[100][100],dsum=0;
printf("Enter the number of rows and columns.");
scanf("%d%d",&r,&c);
if(r==c)
{
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
{
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
{
if((i==j)||(i+j==r-1))
{
dsum=dsum+arr[i][j];
}
}
}
printf("The sum of elements of both diagonals is
%d.",dsum);
}
else
{
printf("The sum of diagonals cannot be
calculated.");
}
return 0;
}
Write a C Program to add the elements of both
diagonals of a user defined matrix (method 2)
#include<stdio.h>
int main()
{
int n,i,j,r,c,arr[100][100],dsum=0;
printf("Enter the number of rows and columns.");
scanf("%d%d",&r,&c);
if(r==c)
{
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
{
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<=r-1;i++)
{
dsum=dsum+arr[i][i];
}
for(i=0;i<=r-1;i++)
{
dsum=dsum+arr[i][r-1-i];
}
printf("The sum of elements of both diagonals is
%d.",dsum);
}
else
{
printf("The sum of diagonals cannot be
calculated.");
}
return 0;
}