0% found this document useful (0 votes)
2 views

11CS ProgramBasedTest1 Answers

The document contains a series of coding exercises and their outputs, primarily focused on C++ programming concepts. It includes snippets that demonstrate operations like arithmetic, conditionals, loops, and error handling. Additionally, there are sections for correcting code and filling in blanks, aimed at reinforcing programming skills.

Uploaded by

Tharun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

11CS ProgramBasedTest1 Answers

The document contains a series of coding exercises and their outputs, primarily focused on C++ programming concepts. It includes snippets that demonstrate operations like arithmetic, conditionals, loops, and error handling. Additionally, there are sections for correcting code and filling in blanks, aimed at reinforcing programming skills.

Uploaded by

Tharun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

11 – COMPUTER SCIENCE

LESSONS – 9 & 10
Name: ________________________

என்றும் மாணவர்கள் நலனில்

CODING WITH ANSWERS

WRITE THE OUTPUT OF THE FOLLOWING SNIPPETS. / பின்வரும் குறிமுறைகளின் வெளியீட்டை எழுதுக.

1) cout<<(10/3)<<endl;
cout<<(10%3);
3
1
2) cout<<(8.5 % 2);
Error!
3) cout<<((int)8.5 % 3);
2
4) int i = 8, j = 10, k = 8;
cout<<(i <k )<<endl;
cout<<(i == j)<<endl;
cout<<(i != k )<<endl;
cout<<(I >= k);
0
0
0
1
5) int a = 5, b = 6, c = 7;
cout<<((a>b) && (b>c))<<endl;
cout<<((a<b) || (b>c));
0
1
6) #include <iostream.h>
using namespace std;
int main ()
{
..1.. A. PRABHAKAR - 9442979144
int n=100;
char ch;
ch = n;
cout << "\n Equivalent Character: " << ch;
}
Equivalent Character: d
7) #include <iostream.h>
using namespace std;
int main()
{
const int num=100;
cout << "\n Value of num is = " << num;
num = num + 1;
cout << "\n Value of num after increment " << num;
}
Error!
8) #include <iostream>
using namespace std;
int main()
{
int m3;
int practical = 30;
int &physics = m3;
m3 = 51;
physics = physics + practical;
cout << "\n The physics mark = " << physics;
}
The physics mark = 81
9) #include <iostream.h>
using namespace std;
int main( )
{
float a = 78.685;
cout<<"a = "<<(int)a;
}
a = 78

..2.. A. PRABHAKAR - 9442979144


10) #include <iostream>
using namespace std;
int main( )
{
char ch = 'A';
ch = ch + 5;
cout<<ch;
}
F
11) #include <iostream>
using namespace std;
int main( )
{
int num = 6;
cout<<num<<endl;
cout<<(num==5);
}
6
0
12) Fill the right word in the blanks of the following C++ program:
#include <iostream.h>
using namespace std;
int main()
{
int num;
cout<< "\n Enter a number: ";
cin>>num;
if (num % 2 != 0)
cout<< "\n The given number" <<num<< " is _______ ";
else
cout<< "\n The given number "<<num<< " is ________ ";
return 0;
}
Odd
Even

..3.. A. PRABHAKAR - 9442979144


13) #include <iostream>
using namespace std;
int main()
{
int num = -16;
int res = (num%2==0)?1:0;
if (res)
cout<<"Even";
else
cout<<"Odd";
return 0;
}
Even
14) #include <iostream>
using namespace std;
int main()
{
int num = 4;
switch (num)
{
case 1 : cout << "\n Sunday";
case 2 : cout << "\n Monday"; break;
case 3 : cout << "\n Tuesday"; break;
case 4 : cout << "\n Wednesday";
case 5 : cout << "\n Thursday"; break;
case 6 : cout << "\n Friday";
case 7 : cout << "\n Saturday"; break;
default: cout << "\n Wrong input....";
}
}

Wednesday
Thursday
15) #include <iostream>
using namespace std;
int main ()
{
int i;
..4.. A. PRABHAKAR - 9442979144
for(i = 0; i<= 10; i+=2)
cout<< "value of i : " <<i<<endl;
return 0;
}
value of i : 0
value of i : 2
value of i : 4
value of i : 6
value of i : 8
value of i : 10
16) #include <iostream>
using namespace std;
int main ()
{
int i, sum=0;
for(i=1; i<=10;i++);
{
sum=sum+i;
}
cout<<"The sum of 1 to 10 is "<<sum;
}
The sum of 1 to 10 is 11
17) #include <iostream>
using namespace std;
int main ()
{
int i, sum=0;
while(i<=10)
{
sum=sum+i;
i=i+1;
}
cout<<"The sum of 1 to 10 is "<<sum;
}
The sum of 1 to 10 is 55

..5.. A. PRABHAKAR - 9442979144


18) #include <iostream>
using namespace std;
int main ()
{
int n = 10;
do
{
cout<<n<<", ";
n--;
}while (n>0) ;
}
10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
19) for (int i=1; i<10; i++)
cout<<i;
123456789
20) for (int i=0; i<=10; i++)
cout<<i;
012345678910
21) int i;
for (i=0; i<=10; i++);
cout<<i;
11
22) for (int i=0; ; i++)
cout<<i;
0123456789101112131415161718………(Infinity)
23) for (int i=1; ; i++)
{
cout<<i;
if (i==5)
break;
}
12345
24) for (int i=2; i<=10 ; i+=2)
cout << i;
246810

..6.. A. PRABHAKAR - 9442979144


25) #include<iostream>
using namespace std;
int main()
{
int i, sum = 5;
for( i = 1 ; i <= 5 i++)
{
sum = sum + i;
}
cout<<sum;
return 0;
}
20
26) #include<iostream>
using namespace std;
int main(){
int i = 1, sum = 0;
while (i <= 10)
{
sum=sum+i;
i++;
}
cout<<sum;
return 0;
}
55
27) #include<iostream>
using namespace std;
int main()
{
int i;
for( i = 0; i < 8; i++)
cout<< i <<endl;
return 0;
}

..7.. A. PRABHAKAR - 9442979144


0
1
2
3
4
5
6
7
28) Correct the following code segment:
int x=5, p;
if (x=1)
p= 100;
else
p = 10;
Second line should be → if (x==1)
29) Rewrite the following code so that it is functional:
v = 5;
do;
{
total += v;
cout << total;
while v <= 10
Correct coding:
int v = 5, total = 0;
do
{
total += v;
cout<<total;
v = v + 1;
} while (v <= 10);
30) Correct the following code segment:
int a, x=25, m = 10;
if x >= 10
a = m + 5;
else
a = m - 5;
Condition should be in parenthesis → if (x >= 10)

..8.. A. PRABHAKAR - 9442979144

You might also like