Sie sind auf Seite 1von 4

//Program to arrange the given numbers in ascending order

void main()
{
int i,j,temp,n,a[25];
cout<<"Enter the no. of values less than 25"<<endl;
readln(n);
cout<<"Enter the array values"<<endl;
for(i=1;i<n;i++)
cin>>a[i];
for(i=1;i<n-1;i++)
for(j=i+1;j<n;j++)
if (a[i]>a[j])
{
temp:=a[i];
a[i]:=a[j];
a[j]:=temp;
}
cout<<"The ascending order is \n"
for i:=1 to n do
cout<<a[i];
getch();
}

* program to find the sum of two matrices }


two matrices can be added only if both of them are of same order */

#include<iostream.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int m,n,i,j;
cout<<"Enter the order of matrix1\n";
cin>>m>>n;
cout<<"Enter the elements of matrix 1\n";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cout<<"Enter the elements of matrix 2\n";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>b[i][j];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
cout<<"The sum of two matrix is\n";
for(i=0;i<m;i++)
{
cout<<endl;
for(j=0;j<n;j++)
cout<<c[i][j];
}
getch();
}

/* A program to find the factorial of a given number using function*/

#include<iostream.h>
#include<conio.h>

void main()
{
int n;
int fact(int);
clrscr();
cout<<"Enter an integer number\n";
cin>>n;
cout<<"factorial of"<<n<<" is "<<fact(n);
getch();
}

int fact(int m)
{

int i,j=1;
for(i=1;i<=m;i++)
j=j*i;
return(j);
}
/*Program to find whether the given number is prime or not using Function.*/
#include<iostream.h>
#include<conio.h>
int isprime(int n)
{
int i=2;
while(i<=n/2)
{
if(n%i==0)
return(0);
i=i+1;
}
return(1);
}
void main() // { Main program }
{
int i;
int isprime(int);
clrscr();
cout<<"Enter the number\n";
cin>>i;
if(isprime(i)==1)
cout<<"Given number is PRIME\n";
else
cout<<"NOT PRIME";
getch();
}

/* A program to prepare a mark list of a student by defining a suitable record*/


#include<iostream.h>
#include<conio.h>
struct student
{
int id;
char name[20];
int mark1;
int mark2;
int mark3;
int total;
double average;
};
void main()
{
student st;
clrscr();
cout<<"Enter Student id\n";
cin>>st.id;
cout<<"Enter the student name\n";
cin>>st.name;
cout<<"Enter the three marks\n";
cin>>st.mark1>>st.mark2>>st.mark3;
st.total=st.mark1+st.mark2+st.mark3;
st.average=st.total/3;
clrscr;
cout<<"\n \t MARKLIST \n";
cout<<"STUDENT ID = "<<st.id<<endl;
cout<<"NAME = "<<st.name<<endl;
cout<<"Mark1 = "<<st.mark1<<endl;
cout<<"Mark2 = "<<st.mark2<<endl;
cout<<"Mark3 = "<<st.mark3<<endl;
cout<<"Total = "<<st.total<<endl;
cout<<"Average = "<<st.average<<endl;
if ((st.mark1>=50) && (st.mark2>=50) && (st.mark3>=50))
cout<<"GRADE = PASS";
else
cout<<"GRADE = FAIL";
getch();
}