c1

četvrtak, 13. prosinca 2012.

Program with integer, modul, average


/* 

 Make a program in which user enters a number n...If n is not integer, print a message about that and ask a user to enter a number again...User than enters n numbers, after that program  prints an  average of entered numbers....


#include <iostream>
using namespace std;
int main()
{
    bool ok=false;
    int m;
    while(ok==false){
                      cout<<"Type number n:  "<<endl;
    double n;
    cin>>n;
    n=n*10;
    
    m=(int)n;
    if(m%10==0){
                m=m/10;
    cout<<endl<<"It's OK, you can continue....  "<<endl<<endl;
    ok=true;
}
else{
     cout<<endl<<"You need to enter integer....  "<<endl<<endl;
     ok=false;
     }
}
cout<<endl<<"Now type "<<m<<" numbers  "<<endl;
int niz[m];
int sum=0;
for(int i=0;i<m;i++){
        cin>>niz[i];
        cout<<endl;
        sum=sum+niz[i];
         }
float as;
float sum1=sum;
float m1=m;
as=sum1/m1;

cout<<"Average is:   "<<as<<endl;    

    system("PAUSE");
    return EXIT_SUCCESS;
}


utorak, 11. prosinca 2012.

Matrix 50 x 50 and secondary diagonal

/*
Question:
Make a logic of program which will use a matrix [50][50]....User types the numbers, and numbers must be less or equal to 50, if that condition is not satisfied, you need to repeat the number m....Find and multiply the numbers on secondary diagonal of matrix....(secondary diagonal goes from upper right side to downer left)

*/

HERE YOU CAN FIND MORE C++ PROGRAMS ON REDGAGE







#include <iostream>
using namespace std;
int main()
{
    int x=3;
    int y=3;
    int n[x][y];
    int m;
    int sum=0;
    cout<<" Type the numbers of matrix: "<<x<<" x "<<y<<endl;
    for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                  
            cout<<"Position "<<i+1<<" - "<<j+1<<" is: ";
            cin>>m;
            if(m<51){
            n[i][j]=m;      
            }
            else{
                 j--;
                 cout<<" Type the number which is smaller or equal to 50 "<<endl;
                 }
                    }
            }
  
    cout<<"Matrix is: "<<endl;
    for(int i=0;i<x;i++){
            cout<<endl;
          
            sum=sum+n[i][x-1-i];
            cout<<n[i][x-1-i]<<"   ";
                
                  
                  
            }
    cout<<endl<<endl<<"The sum of secondary diagonal is: "<< sum <<endl;
    cout<<endl;
  
  
    system("PAUSE");
    return EXIT_SUCCESS;
}



HERE YOU CAN FIND MORE C++ PROGRAMS ON REDGAGE