Lab Report -leading university
Lab Report -leading university
Lab Report -leading university
NAME:MD.SAKIB RUHANI.
BATCH:D(63)
ID NO:0182410012101179
#include <stdio.h>
int main(){
printf("Hello World!");
return 0;
}
#include <stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum: %d\\n", sum);
return 0;
}
Output:
3. Subtracting two numbers:
#include <stdio.h>
int main() {
int a, b, diff;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
diff = a - b;
printf("Difference: %d\\n", diff);
return 0;
}
#include <stdio.h>
int main() {
int a, b, product;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
product = a * b;
printf("Product: %d\\n", product);
return 0;
}
5. Dividing two numbers:
#include <stdio.h>
int main() {
float a, b, result;
printf("Enter two numbers: ");
scanf("%f %f", &a, &b);
if (b != 0) {
result = a / b;
printf("Result: %.2f\\n", result);
} else {
printf("Division by zero is not allowed.\\n");
}
return 0;
}
#include <stdio.h>
int main() {
float a, b, average;
printf("Enter two numbers: ");
scanf("%f %f", &a, &b);
average = (a + b) / 2;
printf("Average: %.2f\\n", average);
return 0;
}
8. Finding the factorial:
#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter a positive number: ");
scanf("%d", &n);
if (n < 0) {
printf("Factorial is not defined for negative numbers.\\n");
} else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d: %llu\\n", n, fact);
}
return 0;
}
9. Reverse a number :.
#include <stdio.h>
int main() {
int n, reversed = 0, remainder;
printf("Enter a number: ");
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}
printf("Reversed Number: %d\\n", reversed);
return 0;
}
#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
if (n % 2 == 0) {
printf("The number is Even.\\n");
} else {
printf("The number is Odd.\\n");
}
return 0;
}
#include <stdio.h>
int main() {
int n, count = 0;
printf("Enter a number: ");
scanf("%d", &n);
while (n != 0) {
n = n / 10;
++count;
}
printf("Number of digits: %d\\n", count);
return 0;
}
#include <stdio.h>
int main() {
int num, i, flag = 0;
printf("Enter a number: ");
scanf("%d", &num);
for (i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
flag = 1;
break;
}
}
if (num == 1) {
printf("1 is neither prime nor composite.\\n");
} else {
if (flag == 0) {
printf("%d is a prime number.\\n", num);
} else {
printf("%d is not a prime number.\\n", num);
}
}
return 0;
}
#include <stdio.h>
int main() {
int n, i;
printf("Enter a number: ");
scanf("%d", &n);
printf("Factors of %d are: ", n);
for (i = 1; i <= n; i++) {
if (n % i == 0) {
printf("%d ", i);
}
}
printf("\\n");
return 0;
}
#include <stdio.h>
int main() {
int n, i;
float sum = 0.0, average;
printf("Enter number of elements: ");
scanf("%d", &n);
float arr[n];
printf("Enter the elements: ");
for (i = 0; i < n; i++) {
scanf("%f", &arr[i]);
sum += arr[i];
}
average = sum / n;
printf("Average: %.2f\\n", average);
return 0;
}
15. Boolean Checking (True/False):
#include <stdio.h>
int main() {
int num;
printf("Enter a number (1 for True, 0 for False): ");
scanf("%d", &num);
if (num == 1) {
printf("True\\n");
} else {
printf("False\\n");
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i, len;
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
len = strlen(str);
printf("Reversed string: ");
for (i = len - 1; i >= 0; i--) {
printf("%c", str[i]);
}
printf("\n"); return 0;
}
int main() {
char str[100];
int i, len, flag = 0;
by fgets
str[strcspn(str, "\n")] = '\0';
len = strlen(str);
for (i = 0; i < len / 2; i++) {
if (str[i] != str[len - i - 1]) {
flag = 1;
break;
}
}
20. Build a CGPA calculator.with switch case:
#include <stdio.h>
int main(){
int score;
printf("Enter your score: ");
scanf("%d", &score);
switch (score){
case 80 ... 100:
printf("Your grade is A+");
break;
case 75 ... 79:printf("Your grade is A");
break;
case 70 ... 74:
printf("Your grade is A-");
break;
case 65 ... 69:
printf("Your grade is B+");
break;
case 60 ... 64:
printf("Your grade is B");
break;
case 55 ... 59:
printf("Your grade is B-");
break;
case 50 ... 54:
printf("Your grade is C+");
break;
case 45 ... 49:
printf("Your grade is C");
break;
case 40 ... 44:
printf("Your grade is D");
break;
case 0 ... 39:
printf("Your grade is F");
break;
default:
printf("Invalid input");}
return 0;
}