0% found this document useful (0 votes)
3 views2 pages

Nested Loops

The document contains programming exercises related to nested loops for a Class IX curriculum at City Montessori School, Kanpur Road, Lucknow. It includes questions that require students to predict outputs of given code snippets and fill in the blanks in incomplete code. The exercises focus on concepts such as character manipulation, frequency counting, and special number generation using loops.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Nested Loops

The document contains programming exercises related to nested loops for a Class IX curriculum at City Montessori School, Kanpur Road, Lucknow. It includes questions that require students to predict outputs of given code snippets and fill in the blanks in incomplete code. The exercises focus on concepts such as character manipulation, frequency counting, and special number generation using loops.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CITY MONTESSORI SCHOOL

KANPUR ROAD LUCKNOW

TOPIC :- NESTED LOOPS-1 CLASS:-IX

Q:-1 What will be the output of following program snippets:-

a. char ch=’a’; int i, j;

for ( i=1;i<=5;i++)
{
for ( j=1; j<=i; j++)
{
[Link](ch+” “);
ch=(char)(ch+1);
}
[Link]();

b. int i,j;

for(i=5;i>=1;i--)
{
[Link](“@”);
for(j=1;j<=i;j++)
{ if(i%2==0)
[Link](“*”);
else
[Link](“#”);
}
[Link]();
}
c. int sum;
for(i=2;i<=5;i++)
{
for(j=7,sum=2;j<=9;j++)
sum+=(i*j);
}
[Link](“sum=” + sum);}
d. Int I,j,sum;
for(i=1;i<=6;i++)
{
for(j=1;j<=i;j++)
sum=sum+j;
}
[Link](“sum is”+ sum);
CITY MONTESSORI SCHOOL
KANPUR ROAD LUCKNOW

TOPIC :- NESTED LOOPS-2 CLASS:-IX

Q:-1 Fill in the blanks in the following code snippets

a. Following code will print frequency of each digit of a number


int a1=11003365, a, d1, i, c=0, d;
for(i=0;i<=9;i++)
{
for(c=0,a=a1;a>0;?1?)
{
?2?;
if(d==i)
?3?
}
if(c>0)
[Link]("frequency of"+i+" " +?4?);
}
}}
b. Following code will generate special numbers from 500 to 1000 , fill in the blanks at
appropriate places.
int num, num1,d,i=1,fact=1,sum=0;

for(num=100; num<=5000; num++)


{
for(num1=num;num1>0;num1=num1/10)
{
d=num1%10;
for( i=1;i<=d;i++)
fact=fact*i;
sum=sum+fact;
fact=1;

}
if(sum==num)
[Link](num);
sum=0;

}} }

You might also like