1.Program to find the largest numbers among n numbers entered by the user
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[50];
int i, greatest, n;
printf("Enter the number of terms.\n");
scanf("%d", & n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0) greatest=a[i];
if(greatest<a[i])
greatest=a[i];
}
printf("The greatest value is %d.",greatest);
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[50];
int i, smallest, n;
printf("Enter the number of terms.\n");
scanf("%d", & n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0) smallest=a[i];
if(smallest>a[i])
smallest=a[i];
}
printf("The smallest value is %d.",smallest);
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[50];
int i,temp,n,j;
printf("Enter the number of terms:");
scanf("%d", & n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<(n-1);i++)
{
for(j=0;j<(n-1);j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("The numbers in ascending order is:\n");
for(i=0;i<n;i++)
{
printf(" %d",a[i]);
}
return 0;
}
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[50];
int i,temp,n,j;
printf("Enter the number of terms:");
scanf("%d", & n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<(n-1);i++)
{
for(j=0;j<(n-1);j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("The numbers in descending order is:\n");
for(i=0;i<n;i++)
{
printf(" %d",a[i]);
}
return 0;
}
#include<stdio.h>
void arr(int a[3][3],int b[3][3]);
void main()
{
int a[3][3],b[3][3],c[3][3],d[3][3],i,j;
printf("Enter first matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("You have entered first matrix as\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("Enter second matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d \t",&b[i][j]);
}
}
printf("You have entered second matrix as\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",b[i][j]);
}
printf("\n");
}
arr(a,b);
}
void arr(int a[3][3],int b[3][3])
{
int sum,k,c[3][3],d[3][3],i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
}
printf("The sum is\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",c[i][j]);
}
printf("\n");
}
for ( i= 0 ; i < 3 ; i++ )
{
for ( j = 0 ; j< 3 ; j++ )
{
sum=0;
for ( k = 0 ; k < 3 ; k++ )
{
sum = sum + a[i][k]*b[k][j];
}
d[i][j] = sum;
}
}
printf("The Product is\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",d[i][j]);
}
printf("\n");
}
}
#include<conio.h>
int main( )
{
int a[50];
int i, greatest, n;
printf("Enter the number of terms.\n");
scanf("%d", & n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0) greatest=a[i];
if(greatest<a[i])
greatest=a[i];
}
printf("The greatest value is %d.",greatest);
getch();
return 0;
}
2.Program to find the smallest numbers among n numbers entered by the user
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[50];
int i, smallest, n;
printf("Enter the number of terms.\n");
scanf("%d", & n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0) smallest=a[i];
if(smallest>a[i])
smallest=a[i];
}
printf("The smallest value is %d.",smallest);
getch();
return 0;
}
3.Program to arrange n numbers entered by the user in ascending order
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[50];
int i,temp,n,j;
printf("Enter the number of terms:");
scanf("%d", & n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<(n-1);i++)
{
for(j=0;j<(n-1);j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("The numbers in ascending order is:\n");
for(i=0;i<n;i++)
{
printf(" %d",a[i]);
}
return 0;
}
4.Program to arrange n numbers entered by the user in descending order
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[50];
int i,temp,n,j;
printf("Enter the number of terms:");
scanf("%d", & n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<(n-1);i++)
{
for(j=0;j<(n-1);j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("The numbers in descending order is:\n");
for(i=0;i<n;i++)
{
printf(" %d",a[i]);
}
return 0;
}
5.Program to find sum and product of two matrices by passing array to function
#include<stdio.h>
void arr(int a[3][3],int b[3][3]);
void main()
{
int a[3][3],b[3][3],c[3][3],d[3][3],i,j;
printf("Enter first matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("You have entered first matrix as\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("Enter second matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d \t",&b[i][j]);
}
}
printf("You have entered second matrix as\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",b[i][j]);
}
printf("\n");
}
arr(a,b);
}
void arr(int a[3][3],int b[3][3])
{
int sum,k,c[3][3],d[3][3],i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
}
printf("The sum is\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",c[i][j]);
}
printf("\n");
}
for ( i= 0 ; i < 3 ; i++ )
{
for ( j = 0 ; j< 3 ; j++ )
{
sum=0;
for ( k = 0 ; k < 3 ; k++ )
{
sum = sum + a[i][k]*b[k][j];
}
d[i][j] = sum;
}
}
printf("The Product is\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",d[i][j]);
}
printf("\n");
}
}
0 comments:
Post a Comment