Codes
Codes
Codes
#include <stdio.h>
int main() {
char str[MAX_SIZE];
fgets(str, MAX_SIZE, stdin); // Use stdin to read from the standard input
size_t len = strlen(str); // Include the string.h library for strlen function
str[len - 1] = '\0';
str[i] = toupper(str[i]);
return 0;
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
struct Employee {
char full_name[100];
char sex;
char cellphone_number[15];
int employee_id;
char marital_status;
};
do {
scanf("%s", employee->cellphone_number);
do {
if (scanf("%d", &employee->employee_id) != 1) {
} while (employee->employee_id < 1000); // Assuming employee IDs must be at least 1000
do {
printf("\nEmployee Information:\n");
int main() {
return 0;
#include <stdio.h>
#include <ctype.h> // Include the ctype.h library for character type checking
int main() {
char input;
scanf(" %c", &input); // Use %c to read a single character, and add a space before %c to skip leading
whitespace
determineInputType(input);
return 0;
} else if (isalpha(input)) {
} else {
#include <stdio.h>
#include <string.h>
printf("CPUT offers a wide range of programs in the faculties of engineering, computing, and
architecture.\n");
printf("To register at CPUT, please visit our official website and follow the registration
instructions.\n");
printf("CPUT provides bursary opportunities to eligible students. You can find more information on
} else {
printf("I'm sorry, I couldn't understand your query. Please ask about EBE programs, registration, or
bursary opportunities.\n");
int main() {
printf("Welcome to the CPUT Chatbot. How can I assist you today? (Type 'exit' to quit)\n");
char user_input[100];
while (1) {
printf("You: ");
if (strcmp(user_input, "exit") == 0) {
break;
respondToUserQuery(user_input);
return 0;
#include <stdio.h>
union Data {
int i;
float f;
};
int main() {
data.i = 10;
data.f = 3.14;
return 0;
#include <stdio.h>
// Define a structure named "Person" to represent a person's information
struct Person {
char name[50];
int age;
float height;
};
int main() {
strcpy(person1.name, "John");
person1.age = 30;
person1.height = 5.9;
return 0;
Start
If the length of the username is greater than 6 characters, display an error message and ask the user to
If the length is within the limit, prompt the user to enter a password.
If the password does not contain a special character, display an error message and ask the user to
If both the username length and password meet the criteria, display a success message and proceed
End
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define MAX_USERNAME_LENGTH 6
if (ch == specialCharacters[i]) {
return true;
return false;
int main() {
printf("Registration Page\n");
scanf("%s", username);
if (strlen(username) > MAX_USERNAME_LENGTH) {
scanf("%s", password);
if (isSpecialCharacter(password[i])) {
containsSpecialCharacter = true;
break;
if (!containsSpecialCharacter) {
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUMBER_OF_ASSESSMENTS 5
#define PASSING_SCORE 50
int main() {
srand(time(NULL)); // Seed the random number generator with the current time
int studentsBelowPassing = 0;
int totalScore = 0;
int assessmentScore = rand() % 101; // Generate a random score between 0 and 100
totalScore += assessmentScore;
studentsBelowPassing++;
return 0;
#include <stdio.h>
struct CircuitComponents {
double VCC;
double RB;
double RC;
};
double IB;
double IE;
double IC;
double VCB;
double VCE;
};
choice) {
double VE = VB - VBE;
switch (choice) {
case 1:
output->IB = VE / components.RB;
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
printf("Invalid choice.\n");
switch (choice) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
break;
int main() {
scanf("%lf", &components.VCC);
scanf("%lf", &components.RB);
scanf("%lf", &components.RC);
int choice;
scanf("%d", &choice);
printResult(&output, choice);
return 0;
#include <stdio.h>
struct Date {
};
else {
else {
int main() {
if (result > 0) {
} else {
return 0;
}
#include <stdio.h>
#include <string.h>
struct Employee {
char name[50];
int id;
float salary;
};
int main() {
scanf("%s", employees[i].name);
scanf("%d", &employees[i].id);
scanf("%f", &employees[i].salary);
int highestSalaryIndex = 0;
highestSalaryIndex = i;
}
printf("Employee with highest salary:\n");
return 0;
Write a program to store the roll no. (starting from 1), name and age of 5 students and then print the
details of the student with roll no. 2.
#include <stdio.h>
int main()
int i;
struct student
int roll_no;
char name[30];
int age;
};
printf("Student %d\n",i+1);
stud[i].roll_no = i+1;
scanf("%s",stud[i].name);
printf("Enter age :\n");
scanf("%d", &stud[i].age);
if(stud[i].roll_no == 2)
printf("Student %d\n",i+1);
return 0;
#include <stdio.h>
#include <string.h>
struct Customer {
char name[50];
int accountNumber;
float balance;
};
printf("%s\n", customers[i].name);
customers[i].balance += 100;
int main() {
};
// Task 2: Add $100 to balance of customers with more than $1000 and print updated balances
addBalanceForRichCustomers(customers, numCustomers);
return 0;
#include <stdio.h>
#include <string.h>
struct Customer {
char name[50];
int accountNumber;
float balance;
};
printf("%s\n", customers[i].name);
customers[i].balance += 100;
int main() {
};
printCustomersWithLowBalance(customers, numCustomers);
// Task 2: Add $100 to balance of customers with more than $1000 and print updated balances
addBalanceForRichCustomers(customers, numCustomers);
return 0;
}
#include<stdio.h>
int main()
scanf("%d", &n);
if(n >= 1)
printf("2 ");
if(i%c == 0)
break;
if(c == i) // c is prime
{
printf("%d ", i);
return 0;
#include<stdio.h>
int main()
float a, b, c;
printf("Enter 3 numbers:\n\n");
/*
*/
{
printf("\n\nLargest number is = %.3f", b);
else
return 0;
#include <stdio.h>
struct Date {
int day;
int month;
int year;
};
date->day += daysToAdd;
// Update month and year if the day exceeds the maximum days in a month
date->day -= 30;
date->month++;
} else if (date->month == 2) {
date->day -= 29;
date->month++;
} else {
date->day -= 28;
date->month++;
} else {
date->day -= 31;
date->month++;
date->month -= 12;
date->year++;
int main() {
struct Date currentDate = {5, 11, 2023}; // Assuming current date is November 5, 2023
addDaysToDate(¤tDate, daysToAdd);
return 0;
#include <stdio.h>
#include <string.h>
int main() {
char sentence[100];
int vowelCount = 0;
char ch = sentence[i];
vowelCount++;
}
printf("Number of vowels in the sentence: %d\n", vowelCount);
return 0;
#include <stdio.h>
struct Person {
char name[50];
int age;
float height;
};
int main() {
scanf("%s", person[i].name);
scanf("%d", &person[i].age);
scanf("%f", &person[i].height);
int tallestPersonIndex = 0;
tallestPersonIndex = i;
return 0;
// C program to demonstrate
#include <ctype.h>
#include <stdio.h>
int main()
int j = 0;
char ch;
while (str[j]) {
ch = str[j];
putchar(toupper(ch));
j++;
}
return 0;
#include<stdio.h>
#include<math.h>
#include "rlc.h"
#define pi 3.142
#define pi 3.142
#ifndef RLC_H_INCLUDED
#define RLC_H_INCLUDED
#endif // RLC_H_INCLUDED
double Xz;
*Xc = 1/(2*pi*fc);
*Xl = 2*pi*fl;
Xz = *Xl-*Xc;
*z = sqrt((r*r)+(Xz*Xz));
double P = rms_i*rms_i*r;
return P;
#define pi 3.142
double f;
double s,result;
s=l*c;
result=sqrt(s);
f=1/(2*pi*result);
return f;
double rms_i;
rms_i=v/z;
return rms_i;
double Vz = Vl-Vc;
double Vs = sqrt((Vr*Vr)+(Vz*Vz));
return Vs;
}
int main(void)
double r,l,c,f,v;
double Xc,Xl,z,rms_i,res_f,Vs,P;
scanf("%lf",&r);
scanf("%lf",&l);
scanf("%lf",&c);
scanf("%lf",&v);
scanf("%lf",&f);
Cal_impedance(f*c,f*l,r,&Xc,&Xl,&z);
rms_i=Cal_RMS_current(z,v);
Vs=Cal_series_voltage(r,Xc,Xl,rms_i);
P=Cal_power(rms_i,r);
res_f=Cal_Res_frequency(l,c);
printf("\n");
printf("\n**********************************************************\n");
#include <stdio.h>
#include <stdbool.h>
void printPrimes(int n) {
bool primes[n+1];
primes[i] = true;
if(primes[p] == true) {
for(int i = p * p; i <= n; i += p) {
primes[i] = false;
if(primes[i]) {
printf("\n");
int main() {
int n;
scanf("%d", &n);
printPrimes(n);
return 0;