0% found this document useful (0 votes)
11 views14 pages

Co Lab Project

Uploaded by

rockstart22005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views14 pages

Co Lab Project

Uploaded by

rockstart22005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 1
Question: Write a program to find simple interest.
Code:
#include<stdio.h>

int main(){
int P;
int R;
int T;
int SI;

printf("enter p:\n");
scanf("%d",&P);
printf("enter R:\n");
scanf("%d",&R);
printf("enter T:\n");
scanf("%d",&T);
SI = (P*R*T)/100;

printf("the simple interest is : %d\n",SI);

return 0;}

OUTPUT:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 2
Question: Write a program to find greatest of 10 in number.
Code:
#include <stdio.h>

int main() {
int numbers[10];
int i, greatest;
printf("Enter ten values:\n");

for (i = 0; i < 10; i++) {


scanf("%d", &numbers[i]);
}

greatest = numbers[0];
for (i = 1; i < 10; i++) {
if (numbers[i] > greatest) {
greatest = numbers[i];
}
}
printf("The greatest of ten numbers is %d\n", greatest);

return 0;
}
Output:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 3
Question: Write a program to find some and average of two number.
Code:
#include<stdio.h>

int main(){
float a;
float b;

printf("entre a:");
scanf("%f",&a);
printf("entre b:");
scanf("%f",&b);

printf("sum of two no is:%f\n",a+b);


printf("avg of 2 no:%f\n",(a+b)/2);

return 0;

Output:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 4
Question: Write a program to find reverse of five digit
number.
CODE:

#include<stdio.h>

int main(){
int n;
printf("entre n:");
scanf("%d",&n);

for(int i=n ; i > 0; i--){

printf("reverse of %d no is:%d\n",n,i);

if(i==n-5){
break;
}
}
return 0;
}

OUTPUT:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 5
Question: Write a program to Implement switch case.
Code:
#include<stdio.h>

int main(){
int option;
printf("entre:");
scanf(“%d”,&option);

switch(option){
case 1:
printf("you seletd option 1\n");
break;

case 2:
printf("you seletd option 2\n");
break;

case 3:
printf("you seletd option 3\n");
break;

case 4:
printf("you seletd option 4\n");
break;

default:
printf("invalid option selcted\n");

return 0;
}
Ouput:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 6
Question: Write a program to convert binary to decimal
Code :
#include <stdio.h>
#include <string.h>
#include <math.h>

int binary_to_decimal(const char *binary_str) {


int decimal_value = 0;
int length = strlen(binary_str);

for (int i = 0; i < length; i++) {


if (binary_str[length - 1 - i] == '1') {
decimal_value += pow(2, i);
} else if (binary_str[length - 1 - i] != '0') {
printf("Invalid binary number\n");
return -1;
}
}

return decimal_value;
}

int main() {
char binary_input[65];

printf("Enter a binary number: ");


scanf("%64s", binary_input);

int decimal_output = binary_to_decimal(binary_input);

if (decimal_output != -1) {
printf("The decimal value of binary %s is %d.\n", binary_input,
decimal_output);
}

return 0;
}
Name: Tanuj Roll no 24/A14/035 class: EC-04

Output:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 7
Question: Write a program to convert decimal to binary.
Code:
#include <stdio.h>

void decimal_to_binary(int decimal) {


if (decimal == 0) {
printf("0");
return;
}

int binary[32]; // Array to hold binary digits


int index = 0;

// Convert decimal to binary


while (decimal > 0) {
binary[index] = decimal % 2;
decimal = decimal / 2;
index++;
}

printf("Binary: ");
for (int i = index - 1; i >= 0; i--) {
printf("%d", binary[i]);
}
printf("\n");
}

int main() {
int decimal_input;

printf("Enter a decimal number: ");


scanf("%d", &decimal_input);

printf("Decimal: %d\n", decimal_input);


printf("Binary: ");
decimal_to_binary(decimal_input);

return 0;}
Name: Tanuj Roll no 24/A14/035 class: EC-04

Output:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 8
Question: Write a program to generate fibonacci series
Code:
#include <stdio.h>

void generate_fibonacci(int terms) {


int first = 0, second = 1, next;

printf("Fibonacci Series: ");

for (int i = 0; i < terms; i++) {


if (i == 0) {
printf("%d", first);
continue;
}
if (i == 1) {
printf(", %d", second);
continue;
}

next = first + second;


printf(", %d", next);

first = second;
second = next;
}
printf("\n");
}

int main() {
int terms;

printf("Enter the number of terms for the Fibonacci series: ");


scanf("%d", &terms);

if (terms <= 0) {
printf("Please enter a positive integer.\n");
} else {
generate_fibonacci(terms);
}

return 0;
}
Name: Tanuj Roll no 24/A14/035 class: EC-04

Output:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Expetiment 9
Question: Write a program to find exponential function
Code:
#include <stdio.h>
#include <math.h>

int main() {
double x;

// Prompt the user for input


printf("Enter the value of x: ");
scanf("%lf", &x);

// Calculate e^x using the exp function


double result = exp(x);

// Display the result


printf("e^%.2lf = %.6lf\n", x, result);

return 0;
}

Output:
Name: Tanuj Roll no 24/A14/035 class: EC-04

Experiment 10
Question: Write a program to find sum of digits of a 5 digit
number.
Code:
#include <stdio.h>

int main() {
int number, sum = 0;

// Prompt the user for a 5-digit number


printf("Enter a 5-digit number: ");
scanf("%d", &number);

// Check if the number is a 5-digit number


if (number < 10000 || number > 99999) {
printf("Please enter a valid 5-digit number.\n");
return 1; // Exit the program with an error code
}

// Calculate the sum of digits


while (number > 0) {
sum += number % 10; // Add the last digit to sum
number /= 10; // Remove the last digit
}

// Display the result


printf("The sum of the digits is: %d\n", sum);

return 0;
}

Output:
Name: Tanuj Roll no 24/A14/035 class: EC-04

You might also like