Here is my few successful program:
#include<iostream.h>
#include<conio.h>
//==============================================================================
void main() {
short int n,i,j,k,max;
int m[50];
i=0; j=0; k=0; max=-32767;
cout<<"Value of length: "; cin>>n;
for(i;i<n;i++) {
cout<<"Value "<<(i+1)<<": "; cin>>m[i];
if(m[i]>0&&m[i]%2==0) k++;
if(m[i]<0&&m[i]>max) {
max=m[i];
j++;
}
}
cout<<endl<<"Number of natural even value: "<<k<<endl;
if(j>0) {
cout<<"Position of max negative value ("<<max<<"):";
for(i=0;i<n;i++)
if(m[i]==max) cout<<" "<<(i+1);
}
else cout<<"Don't have negative value!";
getch();
}
And here is my fail program (run yet but not right), please help me fix this, this program input an student list, then follow their marks and rank them, which t is the name of student, d is mark of each student, n is the number of students, m is the number of objects and tb is the average mark of each student:
#include<iostream>
#include<conio>
#include<fstream>
#include<string.h>
#define ip "C:\\Users\\Admin\\Desktop\\progC\\ip.txt"
#define op "C:\\Users\\Admin\\Desktop\\progC\\op.txt"
short int n,m;
struct hs {
char t[10];
short int d[10],tb;
}h[100];
//==============================================================================
void inp();
void prc();
void oup();
//==============================================================================
void inp() {
ifstream f(ip);
if(f) {
short int i,j;
f>>n>>m;
for(i=0;i<n;i++)
f>>h[i].t;
for(i=0;i<n;i++) {
h[i].tb=0;
for(j=0;j<m;j++) {
f>>h[i].d[j];
h[i].tb+=h[i].d[j];
}
}
}
else {
cout<<"Can't open file!";
getch();
}
f.close();
};
//------------------------------------------------------------------------------
void s(char a[10],char b[10]) {
char p[10];
strcpy(p,a);
strcpy(a,b);
strcpy(b,p);
};
void prc() {
short int i,j;
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
if(h[j].tb<h[j+1].tb)
s(h[j].t,h[j+1].t);
else if(h[j].tb==h[j+1].tb)
if(h[j].t[0]>h[j+1].t[0])
s(h[j].t,h[j+1].t);
};
//------------------------------------------------------------------------------
void oup() {
ofstream f(op);
if(n!=0) {
short int i;
for(i=0;i<n;i++)
f<<(i+1)<<"-"<<h[i].t<<endl;
}
else {
cout<<"Nothing to print!";
getch();
}
f.close();
};
//==============================================================================
void main() {
inp();
prc();
oup();
}