0% found this document useful (0 votes)
28 views3 pages

Day 2 C

The document contains 12 C programming problems and their solutions involving basic concepts like input/output, if-else conditions, arithmetic operations. Each problem is solved with a short code snippet that takes input, applies logic using if-else statements and arithmetic operators, and prints the output. The problems cover finding absolute value, changing character case, checking even/odd number, finding max/min of 3 numbers, checking leap year, calculating telephone bill based on call slabs, and solving quadratic equations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

Day 2 C

The document contains 12 C programming problems and their solutions involving basic concepts like input/output, if-else conditions, arithmetic operations. Each problem is solved with a short code snippet that takes input, applies logic using if-else statements and arithmetic operators, and prints the output. The problems cover finding absolute value, changing character case, checking even/odd number, finding max/min of 3 numbers, checking leap year, calculating telephone bill based on call slabs, and solving quadratic equations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Day 2 h/w

6. Input anumber and find its absolute value.

#include <stdio.h>

int main()
{
int a;
printf("Enter the value of a ");
scanf("%d",&a);
if(a<0) {
a=(-1)*a;
}

printf("Absolute value of a is %d",a);


return 0;
}

7.Change the case of a character(lowercase to uppercase and vice versa)

#include<stdio.h>

int main()
{
char ch;
printf("Enter any character : ");
scanf("%ch", &ch);
if(ch>='A' && ch<='Z'){

ch=ch+32;
}
else if(ch>='a' && ch<='z'){
ch=ch-32;
}
printf("Convert case of character : %c",ch);
return 0;
}

8.Input a number and check it is even or odd.

#include <stdio.h>
int main()
{
int num;
printf("enter the number\n");
scanf("%d",&num);
if(num%2!=0)
{
printf("number is odd %d",num);
}
else
printf("number is even %d",num);
return 0;
}

9. Find the largest and smallest among three numbers supplied by user.
#include<stdio.h>
int main() {
int num1,num2,num3;
printf("enter the value of num1,num2,num3 respectively \n");
scanf("%d%d%d",&num1,&num2,&num3);
//search for greatest number
if(num1>num2 && num1>num3)
{

printf("num1 is greatest of the two numbers%d",num1);

}
else if(num2>num1 && num2>num3)
{
printf("num2 is the greatest of the two numbers%d",num2);
}
else
{
printf("num3 is greatest of the two numbers%d",num3);
}
//search for smallest numbers
if(num1<num2 && num1<num3)
{

printf("\n num1 is smallest of the two numbers%d \n ",num1);


}
else if(num2<num1 && num2<num3)
{
printf("\nnum2 is the smallest of two numbers%d \n",num2);
}
else
{
printf("\nnum3 is the smallest of the two numbers%d \n",num3);
return 0;
}
}

10.To check whether a year is leap year or not.

#include<stdio.h>
int main() {
int year;
printf("enter the value of year");
scanf("%d",&year);

if(year%4==0 &&year%400==0 || year%100!=0)


{
printf("the year is a leap year %d",year);
}
else
{
printf("the year is not a leap year %d",year);
return 0;
}
}

11.Compute the telephone bill for Mr. X as per the call rates given below:
Rental = 250
1
st 100 calls @Rs. 0.2
Next 100 calls @ Rs. 0.3
Remaining calls @ Rs. 0.5

#include<stdio.h>

int main()
{
int rental=250,calls,totalbill;
printf("enter the number of call made by Mr X\n");
scanf("%d",&calls);
if(calls<=100)
{
totalbill=rental+ (0.2*calls);
}
else if(calls>100 && calls<=200)
{
totalbill=rental+ (0.2*100)+(0.3*calls);
}
else if (calls>200)
{
totalbill=rental+(0.5*calls)+(0.3*200);

}
printf("your bill is%d \n",totalbill);
return 0;
}

12. Solve a given quadratic equation. [Without imaginary roots].

#include <stdio.h>
#include <math.h>

int main() {
double a, b, c, discriminant, root1, root2;

printf("Enter coefficients a, b, and c: ");


scanf("%lf %lf %lf", &a, &b, &c);
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Two distinct real roots: %lf and %lf\n", root1, root2);
} else if (discriminant == 0) {
root1 = -b / (2 * a);
printf("One real root: %lf\n", root1);
} else {
printf("No real roots exist.\n");
}

    return 0;
}

You might also like