ntsTest.com


Assignment No. 02 Semester: Fall 2007 CS 201: Introduction to Programming

Question No: 01 Marks: 10
Write a program which contains a user defined function named multiple. This function takes two integers values and determines whether the second integer is a multiple of the first. The function should take two integer arguments and return 1 (true) if the second is a multiple of the first and 0 (false) otherwise.

Call this function in a main program after getting two integers from user.

Output:
Enter first number : 4
Enter second number : 16

16 is multiple of 4

Question No: 02 Marks: 10
Write a program which defines an integer array of size 8. The array size should be defined by a constant variable.
Read numbers from keyboard for this array.
Interchange the values at position 2 and 7 and then display the array.

Output:
Enter the values for array :
6
5
2
4
8
3
7
12
The values of array after interchange :
6 7 2 4 8 3 5 12

Question No: 01 Marks: 10
Write a program which contains a user defined function named multiple. This function takes two integers values and determines whether the second integer is a multiple of the first. The function should take two integer arguments and return 1 (true) if the second is a multiple of the first and 0 (false) otherwise.

Call this function in a main program after getting two integers from user.

Output:
Enter first number : 4
Enter second number : 16

16 is multiple of 4
Solution:
#include
bool multiple(int ,int);//function declaration
main()
{
int fValue,sValue; //declare two value of type integer
cout<> fValue;
cout<> sValue;
cout<<endl;
if(multiple(fValue,sValue)) //if multiple function returns true
{
cout<<sValue<<" is multiple of "<<fValue<<endl;
}
else
{
cout<<sValue<<" is not multiple of "<<fValue<<endl;
}

}
bool multiple(int firstValue,int secondValue) //function definition
{
//if secondValue is divided by firstValue and remainder comes out zero

if(secondValue%firstValue==0)
return 1; //return true
else
return 0; //otherwise return false
}

Question No: 02 Marks: 10
Write a program which defines an integer array of size 8. The array size should be defined by a constant variable.
Read numbers from keyboard for this array.
Interchange the values at position 2 and 7 and then display the array.

Output:
Enter the values for array :
6
5
2
4
8
3
7
12
The values of array after interchange :
6 7 2 4 8 3 5 12
Solution:

#include

const int Size = 8; // Constant variable for size of array.

main()
{
int Int_array[Size], Temp;

cout<<" Enter the values for array : "<<'\n';

for(int i=0; i>Int_array[i];

//Interchange the values of Positions 2 and Position 7

Temp = Int_array[1]; // Put the value of position 2 in a temporary variable
Int_array[1] = Int_array[6]; // Assign the value of position 7 to position 2
Int_array[6] =Temp; // Assign the value of Temp(position 2) to position 7

//Display the values of array

cout<<" The values of array of interchange : "<<'\n';

for(int i = 0;i<Size; i++)
cout<<Int_array[i]<<'\t';

}


Related Posts


Comments

2 responses to “Assignment No. 02 Semester: Fall 2007 CS 201: Introduction to Programming”

Leave your response
  1. unizeremaremi says:

    http://imgfeedget.com/36958/img0/buy tramadol/1_style_name.png
    legit viagralegit website for phentermine
    phentermine 30 or 37.5 reviewphentermine 30 phentra
    overnight ultramovernight us delivery on kamagra
    order plavix 75 mgorder plavix 75 mg online
    celebrex dosing instructionscelebrex dosing requirement

    tramadol hcl 50mg dosage informationwithdrawal symptom paxil withdrawl side effectsdoes xanax cause weight gainpropecia tampapropecia painlexapro online a hrefeuropean adderallcelexa citalopram show availableeffexor and zoloft comparisonspaxil peaceviagra discussionswitch from prozac to lexaproviagra in mexicou 15017 cialisultram and suboxonetreatment for viagra hearing problemsallegra effect on herpescipro taken off the marketnexium side effects forumpropecia affect meiosis

  2. Pharmf370 says:

    Hello! dcgedeg interesting dcgedeg site!