Practical C
Practical C
Practical C
#include <stdio.h>
#include <math.h>
int main() {
float side, area, perimeter, diagonal;
return 0;
}
/*
#include <stdio.h>
#include <math.h>
int main() {
float length, width, area, perimeter, diagonal;
return 0;
}
#include <stdio.h>
#include <math.h>
int main() {
float radius, height, surfaceArea, volume;
return 0;
}
*/
Practical 3 :-
#include <stdio.h>
int main() {
float u, a, time_interval;
char choice;
do {
printf("Enter initial velocity (u in m/s): ");
scanf("%f", &u);
return 0;
}
/*
#include <stdio.h>
int main() {
int operand1, operand2;
char operator;
switch (operator) {
case '+':
printf("Result: %d\n", operand1 + operand2);
break;
case '-':
printf("Result: %d\n", operand1 - operand2);
break;
case '*':
printf("Result: %d\n", operand1 * operand2);
break;
case '/':
if (operand2 != 0) {
printf("Result: %.2f\n", (float)operand1 / operand2);
} else {
printf("Error: Division by zero!\n");
}
break;
default:
printf("Invalid operator!\n");
}
return 0;
}
*/
Practical 4 :-
#include <stdio.h>
int main() {
int num, sum = 0, digit;
return 0;
}
/*
#include <stdio.h>
int main() {
int n, first = 0, second = 1, next, i;
printf("\n");
return 0;
}
#include <stdio.h>
int main() {
int n;
printf("\n");
return 0;
}
*/
Practical 5:-
#include <stdio.h>
#include <math.h>
double calculateFactorial(int n) {
double factorial = 1;
for (int i = 1; i <= n; i++) {
factorial *= i;
}
return factorial;
}
int main() {
double x, sum = 1.0;
int n;
return 0;
}
/*
#include <stdio.h>
#include <math.h>
int main() {
double a, b, c, discriminant, root1, root2;
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and different.\n");
printf("Root 1 = %.4f\n", root1);
printf("Root 2 = %.4f\n", root2);
} else if (discriminant == 0) {
root1 = -b / (2 * a);
printf("Roots are real and the same.\n");
printf("Root = %.4f\n", root1);
} else {
double realPart = -b / (2 * a);
double imaginaryPart = sqrt(-discriminant) / (2 * a);
printf("Roots are complex and different.\n");
printf("Root 1 = %.4f + %.4fi\n", realPart, imaginaryPart);
printf("Root 2 = %.4f - %.4fi\n", realPart, imaginaryPart);
}
return 0;
}
*/
Practical 6 :-
#include <stdio.h>
int main() {
int num;
return 0;
}
/*
#include <stdio.h>
int main() {
int num1, num2;
return 0;
}
*/
Practical 7 :-
#include <stdio.h>
int main() {
int size;
int arr[size];
return 0;
}
/*
#include <stdio.h>
#define MAX_SIZE 10
int main() {
int rows, cols;
// Adding matrices
addMatrices(mat1, mat2, result, rows, cols);
return 0;
}
#include <stdio.h>
#define MAX_SIZE 10
int main() {
int rows1, cols1, rows2, cols2;
if (cols1 != rows2) {
printf("Error: Matrix multiplication not possible due to incompatible
dimensions.\n");
return 1;
}
// Multiplying matrices
multiplyMatrices(mat1, mat2, result, rows1, cols1, cols2);
return 0;
}
*/
Practical 8 :-
#include <stdio.h>
#include <string.h>
int main() {
char mainStr[100], subStr[50];
int position;
// Inserting sub-string
insertSubstring(mainStr, subStr, position);
return 0;
}
/*
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int position, n;
return 0;
}
#include <stdio.h>
#include <string.h>
return 1; // Palindrome
}
int main() {
char str[100];
return 0;
}
*/
Practical 9 :-
#include <stdio.h>
#include <string.h>
int main() {
char S[100], T[50];
if (position != -1) {
printf("Substring '%s' found at position/index: %d\n", T, position);
} else {
printf("Substring '%s' not found in the main string.\n", T);
}
return 0;
}
/*
#include <stdio.h>
// Function to count lines, words, and characters in a given text
void countMetrics(char text[]) {
int lines = 0, words = 0, characters = 0;
int i = 0;
// Counting words
if (text[i] == ' ' || text[i] == '\n' || text[i] == '\t') {
words++;
}
// Counting lines
if (text[i] == '\n') {
lines++;
}
i++;
}
int main() {
char text[1000];
return 0;
}
*/
Practical 10 :-
#include <stdio.h>
int main() {
int rows;
return 0;
}
/*
#include <stdio.h>
printf("\n");
}
}
int main() {
int height;
return 0;
}
*/
Practical 11 :-
#include <stdio.h>
#include <math.h>
int main() {
double x, sum;
int n;
while (1) {
// Read input values
printf("Enter x and n (separated by space): ");
if (scanf("%lf %d", &x, &n) != 2) {
// Handle invalid input
printf("Invalid input. Please enter valid numbers.\n");
while (getchar() != '\n'); // Clear input buffer
continue;
}
if (n < 0) {
// Error: Negative exponent
printf("Error: n should not be less than 0.\n");
continue;
}
if (x == 1 && n == 0) {
// Error: Result is undefined for x=1 and n=0
printf("Error: The result is undefined for x=1 and n=0.\n");
continue;
}
return 0;
}
Practical 12 :-
#include <stdio.h>
int main() {
char binaryNum[100];
findTwosComplement(binaryNum);
return 0;
}
/*
#include <stdio.h>
return decimalNum;
}
int main() {
char romanNum[100];
return 0;
}
*/
Practical 13 :-
#include <stdio.h>
// Find the index of the first appearance of '1' from the right
for (i = 0; binary[i] != '\0'; i++) {
if (binary[i] == '1') {
firstOneIndex = i;
break;
}
}
int main() {
char binary[100];
return 0;
}
/*
#include <stdio.h>
return decimal;
}
int main() {
char roman[20];
if (decimal != -1) {
printf("Decimal Equivalent: %d\n", decimal);
}
return 0;
}
*/
Practical 14 :-
#include <stdio.h>
#include <string.h>
int main() {
char input[1000];
printf("Enter multiline text (Ctrl+D to end on Unix/Linux or Ctrl+Z on
Windows):\n");
return 0;
}
/*
#include <stdio.h>
#include <string.h>
int main() {
char input[1000];
printf("Enter a string: ");
gets(input);
int i = 0;
while (input[i] != '\0') {
// Find the start of a word
while (input[i] == ' ' && input[i] != '\0') {
i++;
}
printf("\n");
return 0;
}
*/