80 Thiagarajar College of Engineering
80
80
8
12
12
12
12
68
68
68
68
Name: KUMARAN G Scan to verify results
Email: [email protected]
Roll no: 681280
Phone: 9342539861
Branch: TCE
Department: CSBS - Q
Batch: 2029
Degree: B Tech CSBS
80
80
80
28
2025_29_I_21CB170_Fundamentals of Computer Lab Q
12
12
12
1
68
68
68
68
TCE_21CB170_Week 3_COD
Attempt : 1
Total Mark : 50
Marks Obtained : 50
Section 1 : COD
1. Problem Statement
80
80
80
8
Liam is organizing a coding event and wants to create a unique display
12
12
12
12
68
68
68
pattern for the event banner. Help Liam generate the following pattern for a68
number of rows and columns.
Example:
Input:
5
Output:
1111*
#2222
80
80
80
28
12
12
12
1
3333*
68
68
68
68
#4444
80
80
80
8
5555*
12
12
12
12
68
68
68
68
Input Format
The input consists of an integer N, representing the number of rows and
columns of the given pattern.
Output Format
The output prints the required pattern in N rows and N columns, as displayed in
the question. A single space separates the elements in each row.
80
80
80
28
12
12
12
1
Refer to the sample outputs for the formatting specifications.
68
68
68
68
Sample Test Case
Input: 5
Output: 1 1 1 1 *
#2222
3333*
#4444
5555*
Answer
#include<stdio.h>
80
80
80
8
int main()
12
12
12
12
68
68
68
{ 68
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
printf("#");
for(j=1;j<=n-1;j++)
{
printf("%d",i);
}
if(i%2!=0)
80
80
80
28
printf("*");
12
12
12
1
68
68
68
68
80printf("\n");
80
80
}
8
12
12
12
12
return 0;
68
68
68
68
}
Status : Correct Marks : 10/10
2. Problem Statement
As you embark on this programming journey, develop a program that takes
80
80
80
advantage of nested do-while loops to construct an enchanting pattern of
28
12
12
12
1
numbers forming a captivating triangular arrangement!
68
68
68
68
The program takes a positive integer as input, representing the desired
number of rows for the pattern, and prints the required pattern as shown in
the example below using a do-while loop.
Input Format
The input consists of an integer n, representing the desired number of rows for
the pattern.
Output Format
80
80
80
8
The output prints the desired pattern based on the number of rows given.
12
12
12
12
68
68
68
68
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: 5
Output: 1
12
123
1234
80
80
80
28
12345
12
12
12
1
68
68
68
68
Answer
80
80
80
8
#include<stdio.h>
12
12
12
12
68
68
68
68
int main()
{
int n,i=1,j;
scanf("%d",&n);
do
{
j=1;
do
{
printf("%d",j);
j++;
}
80
80
80
28
while(j<=i);
12
12
12
1
68
68
68
68
printf("\n");
i++;
}
while(i<=n);
return 0;
}
Status : Correct Marks : 10/10
3. Problem Statement
80
80
80
8
12
12
12
12
68
68
68
Emma is intrigued by a program designed to calculate the sum of numbers 68
provided by a user. The program repeatedly prompts the user to input a
number. The entered number is then added to a running total.
Write a program using the do-while loop that calculates the sum of all
numbers to achieve the final result.
Input Format
The input consists of the numbers (excluding 0) in separate lines.
The last line of input consists of 0, indicating the end of the input.
80
80
80
28
12
12
12
1
Output Format
68
68
68
68
The output prints the sum of the entered numbers with the format "Sum = <sum>
80
80
80
"
8
12
12
12
12
68
68
68
68
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: -82
55
-22
68
-23
80
80
80
39
28
12
12
12
1
26
68
68
68
68
0
Output: Sum = 61
Answer
// You are using GCC
#include<stdio.h>
int main()
{
int n,sum=0;
do
{
80
80
80
8
scanf("%d",&n);
12
12
12
12
sum=sum+n;
68
68
68
68
}
while(n!=0);
printf("Sum = %d",sum);
}
Status : Correct Marks : 10/10
4. Problem Statement
You are organizing a mathematics competition where participants need to
80
80
80
28
test their knowledge of prime numbers. As part of the competition, you
12
12
12
1
68
68
68
68
decide to write a program that checks whether a given number is prime or
80
80
80
not. During the competition, each participant will enter a number, and your
8
12
12
12
12
program will determine if it is prime.
68
68
68
68
Input Format
The input consists of an integer n.
Output Format
The output prints whether n is a prime number or not prime number in one of the
following formats:
1. "n is a prime number." where n is the input number.
2. "n is not a prime number." where n is the input number.
80
80
80
28
12
12
12
1
68
68
68
68
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: 2
Output: 2 is a prime number.
Answer
#include<stdio.h>
int main()
80
80
80
{
8
12
12
12
12
int n,i,c=0;
68
68
68
scanf("%d",&n);
68
for(i=1;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
{
printf("%d is a prime number.",n);
80
80
80
}
28
12
12
12
1
else
68
68
68
68
80{
80
80
printf("%d is not a prime number.",n);
8
12
12
12
12
}
68
68
68
68
}
Status : Correct Marks : 10/10
5. Problem Statement
Create a program that generates and prints the Fibonacci series up to a
specified number N. The Fibonacci series is a sequence of numbers in
which each number is the sum of the two preceding numbers, starting with
0 and 1.
80
80
80
28
12
12
12
1
68
68
68
68
Your program should take an integer input N and display the Fibonacci
series up to the Nth term.
Fibonacci series: 0, 1, 1, 2, 3, 5, 8,...
Input Format
The input consists of a positive integer N.
Output Format
The output displays the Fibonacci series up to the Nth term separated by space.
80
80
80
8
12
12
12
12
68
68
68
68
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: 7
Output: 0 1 1 2 3 5 8
Answer
// You are using GCC
#include<stdio.h>
int main()
80
80
80
28
12
12
12
{
1
68
68
68
68
80int n;
80
80
scanf("%d",&n);
8
12
12
12
12
int a=0,b=1,c;
68
68
68
68
for(int i=1;i<=n;i++)
{
printf("%d ", a);
c=a+b;
a=b;
b=c;
}
}
Status : Correct Marks : 10/10
80
80
80
28
12
12
12
1
68
68
68
68
80
80
80
8
12
12
12
12
68
68
68
68
80
80
80
28
12
12
12
1
68
68
68
68