Barkha
Barkha
REG ID:67855
#include <stdio.h>
#include <string.h>
void create_account() {
int age;
scanf("%s", username);
scanf("%s", password);
scanf("%d", &age);
} else {
// User is under 18
printf("Account creation failed. You must be above 18 years old to create an account.\n");
}
}
int main() {
create_account();
return 0;
Problem02(login.sb)
Takeausernameandpasswordas inputandvalidateifpasswordisequalsto12345thenlogintothesystem.
#include <stdio.h>
#include <string.h>
void login() {
scanf("%s", username);
if (strcmp(password, "12345") == 0) {
} else {
int main() {
login();
return 0;
Problem03(change.sb)
Take a number as input if the number is less than 0 then change the color of sprite else change
the positionof thespriteby2 pointsbyy.
Assignment 02
Create script to generate three numbers randomly and set to the variables (guess1, guess2
guess3) respectively after that play a game if the all three generated number are equal then you
win
the game otherwise lose.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(0));
} else {
return 0;
Problem02 (circle.sb)
Problem03 (voteCasting.sb)
Create script to take age of the person as input and determine whether it is eligible
for casting his/her own vote.
else
Assignment 03
1) Write a C program to convert temperature from Celsius to Fahrenheit. Use the formula:
Fahrenheit = (Celsius * 9/5) + 32
#include <stdio.h>
int main() {
scanf("%f", &celsius);
return 0;
}
2) Write a C program to calculate the volume of a cube. The volume of a cube is given by:
Volume = side * side * side
#include <stdio.h>
int main() {
float side, volume;
return 0;
}
3) Write a C program to take three numbers as input and calculate their sum and average.
#include <stdio.h>
int main() {
average = sum / 3;
return 0;
4) Write a C program to convert a given number of days into years, weeks, and days.
#include <stdio.h>
int main() {
inttotal_days, years, weeks, days;
return 0;
}
Assignment 04
1. Write a C program that asks the user for their age and uses an if-else statement to check if they are
eligible to vote (18 years or older). Print a message indicating eligibility.
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 18) {
printf("You are eligible to vote!\n");
} else {
printf("You are not eligible to vote.\n");
}
return 0;
}
2. Write a program to check whether a year entered by the user is a leap year or not using nested if-else.
#include <stdio.h>
int main() {
int year;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
}
} else {
// If divisible by 4 but not by 100
printf("%d is a leap year.\n", year);
}
} else {
// If not divisible by 4
printf("%d is not a leap year.\n", year);
}
return 0;
}
3. Write a simple C program using cascaded if-else statements to perform addition, subtraction,
multiplication, or division based on user input.
#include <stdio.h>
int main() {
int num1, num2;
char operator;
printf("Enter first number: ");
scanf("%d", &num1);
if (operator == '+') {
printf("%d + %d = %d\n", num1, num2, num1 + num2);
} else if (operator == '-') {
printf("%d - %d = %d\n", num1, num2, num1 - num2);
} else if (operator == '*') {
printf("%d * %d = %d\n", num1, num2, num1 * num2);
} else if (operator == '/') {
if (num2 != 0) {
printf("%d / %d = %.2f\n", num1, num2, (float)num1 / num2);
} else {
printf("Error! Division by zero is not allowed.\n");
}
} else {
printf("Invalid operator! Please use +, -, *, or /.\n");
}
return 0;
}
4. Write a C program to input the coefficients a, b and c of a quadratic equation in the form
ax2 + bx+ c=0.Using a cascaded if-else statement, calculate the discriminant and check the nature of
the roots. The program should indicate whether the roots are real and distinct, real and equal, or
imaginary.
#include <stdio.h>
#include <math.h>
intmain() {
if (a == 0) {
printf("Invalid input! 'a' cannot be 0 for a quadratic equation.\n");
} else {
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
return 0;
}
Assignment 05
● Question 1: Write a program to prompt the user to enter a number (1–4), where each number
represents a season (1 for Spring, 2 for Summer, etc.). Use a switch-case to display the season
name based on the user's input.
#include <stdio.h>
intmain() {
int season;
scanf("%d", &season);
switch (season) {
case 1:
printf("Spring\n");
break;
case 2:
printf("Summer\n");
break;
case 3:
printf("Autumn\n");
break;
case 4:
printf("Winter\n");
break;
default:
break;
return 0;
● Question 2: Write a program that takes a character input from the user and uses a switch-case to
check if the letter is a vowel (a, e, i, o, u). If it’s a vowel, print "Vowel"; otherwise, print
"Consonant."
#include <stdio.h>
#include <ctype.h>
intmain() {
char input;
input = tolower(input);
if (!isalpha(input)) {
} else {
switch (input) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("Vowel\n");
break;
default:
printf("Consonant\n");
return 0;
● Question 3: Write a program that asks the user to choose a conversion type:
o 1: Kilometers to Miles
o 2: Meters to Feet
o 3: Centimeters to Inches
Based on the user’s choice, use a switch-case to perform the selected conversion and
display the result.
#include <stdio.h>
intmain() {
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%f", &value);
break;
case 2:
scanf("%f", &value);
break;
case 3:
scanf("%f", &value);
result = value * 0.393701; // Conversion factor
break;
default:
return 0;
Assignment 06
Write a program that takes a series of integer inputs from the user and performs the
following:
Use a while loop to keep accepting input until the user enters a zero (0) to stop.
Use a do while loop to display each entered number until zero is encountered.
Use a for loop to display the total count of numbers entered, excluding zero.
LAB TASKS:
Task 01:
Sum of Integers Using While Loop
Write a program that prompts the user to enter a positive integer and calculates the sum
of all integers from 1 to that number using a while loop.
#include <stdio.h>
intmain() {
scanf("%d", &number);
if (number <= 0) {
} else {
sum += i;
i++;
return 0;
}
Task 02:
User Input Validation Using Do While Loop
Create a program that continuously asks the user to enter a number until they enter a negative
number. Use a do while loop
#include <stdio.h>
intmain() {
int number;
do {
scanf("%d", &number);
if (number >= 0) {
} while (number >= 0); // Continue looping until a negative number is entered
Task 03:
Printing Even Numbers Using For Loop
Develop a program that prints the first 10 even numbers (0 to 18) using a for loop.
#include <stdio.h>
intmain() {
inti;
Assignment 07
1. Find out the sum of series 12 + 22 + …. + n2
2. If a four-digit number is input through the keyboard, write a program to obtain the sum of
the first and last digit of this number.
3. Write a program to find GCD (greatest common divisor or HCF) and LCM (least common
multiple) of two numbers.
#include <stdio.h>
intmain() {
printf("*");
return 0;
scanf("%d", &number);
original = number;
while (number != 0) {
number /= 10;
if (original == reversed) {
} else {
return 0;
}
3. Write a program to generate Fibonacci series.
#include <stdio.h>
intmain() {
scanf("%d", &n);
if (n <= 0) {
} else {
if (i == 1) {
next = first;
} else if (i == 2) {
next = second;
} else {
second = next;
printf("\n");
return 0;
intmain() {
int rows = 5; // Number of rows in the pattern
return 0;
}