0% found this document useful (0 votes)
41 views21 pages

Oops Da

Uploaded by

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

Oops Da

Uploaded by

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

MADHAV SANTHANU

23BDS0193
1. Construct a program to read the numbers until -1 is encountered. Find the average of
positive numbers and negative numbers entered by user.

CODE:

#include<stdio.h>

void main()

int n,ns=0,nc=0;

int ps=0,pc=0;

printf("Enter -1 to exit...");

while(1)

printf("\nEnter the number:");

scanf("%d",&n);

if(n==-1)

break;

else if (n>=0)

ps=ps+n;

pc++;

else

ns=ns+n;

nc++;

printf("The average of negative numbers is:%.2f\n",(float)ns/nc);

printf("The average of positive numbers is:%.2f\n",(float)ps/pc);

}
OUTPUT:

2. Calculate tax given the following conditions: If income is less than or equal to 1,50,000 then
no tax If taxable income is 1,50,001 – 3,00,000 then charge 10% tax for the remaining slab If
taxable income is 3,00,001 – 5,00,000 then charge 20% tax for the remaining slab If taxable
income is above 5,00,001 then charge 30% tax for the remaining slab.

CODE:

#include<stdio.h>

void main()

float in,txn,tax=0;

printf("Enter the income:");

scanf("%f",&in);

if(in<=150000)

tax=0;

else if(in<=300000)

txn=in-150000;

tax=txn*0.1;

