Pages

Monday, November 4, 2013

star

#include<iostream>
using namespace std;


int main()
{
    int i,j;
    
    for (i = 1; i <= 5 ; i++)
    {
        for (j = 1; j <= i; j++)
            cout << "*";
        cout << endl;
    }
    
    return 0;

}


*
**
***
****
*****


#include<iostream>
using namespace std;


int main()
{
    int i,j;
    for (i = 5; i >= 1; i--)
            
    {
        for (j = 1; j <= i; j++)
            cout << "*";
        cout << endl;
    }
    
    return 0;
}

*****
****
***
**
*

array

#include<iostream>

using namespace std;

int main()

{

    int i;
    int score[10]={4,1,5,3,4,10,9,2,1,7};
    int max = score[0];
    int min = score[0];
    
    for ( i = 0 ; i < 10 ; i++ )
{
        
    if (score[i] > max)
        max = score[i];
        
        else if (score[i] < min)
            min = score[i];
}
    cout <<"\n maximun of umber is"<<max;
    cout <<"\n minimun of number is"<<min;
    
    system("PAUSE");
    return 0;

}

Bornag maklumat peribadi

#include<iostream>

using namespace std;
int main()

{
    char name[20],matrix_no[10],program[20];
    int age,height,weight;
    
    cout<<"Name:"<<endl;
    cin >>name;
    cout<<"Matrix No:"<<endl;
    cin >>matrix_no;
    cout<<"Program :"<<endl;
    cin >>program;
    cout<<"Age:"<<endl;
    cin >>age;
    cout<<"Height:"<<endl;
    cin >>height;
    cout<<"Weight:"<<endl;
    cin >>weight;
    
    system("PAUSE");
    return 0;

}


output :

Name:
nik
Matrix No:
13A06037
Program :
DEEI
Age:
18
Height:
12
Weight:
32

score programming


#include<iostream>
using namespace std;

int main()
{
    
    int score;
    
    cout<<"Enter your score"<<endl;
    cin>>score;
    
    if(score >= 90)
        cout<<"The grade is A"<<endl;
    
    else if(score >= 80)
        cout<<"The grade is B"<<endl;
    
    else if(score >= 70)
        cout<<"The grade is C"<<endl;
    
    else if(score >= 60)
        cout<<"The grade is D"<<endl;
    
    else
        cout<<"The grade is F"<<endl;
    
    system("PAUSE");
    return 0;

}

Sunday, November 3, 2013

set in resistor

#include<iostream>
#include<iomanip>

using namespace std;

int main()
{

    int res1,res2,res3;
    double a=1.0;
    cout<<fixed<<showpoint;
    cout<<"enter first resistor:"<<endl;
    cin>>res1;
    cout<<"enter second resistor:"<<endl;
    cin>>res2;
    cout<<"enter third resistor:"<<endl;
    cin>>res3;
    
    double resistance;
    resistance=a/((a/res1)+(a/res2)+(a/res3));
    
    cout<<setprecision(1)<<endl;
    cout<<"The combined resistance is"<<setw(3)<<resistance<<"ohms"<<endl;
        return 0;

    }

Friday, November 1, 2013

i++

using namespace std;
int main()

{

    int sum;
    
    sum=0;
    
    cout<<"the value of sum is initially se to"<< sum <<endl;
    sum = sum + 96;
    cout<<"sum is now"<< sum <<endl;
    sum = sum + 70;
    cout<<"sum is now"<< sum <<endl;
    sum = sum + 85;
    cout<<"sum is now"<< sum <<endl;
    sum = sum + 60;
    cout<<"the final sum is"<< sum <<endl;

    
    
       return 0;
    

}

Programming about age >= 21

Write a C program to determine whether a person is entitled to vote or not based on his/her age.(Note that a person aged 21 year old and above is netitled to vote)

#include<iostream>

using namespace std;
int main()

{

    int age;
    
    cout<<"enter your age"<<endl;
    cin>>age;
    
    if(age >= 21)
        cout<<"you can antitled to vote"<<endl;
        else
            cout<<"you not antitled to vote"<<endl;
    
    
       return 0;
    

}