Showing posts with label find. Show all posts
Showing posts with label find. Show all posts
Wednesday, February 18, 2015
C program to find sum of elements above and below the main digonal of a matrix
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[5][5],a=0,b=0,i,j,n;
cout<<"Enter size of array(max 5):";
cin>>n;
cout<<"Enter the array:";
for(i=0;i<n;++i)
for(j=0;j<n;++j)
cin>>arr[i][j];
for(i=0;i<n;++i)
for(j=0;j<n;++j)
if(j>i)
a+=arr[i][j];
else
if(i>j)
b+=arr[i][j];
cout<<"
Sum of elements above the digonal:"<<a;
cout<<"
Sum of elements below the digonal:"<<b;
getch();
}
Wednesday, February 11, 2015
C Program to find highest and lowest element of a Matrix
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int m,n,a[10][10],i,j,high,low;
cout<<"Enter no. of rows and coloumns:";
cin>>m>>n;
cout<<"
Enter matrix:
";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
cin>>a[i][j];
}
for(i=0;i<m;++i)
{
high=a[0][0];
low=a[0][0];
for(j=0;j<n;++j)
{
if(a[i][j]>high)
high=a[i][j];
else
if(a[i][j]<low)
low=a[i][j];
}
}
cout<<"
Heighst Element:"<<high<<"
Lowest Element:"<<low<<"
";
getch();
}
C Program to Find ASCII value of a character
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char ch,c;
int cha;
cout<<"Enter a character:";
cin>>ch;
cha=ch;
cout<<"
ASCII value of "<<ch<<" is "<<cha;
c=ch+1; cha=c;
cout<<"
Adding one to the character:"<<"
ASCII value of "<<c<<" is "<<cha;
getch();
}
Subscribe to:
Posts (Atom)