else if(in<=500000)
{

txn=in-300000;

tax=15000+txn*0.2;

else

txn=in-500000;

tax=45000+txn*0.3;

printf("Tax=%.2f\n",tax);

OUTPUT:

3. In an organization they decide to give bonus to all the employees on New Year. A 5% bonus
on salary is given to the grade A workers and 10% bonus on salary to the grade B workers.
Write a program to enter the salary and grade of the employee. If the salary of the employee
is less than $10,000 then the employee gets an extra 2% bonus on salary Calculate the bonus
that has to be given to the employee and print the salary that the employee will get.

CODE:

#include<stdio.h>

void main()

int salary;

char ch;

float amt=0,bonus;

printf("Enter the grade of the employee:");

scanf("%c",&ch);

printf("\nEnter the employee salary:");

scanf("%d",&salary);

switch(ch)

case 'A':
{

if(salary<10000)

bonus=(0.07)*salary;

amt=salary+bonus;

else{

bonus=0.05*salary;

amt=salary+bonus;

case 'B':

if(salary<10000)

bonus=0.12*salary;

amt=salary+bonus;

else{

bonus=0.1*salary;

amt=salary+bonus;

default:

printf("No such category.");

printf("Bonus=%.2f\n",bonus);

printf("Total to be paid:%.2f\n",amt);

}
OUTPUT:

4. A company is recruiting persons base on daily wages. The wage is fixed based on the hours of
service. For the first 5 hours the wage is Rs.500. for the additional hours his wage is 10% for 1
hour, 20% for two hours and 30% for three hours. The person can work upto 8 hours per day.
Write C program to read the details of two workers and calculate total payment of workers
using structure.

CODE:

#include<stdio.h>

void main()

char str[20],str1[20];

int h1,h2;

float wages1=0,wages2=0;

printf("Enter the worker name:");

scanf("%s",str);

printf("\nEnter the hours of work:");

scanf("%d",&h1);

printf("\nEnter the worker name:");

scanf("%s",str1);

printf("\nEnter the hours of work:");

scanf("%d",&h2);

if(h1==5)

wages1=500;

if(h2==5)

wages1=500+(0.1*500);
}

if(h1==6)

wages1=500+(0.1*500);

if(h2==6)

wages2=500+(0.1*500);

if(h1==7)

wages1=500+(0.2*500);

if(h2==7)

wages2=500+(0.2*500);

if(h1==8)

wages1=500+(0.3*500);

if(h2==8)

wages2=500+(0.3*500);

printf("Name of first worker:%s\n",str);

if(h1>8){

printf("Received wage of: Not applicable\n");

else{

printf("Received wages of:Rs %.2f\n",wages1);


}

printf("Name of second worker:%s\n",str1);

if(h2>8){

printf("Received wages of: Not applicable\n");

else{

printf("Received wages of:Rs %.2f\n",wages2);

OUTPUT:

5. A neon number is a number where the sum of digits of square of the number is equal to
the number. Write a c program to check whether given number is neon numbers or not.
CODE:
#include<stdio.h>

void main()

int a,b=0,sq;

printf("Enter a number:");

scanf("%d",&a);

sq=a*a;

while(sq!=0)

b=b+sq%10;

sq=sq/10;
}

if(b==a)

printf("Neon number");

else

printf("Not a neon number");

OUTPUT:

6. Complete the function void update(int *a,int *b). It receives two integer pointers, int* a
and int* b. Set the value of to their product, and to their sum. There is no return value,
and no return statement is needed.
CODE:
#include <stdio.h>

void update(int *a, int *b)

int temp_a = *a;

*a = *a + *b;

*b = temp_a * (*b);

int main()

int a, b;

printf("Enter two integers: ");

scanf("%d %d", &a, &b);

update(&a, &b);

printf("Updated values: a = %d, b = %d\n", a, b);


return 0;

OUTPUT:

7. Using pointer, write a C program that reads a character string and a character as
input and deletes all occurrence of this character in the string. The program should
display the corrected string with no holes.
CODE:
#include <stdio.h>

void deleteChar(char *str, char ch) {

char *src = str;

char *dst = str;

while (*src != '\0')

if (*src != ch)

*dst = *src;

dst++;

src++;

*dst = '\0';

int main()

char str[100];

char ch;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

printf("Enter a character to delete: ");


scanf("%c", &ch);

deleteChar(str, ch);

printf("Corrected string: %s\n", str);

return 0;

OUTPUT:

8. Write a c-program to find the smallest possible two digit sum of a 4 digit number.
e.g 5592 is the input 25+59=84 is the smallest two digit sum possible.
CODE:
#include <stdio.h>

int main() {

int num, smallest_sum;

printf("Enter a 4-digit number: ");

scanf("%d", &num);

if(num>=0)

int last_two_digits = num % 100;

int first_two_digits = num / 100;

smallest_sum = last_two_digits % 10 + last_two_digits / 10 + first_two_digits % 10 +


first_two_digits / 10;

printf("The smallest possible two-digit sum of the 4-digit number %d is: %d\n", num,
smallest_sum);

return 0;

else

printf("Invalid");

}
OUTPUT:

9. Write a c-program to display the binary format of the user entered number if it is
prime else display In hexadecimal format
CODE:
#include <stdio.h>

int isPrime(int num) {

if (num <= 1) return 0;

for (int i = 2; i * i <= num; i++) {

if (num % i == 0) return 0;

return 1;

int main() {

int num;

printf("Enter a number: ");

scanf("%d", &num);

if (isPrime(num)) {

printf("");

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

printf("%d", (num >> i) & 1);

printf("\n");

} else {

printf("%X\n", num);

return 0;

}
OUTPUT:

10. Write a function day_name() that receive a number n and return a pointer to a
character string containing the name of the corresponding day. The day names should be
kept in a static table of character strings local to the function.
CODE:
#include <stdio.h>

char* day_name(int n)

static char* names[] =

"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday"

};

n %= 7;

if (n < 0)

n += 7;

return names[n];

int main()

int day_number;

printf("Enter a day number (0-6): ");

scanf("%d", &day_number);

char* day = day_name(day_number);

printf("The name of the day is: %s\n", day);

return 0;

}
OUTPUT:

11. Get a DOB from the user which is an 8 digit number. Check whether it is a Lucky
number or not by following the steps below:
Step-1: Calculate the sum of the digits in the odd-numbered positions (the first, third, fifth
and seventh digits) and multiply this sum by 3.
Step-2: Calculate the sum of the digits in the even-numbered positions (the second, fourth,
sixth and eighth digits) and add this to the previous result (got in step 1).
Given Date of Birth is declared as a lucky number, only if the last digit of the result from
step 2 is 0.
Develop a program to read the Date of Birth, if the number of digits is not 8 then print
“Cannot be processed” and terminate program. If the number of digits is 8 and if the DOB
is a lucky number, output the DOB with the message “Lucky Number.” If the number of
digits is 8 and if the DOB is not a lucky number, output the DOB with the message “Not a
Lucky Number.”
CODE:
#include <stdio.h>

int main()

long long dob;

int odd_sum = 0, even_sum = 0, digit, i = 1;

printf("Enter your Date of Birth (8 digits): ");

scanf("%lld", &dob);

long long temp_dob = dob;

int count = 0;

while (temp_dob != 0) {

temp_dob /= 10;

count++;

if (count != 8) {

printf("Cannot be processed\n");

return 0;

while (dob > 0) {


digit = dob % 10;

if (i % 2 == 0) {

even_sum += digit;

} else {

odd_sum += digit;

dob /= 10;

i++;

int result = (odd_sum * 3) + even_sum;

if (result % 10 == 0) {

printf("Lucky Number.\n");

} else {

printf("Not a Lucky Number.\n");

return 0;

OUTPUT:

12. An online educational platform offers three courses: Programming Courses, Robotics
Courses and Academic Writing Courses : The vendor gives a discount of 10% on orders
for programming based courses if the order is for more than Rs. 1000.
On orders of more than Rs. 750 for Robotics Courses, a discount of 5% is given, and a
discount of 10% is given on orders for academic writing courses of value more than Rs.
500. Assume that the numeric codes 1,2 and 3 are used for Programming, Robotics and
Academic Writing Courses respectively.
Get the max 5 student registration for each courses Write a program that reads the
product code and the order amount and prints out the net amount that the learner is
required to pay after the discount.
CODE:
#include<stdio.h>

void main()

{
int amt,pc;

float total_amt=0,dis=0;

printf("Enter product code:");

scanf("%d",&pc);

switch(pc)

case 1:

printf("\nEnter the amount:");

scanf("%d",&amt);

if(amt>1000)

dis=amt*0.1;

total_amt=amt-dis;

else

total_amt=amt;

break;

case 2:

printf("\nEnter the amount:");

scanf("%d",&amt);

if(amt>750)

dis=amt*0.05;

total_amt=amt-dis;

else
{

total_amt=amt;

break;

case 3:

printf("\nEnter the amount:");

scanf("%d",&amt);

if(amt>500)

dis=amt*0.1;

total_amt=amt-dis;

else

total_amt=amt;

break;

default:

printf("\nWrong Input");

break;

printf("\nThanks, Your discounted amount:%.2f",total_amt);

}
OUTPUT:

13. Earthquake Research Institute of Japan has recorded earthquake occurred in the year
2021 using Richter scale. Develop a program to get the ’n’ (number of times) the
earthquake has occurred and print the number of times in which the magnitude was low,
medium and high. The magnitude value is given in microns. If the value is less than
5.4(inclusive) in microns then it is low, 5.4 to 7.0 (inclusive) it is medium and more than 7.0
it is high. Also, if the number of times recorded is Zero, display as “No earthquake
predicted” and if the number of times recorded is negative, display as “Invalid Input”.

CODE:
#include <stdio.h>
void analyzeEarthquakes(int n, float magnitudes[])
{
int low = 0, medium = 0, high = 0;
if (n <= 0)
{
printf("Invalid Input\n");
return;
}
for (int i = 0; i < n; ++i) {
if (magnitudes[i] < 5.4) {
low++;
} else if (magnitudes[i] >= 5.4 && magnitudes[i] <= 7.0) {
medium++;
} else {
high++;
}
}
if (n == 0)
{
printf("No earthquake predicted\n");
} else
{
printf("Low magnitude earthquakes: %d\n", low);
printf("Medium magnitude earthquakes: %d\n", medium);
printf("High magnitude earthquakes: %d\n", high);
}
}
int main()
{
int n;
printf("Enter the number of earthquakes recorded: ");
scanf("%d", &n);
float magnitudes[n];
printf("Enter the magnitudes for %d earthquakes:\n", n);
for (int i = 0; i < n; ++i) {
printf("Magnitude for earthquake %d: ", i + 1);
scanf("%f", &magnitudes[i]);
}
analyzeEarthquakes(n, magnitudes);
return 0;
}
OUTPUT:

14. Write a c-program to determine the digital root of a second largest element in an array
consisting of 6 elements.
CODE:
#include <stdio.h>
int digitalRoot(int num) {
if (num < 10) {
return num;
}
int sum = 0;
while (num != 0) {
sum += num % 10;
num /= 10;
}
return digitalRoot(sum);
}
int main() {
int arr[6], max1, max2;
printf("Enter 6 elements:\n");
for (int i = 0; i < 6; i++) {
scanf("%d", &arr[i]);
}
max1 = max2 = arr[0];
for (int i = 1; i < 6; i++) {
if (arr[i] > max1) {
max2 = max1;
max1 = arr[i];
} else if (arr[i] > max2 && arr[i] != max1) {
max2 = arr[i];
}
}
int secondLargestDigitalRoot = digitalRoot(max2);
printf("The digital root of the second largest element (%d) is: %d\n", max2,
secondLargestDigitalRoot);

return 0;
}
OUTPUT:

15. Given a cricket team with size M x N with multiple players are already occupied
double bedded rooms, separate the even and odd players and make them to occupy in
single bedded room (Odd & Even). After separation sort and display in ascending order as
shown in output.
CODE:
#include <stdio.h>
int main()
{
int players[100], oddPlayers[100], evenPlayers[100];
int M, N, oddCount = 0, evenCount = 0;
printf("Enter the number of players: ");
scanf("%d", &N);
printf("Enter the player numbers: ");
for (int i = 0; i < N; i++) {
scanf("%d", &players[i]);
}
for (int i = 0; i < N; i++) {
if (players[i] % 2 == 0) {
evenPlayers[evenCount++] = players[i];
} else {
oddPlayers[oddCount++] = players[i];
}
}
for (int i = 0; i < evenCount - 1; i++) {
for (int j = 0; j < evenCount - i - 1; j++) {
if (evenPlayers[j] > evenPlayers[j + 1]) {
int temp = evenPlayers[j];
evenPlayers[j] = evenPlayers[j + 1];
evenPlayers[j + 1] = temp;
}
}
}
for (int i = 0; i < oddCount - 1; i++) {
for (int j = 0; j < oddCount - i - 1; j++) {
if (oddPlayers[j] > oddPlayers[j + 1]) {
int temp = oddPlayers[j];
oddPlayers[j] = oddPlayers[j + 1];
oddPlayers[j + 1] = temp;
}
}
}
printf("OddPlayers[] = ");
for (int i = 0; i < oddCount; i++) {
printf("%d ", oddPlayers[i]);
}
printf("\n");
printf("EvenPlayers[] = ");
for (int i = 0; i < evenCount; i++) {
printf("%d ", evenPlayers[i]);
}
printf("\n");
return 0;
}
OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy