Please scroll down for latest Programs 👇
Code compiled and tested successfully!
Problem Solving through Programming in C
NPTEL
Due date on 2026-08-13, 23:59 IST
Q.
[Marks for Week 3 Programming assignments will not be evaluated finally. This is for users to get familiar with programming in google course builder platform]
Complete Program
C#include <stdio.h>
#define PI 3.14
void main() {
int radius;
float area;
scanf("%d", &radius);
// --- START OF SOLUTION CODE ---
area = PI * radius * radius;
// --- END OF SOLUTION CODE ---
printf("Area of a circle = %5.2f", area);
}
#include <stdio.h>
#define PI 3.14
void main() {
int radius;
float area;
scanf("%d", &radius);
// --- START OF SOLUTION CODE ---
area = PI * radius * radius;
// --- END OF SOLUTION CODE ---
printf("Area of a circle = %5.2f", area);
}
Code Snippet to Paste in the Editor
C// --- START OF SOLUTION CODE ---
area = PI * radius * radius;
// --- END OF SOLUTION CODE ---
// --- START OF SOLUTION CODE ---
area = PI * radius * radius;
// --- END OF SOLUTION CODE ---Due date on 2026-08-13, 23:59 IST
Complete Program
C#include <stdio.h>
int main() {
double number;
scanf("%lf", &number);
// --- START OF SOLUTION CODE ---
if (number == 0) {
printf("The number is 0.");
} else if (number < 0) {
printf("Negative number.");
} else {
printf("Positive number.");
}
// --- END OF SOLUTION CODE ---
return 0;
}
#include <stdio.h>
int main() {
double number;
scanf("%lf", &number);
// --- START OF SOLUTION CODE ---
if (number == 0) {
printf("The number is 0.");
} else if (number < 0) {
printf("Negative number.");
} else {
printf("Positive number.");
}
// --- END OF SOLUTION CODE ---
return 0;
}
Code Snippet to Paste in the Editor
C// --- START OF SOLUTION CODE ---
if (number == 0) {
printf("The number is 0.");
} else if (number < 0) {
printf("Negative number.");
} else {
printf("Positive number.");
}
// --- END OF SOLUTION CODE ---
// --- START OF SOLUTION CODE ---
if (number == 0) {
printf("The number is 0.");
} else if (number < 0) {
printf("Negative number.");
} else {
printf("Positive number.");
}
// --- END OF SOLUTION CODE ---You may submit any number of times before the due date. The final submission will be considered for grading.This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
CompilationSuccessful|Public Test Cases: 3/3 PassedNote: These tests may not be considered while scoring.
Note: These tests may not be considered while scoring.
Public Test Cases
Week-03: Practice Program-03Due date on 2026-08-13, 23:59 IST
Due date on 2026-08-13, 23:59 IST
Complete Program
C#include <stdio.h>
int main() {
int number;
scanf("%d", &number);
// --- START OF SOLUTION CODE ---
if (number % 2 == 0) {
printf("%d is even.", number);
} else {
printf("%d is odd.", number);
}
return 0;
// --- END OF SOLUTION CODE ---
}
#include <stdio.h>
int main() {
int number;
scanf("%d", &number);
// --- START OF SOLUTION CODE ---
if (number % 2 == 0) {
printf("%d is even.", number);
} else {
printf("%d is odd.", number);
}
return 0;
// --- END OF SOLUTION CODE ---
}
Code Snippet to Paste in the Editor
C// --- START OF SOLUTION CODE ---
if (number % 2 == 0) {
printf("%d is even.", number);
} else {
printf("%d is odd.", number);
}
return 0;
// --- END OF SOLUTION CODE ---
// --- START OF SOLUTION CODE ---
if (number % 2 == 0) {
printf("%d is even.", number);
} else {
printf("%d is odd.", number);
}
return 0;
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-13, 23:59 IST
Complete Program
C#include <stdio.h>
int main() {
int n1, n2, n3;
scanf("%d %d %d", &n1, &n2, &n3);
// --- START OF SOLUTION CODE ---
if (n1 >= n2 && n1 >= n3) {
printf("%d is the largest number.", n1);
} else if (n2 >= n1 && n2 >= n3) {
printf("%d is the largest number.", n2);
} else {
printf("%d is the largest number.", n3);
}
return 0;
// --- END OF SOLUTION CODE ---
}
#include <stdio.h>
int main() {
int n1, n2, n3;
scanf("%d %d %d", &n1, &n2, &n3);
// --- START OF SOLUTION CODE ---
if (n1 >= n2 && n1 >= n3) {
printf("%d is the largest number.", n1);
} else if (n2 >= n1 && n2 >= n3) {
printf("%d is the largest number.", n2);
} else {
printf("%d is the largest number.", n3);
}
return 0;
// --- END OF SOLUTION CODE ---
}
Code Snippet to Paste in the Editor
C// --- START OF SOLUTION CODE ---
if (n1 >= n2 && n1 >= n3) {
printf("%d is the largest number.", n1);
} else if (n2 >= n1 && n2 >= n3) {
printf("%d is the largest number.", n2);
} else {
printf("%d is the largest number.", n3);
}
return 0;
// --- END OF SOLUTION CODE ---
// --- START OF SOLUTION CODE ---
if (n1 >= n2 && n1 >= n3) {
printf("%d is the largest number.", n1);
} else if (n2 >= n1 && n2 >= n3) {
printf("%d is the largest number.", n2);
} else {
printf("%d is the largest number.", n3);
}
return 0;
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-20, 23:59 IST
Complete Program
#include<stdio.h>
void main()
{
int n;
long int fact; /* n is the number whose factorial we have to find and fact is the factorial */
scanf("%d",&n); /* The value of n is taken from test cases */
/* complete the program. Use the printf statements in the format mentioned below
to match your output exactly with output test cases
printf("The Factorial of %d is : %ld",n,fact);
You can declare any other variables if required */
// --- START OF SOLUTION CODE ---
int temp = n;
fact = 1;
while (temp > 1)
{
fact = fact * temp;
temp--;
}
printf("The Factorial of %d is : %ld", n, fact);
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int temp = n;
fact = 1;
while (temp > 1)
{
fact = fact * temp;
temp--;
}
printf("The Factorial of %d is : %ld", n, fact);
}
// --- END OF SOLUTION CODE ---
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-20, 23:59 IST
Complete Program
#include <stdio.h>
void main()
{
int N, sum=0;
scanf("%d", &N); /* The value of N is taken from the test cases */
/* Complete the program. Please use the printf statement given below to
exactly match your output with the test cases.
printf("Sum = %d", sum);
*/
// --- START OF SOLUTION CODE ---
int i;
for (i = 2; i <= N; i += 2)
{
sum += i;
}
printf("Sum = %d", sum);
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int i;
for (i = 2; i <= N; i += 2)
{
sum += i;
}
printf("Sum = %d", sum);
}
// --- END OF SOLUTION CODE ---
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-20, 23:59 IST
Complete Program
#include <stdio.h>
int main()
{
int base, exponent;
long int result;
scanf("%d", &base); //The base value is taken from test case
scanf("%d", &exponent); //The exponent value is taken from test case
// --- START OF SOLUTION CODE ---
int exp = exponent;
result = 1;
while (exp > 0)
{
result = result * base;
exp--;
}
// --- END OF SOLUTION CODE ---
printf("The result is : %ld", result);
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int exp = exponent;
result = 1;
while (exp > 0)
{
result = result * base;
exp--;
}
// --- END OF SOLUTION CODE ---
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-20, 23:59 IST
Complete Program
#include <stdio.h>
int main()
{
int N, First_digit, Last_digit;
scanf("%d", &N); //The number is accepted from the test case
// --- START OF SOLUTION CODE ---
Last_digit = N % 10;
First_digit = N;
while (First_digit >= 10)
{
First_digit = First_digit / 10;
}
// --- END OF SOLUTION CODE ---
printf("Sum of First and Last digit = %d", First_digit + Last_digit);
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
Last_digit = N % 10;
First_digit = N;
while (First_digit >= 10)
{
First_digit = First_digit / 10;
}
// --- END OF SOLUTION CODE ---
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-27, 23:59 IST
Complete Program
#include <stdio.h>
int main()
{
int N;
scanf("%d",&N); /* An integer number taken as input from test cases */
/*Complete the program by writing the rest of the code in the space provided.
Please copy and paste the printf statement given below wherever required
printf("%d is a perfect number.",N);
printf("%d is not a perfect number.",N);
*/
// --- START OF SOLUTION CODE ---
int sum = 0;
for (int i = 1; i < N; i++)
{
if (N % i == 0)
{
sum += i;
}
}
if (sum == N && N > 0)
{
printf("%d is a perfect number.", N);
}
else
{
printf("%d is not a perfect number.", N);
}
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int sum = 0;
for (int i = 1; i < N; i++)
{
if (N % i == 0)
{
sum += i;
}
}
if (sum == N && N > 0)
{
printf("%d is a perfect number.", N);
}
else
{
printf("%d is not a perfect number.", N);
}
return 0;
}
// --- END OF SOLUTION CODE ---
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-27, 23:59 IST
Complete Program
#include <stdio.h>
int main()
{
int N;
scanf("%d",&N); /*The number is accepted from the test case data*/
/* Complete the rest of the code. Please use the printf statements as below
by just changing the variables used in your program
printf("The number %d contains %d digits.",N,count);
*/
// --- START OF SOLUTION CODE ---
int count = 0;
int temp = N;
do {
count++;
temp /= 10;
} while (temp != 0);
printf("The number %d contains %d digits.", N, count);
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int count = 0;
int temp = N;
do {
count++;
temp /= 10;
} while (temp != 0);
printf("The number %d contains %d digits.", N, count);
return 0;
}
// --- END OF SOLUTION CODE ---
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-27, 23:59 IST
Complete Program
#include <stdio.h>
int main()
{
int N;
scanf("%d",&N); /* The value of N is taken from the test case data */
/* Complete the code.
Use the printf statements as below
printf("%d is a number that can be expressed as power of 2.",N);
printf("%d cannot be expressed as power of 2.",N);
*/
// --- START OF SOLUTION CODE ---
int temp = N;
int flag = 1;
if (temp <= 0)
{
flag = 0;
}
else
{
while (temp > 1)
{
if (temp % 2 != 0)
{
flag = 0;
break;
}
temp = temp / 2;
}
}
if (flag == 1)
{
printf("%d is a number that can be expressed as power of 2.", N);
}
else
{
printf("%d cannot be expressed as power of 2.", N);
}
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int temp = N;
int flag = 1;
if (temp <= 0)
{
flag = 0;
}
else
{
while (temp > 1)
{
if (temp % 2 != 0)
{
flag = 0;
break;
}
temp = temp / 2;
}
}
if (flag == 1)
{
printf("%d is a number that can be expressed as power of 2.", N);
}
else
{
printf("%d cannot be expressed as power of 2.", N);
}
return 0;
}
// --- END OF SOLUTION CODE ---
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-27, 23:59 IST
Complete Program
#include<stdio.h>
int main()
{
int N;
float sum = 0.0;
scanf("%d",&N); /*Read the value of N from test cases provided*/
/* Complete the program. Please use the printf statement given below:
printf("Sum of the series is: %.2f\n",sum);
*/
// --- START OF SOLUTION CODE ---
int i;
for (i = 1; i <= N; i++)
{
sum += 1.0 / i;
}
printf("Sum of the series is: %.2f\n", sum);
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int i;
for (i = 1; i <= N; i++)
{
sum += 1.0 / i;
}
printf("Sum of the series is: %.2f\n", sum);
return 0;
}
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-09-03, 23:59 IST
Complete Program
#include <stdio.h>
int main()
{
int i, n, largest;
int arr[100];
scanf("%d", &n); /*Accepts total number of elements from the test data */
for(i = 0; i < n; ++i)
{
scanf("%d", &arr[i]); /* Accepts the array element from test data */
}
// --- START OF SOLUTION CODE ---
largest = arr[0];
for (i = 1; i < n; ++i)
{
if (arr[i] > largest)
{
largest = arr[i];
}
}
printf("Largest element = %d", largest);
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
largest = arr[0];
for (i = 1; i < n; ++i)
{
if (arr[i] > largest)
{
largest = arr[i];
}
}
printf("Largest element = %d", largest);
return 0;
}
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-09-03, 23:59 IST
Complete Program
#include<stdio.h>
int main() {
int arr[20], i, n;
scanf("%d", &n); /* Accepts the number of elements in the array */
for (i = 0; i < n; i++)
scanf("%d", &arr[i]); /*Accepts the elements of the array */
// --- START OF SOLUTION CODE ---
int temp;
for (i = 0; i < n / 2; i++) {
temp = arr[i];
arr[i] = arr[n - 1 - i];
arr[n - 1 - i] = temp;
}
// --- END OF SOLUTION CODE ---
for (i = 0; i < n; i++) {
printf("%d\n", arr[i]); // For printing the array elements
}
return (0);
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int temp;
for (i = 0; i < n / 2; i++) {
temp = arr[i];
arr[i] = arr[n - 1 - i];
arr[n - 1 - i] = temp;
}
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-09-03, 23:59 IST
Complete Program
#include<stdio.h>
int main()
{
int arr1[20], arr2[20], array_new[40], n1, n2, size, i;
/*n1 size of first array (i.e. arr1[]), n2 size of second array(i.e. arr2[]),
size is the total size of the new array (array_new[]) */
scanf("%d", &n1); //Get the size of first array from test data and store it in n1.
for (i = 0; i < n1; i++)
scanf("%d", &arr1[i]); //Accepts the values for first array
scanf("%d", &n2); //Get the size of second array from test data and store it in n2.
for (i = 0; i < n2; i++)
scanf("%d", &arr2[i]); //Accepts the values for second array
// --- START OF SOLUTION CODE ---
int j;
for (i = 0; i < n1; ++i)
array_new[i] = arr1[i];
size = n1 + n2;
for (i = 0, j = n1; j < size && i < n2; ++i, ++j)
array_new[j] = arr2[i];
// --- END OF SOLUTION CODE ---
//Printing after merging
for (i = 0; i < size; i++) {
printf("%d\n", array_new[i]);
}
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int j;
for (i = 0; i < n1; ++i)
array_new[i] = arr1[i];
size = n1 + n2;
for (i = 0, j = n1; j < size && i < n2; ++i, ++j)
array_new[j] = arr2[i];
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-09-03, 23:59 IST
Complete Program
#include<stdio.h>
int main()
{
int array[50], i, size;
scanf("%d", &size); /*Accepts the size of array from test case data */
for (i = 0; i < size; i++)
scanf("%d", &array[i]); /* Read the array elements from the test case data */
// --- START OF SOLUTION CODE ---
int j, k;
for (i = 0; i < size; i++) {
for (j = i + 1; j < size;) {
if (array[j] == array[i]) {
for (k = j; k < size; k++) {
array[k] = array[k + 1];
}
size--;
} else
j++;
}
}
// --- END OF SOLUTION CODE ---
for (i = 0; i < size; i++) {
printf("%d\n", array[i]);
}
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int j, k;
for (i = 0; i < size; i++) {
for (j = i + 1; j < size;) {
if (array[j] == array[i]) {
for (k = j; k < size; k++) {
array[k] = array[k + 1];
}
size--;
} else
j++;
}
}
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-09-10, 23:59 IST
Complete Program
#include<stdio.h>
int main() {
int upper = 0, lower = 0;
char ch[100];
scanf(" %[^\n]s", ch); /*A word or a sentence is accepted from test case data */
/* Complete the remaining part of the code to store number of uppercase letters
in the variable upper and lowercase letters in variable lower.
The print part of already written. You can declare any variable if necessary */
// --- START OF SOLUTION CODE ---
int i = 0;
while (ch[i] != '\0') {
if (ch[i] >= 'A' && ch[i] <= 'Z') {
upper++;
} else if (ch[i] >= 'a' && ch[i] <= 'z') {
lower++;
}
i++;
}
// --- END OF SOLUTION CODE ---
printf("Uppercase Letters : %d\n", upper); /*prints number of uppercase letters */
printf("Lowercase Letters : %d", lower); /*prints number of lowercase letters */
return (0);
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int i = 0;
while (ch[i] != '\0') {
if (ch[i] >= 'A' && ch[i] <= 'Z') {
upper++;
} else if (ch[i] >= 'a' && ch[i] <= 'z') {
lower++;
}
i++;
}
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-09-10, 23:59 IST
Complete Program
#include <stdio.h>
int main()
{
int matrix[20][20];
int i,j,r,c;
scanf("%d",&r); //Accepts number of rows
scanf("%d",&c); //Accepts number of columns
for(i=0;i< r;i++) //Accepts the matrix elements from the test case data
{
for(j=0;j< c;j++)
{
scanf("%d",&matrix[i][j]);
}
}
/*Complete the code to print the sum of each rows. Use the printf() statement as
printf("%d\n",sum); Where sum is the sum of a row.
*/
// --- START OF SOLUTION CODE ---
int sum;
for(i=0;i< r;i++)
{
sum=0;
for(j=0;j< c;j++)
{
sum += matrix[i][j];
}
printf("%d\n",sum);
}
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int sum;
for(i=0;i< r;i++)
{
sum=0;
for(j=0;j< c;j++)
{
sum += matrix[i][j];
}
printf("%d\n",sum);
}
return 0;
}
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-09-10, 23:59 IST
Complete Program
#include <stdio.h>
int main()
{
int matrix_A[20][20], matrix_B[20][20], matrix_C[20][20];
int i,j,row,col;
scanf("%d",&row); //Accepts number of rows
scanf("%d",&col); //Accepts number of columns
/* Elements of first matrix are accepted from test data */
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
scanf("%d", &matrix_A[i][j]);
}
}
/* Elements of second matrix are accepted from test data */
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
scanf("%d", &matrix_B[i][j]);
}
}
/* Complete the program to get the desired output. Use printf() statement as below
printf("%d ", matrix_C[i][j]); You can declare your own variables if required.
*/
// --- START OF SOLUTION CODE ---
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
matrix_C[i][j] = matrix_A[i][j] - matrix_B[i][j];
}
}
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
printf("%d ", matrix_C[i][j]);
}
printf("\n");
}
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
matrix_C[i][j] = matrix_A[i][j] - matrix_B[i][j];
}
}
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
printf("%d ", matrix_C[i][j]);
}
printf("\n");
}
return 0;
}
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-09-10, 23:59 IST
Complete Program
#include<stdio.h>
#include<string.h>
int main()
{
char str[100]={0},substr[100][100]={0};
//str[100] is for storing the sentence and substr[50][50] is for storing each word.
scanf("%[^\n]s", str); //Accepts the sentence from the test case data.
/* Complete the program to get the desired output.
The print statement should be as below
printf("Largest Word is: %s\nSmallest word is: %s\n", -------,--------);
*/
// --- START OF SOLUTION CODE ---
int i=0,j=0,k=0,a,minIndex=0,maxIndex=0,max=0,min=0;
char c;
while(str[k]!='\0') //for splitting sentence into words
{
j=0;
while(str[k]!=' '&&str[k]!='\0' && str[k]!='.')
{
substr[i][j]=str[k];
k++;
j++;
}
substr[i][j]='\0';
i++;
if(str[k]!='\0')
{
k++;
}
}
int len=i;
max=strlen(substr[0]);
min=strlen(substr[0]);
//After splitting getting length of string and finding its index having max length and index having min length
for(a=1; a<len; a++)
{
if(strlen(substr[a]) > max)
{
max = strlen(substr[a]);
maxIndex = a;
}
if(strlen(substr[a]) < min)
{
min = strlen(substr[a]);
minIndex = a;
}
}
printf("Largest Word is: %s\nSmallest word is: %s\n", substr[maxIndex], substr[minIndex]);
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int i=0,j=0,k=0,a,minIndex=0,maxIndex=0,max=0,min=0;
char c;
while(str[k]!='\0') //for splitting sentence into words
{
j=0;
while(str[k]!=' '&&str[k]!='\0' && str[k]!='.')
{
substr[i][j]=str[k];
k++;
j++;
}
substr[i][j]='\0';
i++;
if(str[k]!='\0')
{
k++;
}
}
int len=i;
max=strlen(substr[0]);
min=strlen(substr[0]);
//After splitting getting length of string and finding its index having max length and index having min length
for(a=1; a<len; a++)
{
if(strlen(substr[a]) > max)
{
max = strlen(substr[a]);
maxIndex = a;
}
if(strlen(substr[a]) < min)
{
min = strlen(substr[a]);
minIndex = a;
}
}
printf("Largest Word is: %s\nSmallest word is: %s\n", substr[maxIndex], substr[minIndex]);
return 0;
}
// --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.