Introduction to Programming in C - July 2026
Please scroll down for latest Programs 👇
Code compiled and tested successfully!
Due date on 2026-08-14, 23:59 IST
Complete Program
#include <stdio.h>
int find_factorial(int k) {
// --- START OF SOLUTION CODE ---
int fact = 1;
for (int i = 1; i <= k; i++) {
fact *= i;
}
return fact;
// --- END OF SOLUTION CODE ---
}
int main() {
int n, k;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &k);
printf("%d", find_factorial(k));
if (i < n - 1) printf(" ");
}
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int fact = 1;
for (int i = 1; i <= k; i++) {
fact *= i;
}
return 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-14, 23:59 IST
Complete Program
#include <stdio.h>
int parking_fee(int hours)
{
// --- START OF SOLUTION CODE ---
if (hours <= 2) {
return hours * 20;
} else {
return 40 + (hours - 2) * 30;
}
// --- END OF SOLUTION CODE ---
}
int main()
{
int hours;
scanf("%d", &hours);
printf("%d", parking_fee(hours));
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
if (hours <= 2) {
return hours * 20;
} else {
return 40 + (hours - 2) * 30;
}
// --- 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-14, 23:59 IST
Complete Program
// --- START OF SOLUTION CODE ---
#include <stdio.h>
int main() {
char ch;
int k;
scanf(" %c", &ch);
scanf("%d", &k);
printf("%c", (ch - 'a' + k) % 26 + 'a');
return 0;
}
// --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
#include <stdio.h>
int main() {
char ch;
int k;
scanf(" %c", &ch);
scanf("%d", &k);
printf("%c", (ch - 'a' + k) % 26 + 'a');
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>
// --- START OF SOLUTION CODE ---
int *find(int arr[], int n, int key) {
for (int i = 0; i < n; i++) {
if (arr[i] == key) {
return &arr[i];
}
}
return NULL;
}
// --- END OF SOLUTION CODE ---
int main() {
int n, key;
scanf("%d", &n);
int arr[100];
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
scanf("%d", &key);
int *ptr = find(arr, n, key);
if (ptr == NULL) {
printf("Key not found.");
} else {
printf("Value found: %d\n", *ptr);
printf("Index: %ld\n", ptr - arr);
printf("Elements from the first occurrence:\n");
while (ptr < arr + n) {
printf("%d ", *ptr);
ptr++;
}
}
return 0;
}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;
if (scanf("%d", &n) != 1) return 0;
int arr[100];
// Read the array elements
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
// --- START OF SOLUTION CODE ---
for (int i = 0; i < n; i++) {
int isDuplicate = 0;
for (int j = 0; j < i; j++) {
if (arr[i] == arr[j]) {
isDuplicate = 1;
break;
}
}
if (!isDuplicate) {
printf("%d ", arr[i]);
}
}
// --- END OF SOLUTION CODE ---
return 0;
}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 size;
char s1[20], s2[20];
int isanagram = 1;
// Reading the input
if (scanf("%d", &size) != 1) return 0;
scanf("%s", s1);
scanf("%s", s2);
// Flag variable to detect character is present in s2
int flag;
// --- START OF SOLUTION CODE ---
// Loop through each element in s1
for (int i = 0; i < size; i++) {
flag = 0; // Set flag to 0
for (int j = 0; j < size; j++) {
if (s2[j] == s1[i]) { // s1[i] found in s2
s2[j] = '0'; // Set s2[j] to '0', so that it's not counted again
flag = 1;
break;
}
}
if (flag == 0) { // If match is not found, it's not an anagram
isanagram = 0;
}
}
// --- END OF SOLUTION CODE ---
printf("%d", isanagram); // Printing the result
return 0;
}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>
// --- START OF SOLUTION CODE ---
int collatz_repeat(int n) {
if (n == 1) {
return 0;
} else {
if (n % 2 == 1) {
return 1 + collatz_repeat(3 * n + 1);
} else {
return 1 + collatz_repeat(n / 2);
}
}
}
// --- END OF SOLUTION CODE ---
int main() {
int n;
if (scanf("%d", &n) != 1) return 0;
printf("%d", collatz_repeat(n));
return 0;
}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>
#include <stdlib.h>
// --- START OF SOLUTION CODE ---
void genBinary(char *s, int i, int N) {
if (i == N) {
s[N] = '\0';
printf("%s\n", s);
return;
}
s[i] = '0';
genBinary(s, i + 1, N);
s[i] = '1';
genBinary(s, i + 1, N);
}
// --- END OF SOLUTION CODE ---
int main(void) {
char A[8];
int n;
if (scanf("%d", &n) != 1) return 0;
genBinary(A, 0, n);
return 0;
}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, m;
if (scanf("%d %d", &n, &m) != 2) return 0;
int a[n], b[m], c[n + m];
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i < m; i++)
scanf("%d", &b[i]);
int i = 0, j = 0, k = 0;
// --- START OF SOLUTION CODE ---
while (i < n && j < m) {
if (a[i] <= b[j]) {
c[k++] = a[i++];
} else {
c[k++] = b[j++];
}
}
while (i < n) {
c[k++] = a[i++];
}
while (j < m) {
c[k++] = b[j++];
}
for (int x = 0; x < n + m; x++) {
printf("%d ", c[x]);
}
// --- END OF SOLUTION CODE ---
return 0;
}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>
/* Complete the function
check if an n x n matrix A is symmetric
Return 1 if symmetric
Return 0 if not symmetric
*/
int isSymmetric(int n, int A[n][n]) {
// --- START OF SOLUTION CODE ---
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (A[i][j] != A[j][i]) {
return 0;
}
}
}
return 1;
// --- END OF SOLUTION CODE ---
}
int main() {
int n;
// Read the size of the square matrix
if (scanf("%d", &n) != 1) {
return 0;
}
int A[n][n];
// Read the matrix elements
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &A[i][j]);
}
}
printf("%d", isSymmetric(n, A));
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (A[i][j] != A[j][i]) {
return 0;
}
}
}
return 1;
// --- 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 board[9][9];
int i, j, k, r, c;
int num;
// Read the 9x9 grid
for (i = 0; i < 9; i++) {
for (j = 0; j < 9; j++) {
scanf("%d", &board[i][j]);
}
}
/* Complete the code here */
// --- START OF SOLUTION CODE ---
int valid = 1;
// 1. Check Rows
for (i = 0; i < 9; i++) {
int seen[10] = {0};
for (j = 0; j < 9; j++) {
num = board[i][j];
if (num < 1 || num > 9 || seen[num]) {
valid = 0;
break;
}
seen[num] = 1;
}
if (!valid) break;
}
// 2. Check Columns
if (valid) {
for (j = 0; j < 9; j++) {
int seen[10] = {0};
for (i = 0; i < 9; i++) {
num = board[i][j];
if (num < 1 || num > 9 || seen[num]) {
valid = 0;
break;
}
seen[num] = 1;
}
if (!valid) break;
}
}
// 3. Check 3x3 Subgrids
if (valid) {
for (r = 0; r < 9; r += 3) {
for (c = 0; c < 9; c += 3) {
int seen[10] = {0};
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
num = board[r + i][c + j];
if (num < 1 || num > 9 || seen[num]) {
valid = 0;
break;
}
seen[num] = 1;
}
if (!valid) break;
}
if (!valid) break;
}
if (!valid) break;
}
}
if (valid) {
printf("Valid Sudoku\n");
} else {
printf("Invalid Sudoku\n");
}
// --- END OF SOLUTION CODE ---
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
int valid = 1;
// 1. Check Rows
for (i = 0; i < 9; i++) {
int seen[10] = {0};
for (j = 0; j < 9; j++) {
num = board[i][j];
if (num < 1 || num > 9 || seen[num]) {
valid = 0;
break;
}
seen[num] = 1;
}
if (!valid) break;
}
// 2. Check Columns
if (valid) {
for (j = 0; j < 9; j++) {
int seen[10] = {0};
for (i = 0; i < 9; i++) {
num = board[i][j];
if (num < 1 || num > 9 || seen[num]) {
valid = 0;
break;
}
seen[num] = 1;
}
if (!valid) break;
}
}
// 3. Check 3x3 Subgrids
if (valid) {
for (r = 0; r < 9; r += 3) {
for (c = 0; c < 9; c += 3) {
int seen[10] = {0};
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
num = board[r + i][c + j];
if (num < 1 || num > 9 || seen[num]) {
valid = 0;
break;
}
seen[num] = 1;
}
if (!valid) break;
}
if (!valid) break;
}
if (!valid) break;
}
}
if (valid) {
printf("Valid Sudoku\n");
} else {
printf("Invalid Sudoku\n");
}
// --- 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>
char findWinner(char board[3][3])
{
// --- START OF SOLUTION CODE ---
for (int i = 0; i < 3; i++) {
if (board[i][0] == board[i][1] && board[i][1] == board[i][2]) {
if (board[i][0] == 'X' || board[i][0] == 'O')
return board[i][0];
}
}
for (int j = 0; j < 3; j++) {
if (board[0][j] == board[1][j] && board[1][j] == board[2][j]) {
if (board[0][j] == 'X' || board[0][j] == 'O')
return board[0][j];
}
}
if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) {
if (board[0][0] == 'X' || board[0][0] == 'O')
return board[0][0];
}
if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) {
if (board[0][2] == 'X' || board[0][2] == 'O')
return board[0][2];
}
return 'N';
// --- END OF SOLUTION CODE ---
}
int main()
{
char board[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
scanf(" %c", &board[i][j]);
char winner = findWinner(board);
if (winner == 'X')
printf("Player X wins\n");
else if (winner == 'O')
printf("Player O wins\n");
else
printf("No winner\n");
return 0;
}
Code Snippet to Paste in the Editor
// --- START OF SOLUTION CODE ---
for (int i = 0; i < 3; i++) {
if (board[i][0] == board[i][1] && board[i][1] == board[i][2]) {
if (board[i][0] == 'X' || board[i][0] == 'O')
return board[i][0];
}
}
for (int j = 0; j < 3; j++) {
if (board[0][j] == board[1][j] && board[1][j] == board[2][j]) {
if (board[0][j] == 'X' || board[0][j] == 'O')
return board[0][j];
}
}
if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) {
if (board[0][0] == 'X' || board[0][0] == 'O')
return board[0][0];
}
if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) {
if (board[0][2] == 'X' || board[0][2] == 'O')
return board[0][2];
}
return 'N';
// --- 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
If you want to run it locally, here is the full code. Notice that main() is defined first, exactly as in the boilerplate. The function prototypes are declared above main() so that the compiler knows about them when main() calls them.
#include <stdio.h> struct Vector3D { int x; int y; int z; }; // Function declarations (required because main is defined before the implementations) struct Vector3D add(struct Vector3D a, struct Vector3D b); struct Vector3D subtract(struct Vector3D a, struct Vector3D b); int dotProduct(struct Vector3D a, struct Vector3D b); struct Vector3D crossProduct(struct Vector3D a, struct Vector3D b); // --- BOILERPLATE main() (EXACTLY AS GIVEN, DO NOT CHANGE) --- int main() { struct Vector3D a, b; struct Vector3D sum, difference, cross; int dot; scanf("%d %d %d", &a.x, &a.y, &a.z); scanf("%d %d %d", &b.x, &b.y, &b.z); sum = add(a, b); difference = subtract(a, b); dot = dotProduct(a, b); cross = crossProduct(a, b); printf("%d %d %d\n", sum.x, sum.y, sum.z); printf("%d %d %d\n", difference.x, difference.y, difference.z); printf("%d\n", dot); printf("%d %d %d", cross.x, cross.y, cross.z); return 0; } // --- END BOILERPLATE main() --- /* Complete the following functions */ // --- START OF SOLUTION CODE (Paste this block into the editor) --- struct Vector3D add(struct Vector3D a, struct Vector3D b) { struct Vector3D result; result.x = a.x + b.x; result.y = a.y + b.y; result.z = a.z + b.z; return result; } struct Vector3D subtract(struct Vector3D a, struct Vector3D b) { struct Vector3D result; result.x = a.x - b.x; result.y = a.y - b.y; result.z = a.z - b.z; return result; } int dotProduct(struct Vector3D a, struct Vector3D b) { return a.x * b.x + a.y * b.y + a.z * b.z; } struct Vector3D crossProduct(struct Vector3D a, struct Vector3D b) { struct Vector3D result; result.x = a.y * b.z - a.z * b.y; result.y = a.z * b.x - a.x * b.z; result.z = a.x * b.y - a.y * b.x; return result; } // --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
Copy only the following block and paste it exactly where the comment /* Complete the following functions */ appears in your editor. Do not paste the #include, struct Vector3D, or main() — those are already provided by the platform.
// --- START OF SOLUTION CODE --- struct Vector3D add(struct Vector3D a, struct Vector3D b) { struct Vector3D result; result.x = a.x + b.x; result.y = a.y + b.y; result.z = a.z + b.z; return result; } struct Vector3D subtract(struct Vector3D a, struct Vector3D b) { struct Vector3D result; result.x = a.x - b.x; result.y = a.y - b.y; result.z = a.z - b.z; return result; } int dotProduct(struct Vector3D a, struct Vector3D b) { return a.x * b.x + a.y * b.y + a.z * b.z; } struct Vector3D crossProduct(struct Vector3D a, struct Vector3D b) { struct Vector3D result; result.x = a.y * b.z - a.z * b.y; result.y = a.z * b.x - a.x * b.z; result.z = a.x * b.y - a.y * b.x; return result; } // --- 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> #include <stdlib.h> struct Student { // --- START OF SOLUTION CODE --- char name[100]; int physics; int chemistry; int maths; // Must match the field name used in main() // --- END OF SOLUTION CODE --- }; int compare(const void *a, const void *b) { // --- START OF SOLUTION CODE --- const struct Student *s1 = (const struct Student *)a; const struct Student *s2 = (const struct Student *)b; // Higher Physics marks come first (descending) if (s1->physics != s2->physics) return s2->physics - s1->physics; // If Physics ties, higher Chemistry marks come first (descending) if (s1->chemistry != s2->chemistry) return s2->chemistry - s1->chemistry; // If both tie, higher Maths marks come first (descending) return s2->maths - s1->maths; // --- END OF SOLUTION CODE --- } int main() { int n; scanf("%d", &n); struct Student students[n]; for (int i = 0; i < n; i++) { scanf("%s %d %d %d", students[i].name, &students[i].physics, &students[i].chemistry, &students[i].maths); } qsort(students, n, sizeof(struct Student), compare); for (int i = 0; i < n; i++) { printf("%s %d %d %d\n", students[i].name, students[i].physics, students[i].chemistry, students[i].maths); } return 0; }
Code Snippet to Paste in the Editor
Copy exactly this block into the editor at the placeholders /* Complete the struct definition here. */ and /* Complete the code here */:
// --- START OF SOLUTION CODE --- char name[100]; int physics; int chemistry; int maths; int compare(const void *a, const void *b) { const struct Student *s1 = (const struct Student *)a; const struct Student *s2 = (const struct Student *)b; if (s1->physics != s2->physics) return s2->physics - s1->physics; if (s1->chemistry != s2->chemistry) return s2->chemistry - s1->chemistry; return s2->maths - s1->maths; } // --- 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.