0% found this document useful (0 votes)
31 views

Assignment 5

The document contains 8 programs written in C programming language to solve various problems. Program 1 displays the two rightmost digits of a floating point number. Program 2 checks if one integer is a multiple of another without using if statements. Program 3 assigns the result of integer division to a float variable. Program 4 converts characters between uppercase and lowercase. Programs 5-8 demonstrate various mathematical operations and checks on integers like multiplication, division, checking properties of triangles.

Uploaded by

HARISH KUMAR
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)
31 views

Assignment 5

The document contains 8 programs written in C programming language to solve various problems. Program 1 displays the two rightmost digits of a floating point number. Program 2 checks if one integer is a multiple of another without using if statements. Program 3 assigns the result of integer division to a float variable. Program 4 converts characters between uppercase and lowercase. Programs 5-8 demonstrate various mathematical operations and checks on integers like multiplication, division, checking properties of triangles.

Uploaded by

HARISH KUMAR
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/ 16

Program 1: Write a program that reads a floating-point number

and then displays the two right–most digits of the integral part of
the number. (Example: Number is 172.35 then output is 72).

Program

#include <stdio.h>

int main()

float a;

int p,c;

printf("enter the number a=");

scanf("%f",&a);

p=a;

c=p%100;

printf("%d",c);

return 0;

}
OUTPUT

Program 2 : Write a program to read two integer values m and n


and to decide and print whether m is multiple of n without using if
statement.

Program

#include<stdio.h>

int main()

int m,n;

printf("Enter m= ");

scanf("%d",&m);

printf("Enter n= ");
scanf("%d",&n);

(m%n==0)?printf("m is a multiple of n"):printf("m is not a multiple


of n");

return 0;

OUTPUT

Program 3 : Write a program that reads two integer values m and


n. Assign the value of m/n to a floating point variable z in such a
way that the accurate value of division will be assigned to z.
For Example: m=10 , n=4 and z will be computed as 2.5.

Program

#include <stdio.h>

int main()
{

int x=5,y=2;

float z;

z=(float)x/y;

printf("%f",z);

return 0;

OUTPUT

Program 4: Write a C program to convert a given character from


uppercase to lowercase and vice versa. (Hint. Difference between
lowercase and corresponding uppercase characters is 32 in
ASCII code. XOR operation is used.)

Program
#include <stdio.h>

#include<ctype.h>

int main()

printf("Enter a character \n");

char x=getchar();

isalpha(x)?(islower(x)?putchar(toupper(x)):putchar(tolower(x))):pri
ntf("non alphabet");

return 0;

OUTPUT
Program 5: Print multiplication (3 digit numbers ) and division
operation (numerator 4 digits and denominator 2 digits) using
traditional methods. You have to print all steps of operation.

Program

#include <stdio.h>

int main()

int n1,n2,n3,a,b,c;

printf("n1=");

scanf("%d",&n1);

printf("n2=");

scanf("%d",&n2);

n3=n1*n2;

a=n2/100;

b=(n2/10)%10;

c=n2%10;

printf(" %d\n",n1);

printf(" *%d\n",n2);

printf("______\n");

printf(" %d\n",n1*c);

printf(" %d*\n",n1*b);
printf("%d**\n",n1*a);

printf("______\n");

printf("%d\n",n3);

printf("______\n");

return 0;

OUTPUT
Program 5: Print multiplication (3 digit numbers ) and division
operation (numerator 4 digits and denominator 2 digits) using
traditional methods. You have to print all steps of operation.

#include <stdio.h>

int main()

int n1,n2,n3,p,a,b,c,d,e,f;

scanf("%d%d",&n1,&n2);

d=(n1/100);

e=(n1/10)%10;

f=n1%10;

n3=n1/n2;

a=(n3/100);
b=(n3/10)%10;

c=n3%10;

printf(" ____\n");

printf("%d/%d |%d\n",n2,n1,n3);

printf(" -%d\n",n2*a);

printf(" _____\n");

printf(" %d%d\n",d-n2*a,e);

printf(" %d\n",n2*b);

printf(" _____\n");

printf(" %d%d\n",(d-n2*a)*10+e-(n2*b),f);

printf(" %d\n",n2*c);

printf(" _____\n");

printf(" %d\n",n1%n3);

printf(" _____\n");

return 0;

}
OUTPUT
Program 6: Area of a triangle is given by the formula

A=sqrt(S(S-a)(S-b)(S-c)) Where a, b and c are sides of the triangle and 2S=a+b+c.


Write a program to compute the area of the triangle given the values of a, b and c.

Program

#include <stdio.h>

#include <math.h>

int main()

float a,b,c,s,d,Area;

scanf("%f%f%f",&a,&b,&c);

printf("a=%fb=%fc=%f\n",a,b,c);

s=(a+b+c)*1/2;

d=s*(s-a)*(s-b)*(s-c);
Area=pow(d,0.5);

printf("The area of triangle is %f",Area);

return 0;

OUTPUT

Program 7: Write a program to check whether a given number is greater than 100 and
less than 200 that are divisible by 7 and if yes, then print the sum of digits of
the number

Program.

#include <stdio.h>

int main()
{

int n,a,b,c;

scanf("%d",&n);

printf("n=%d\n",n);

a=(n/100);

b=(n/10)%10;

c=n%10;

if(n>=100&&n<=200&&n%7==0)

printf("the sum of digit =%d",a+b+c);

else

printf("Not");

return 0;

}
OUTPUT

Program 8: If the three sides of a triangle are entered through the keyboard, write a program to check
whether the triangle is isosceles, equilateral, or right angled triangle.

Program

#include <stdio.h>

int main()
{

int a,b,c;

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

printf("a=%d b=%d c=%d\n",a,b,c);

if(a==b&&b==c)

printf("Equilateral triangle");

else if(a==b&&c!=b||c==b&&a!=b||a==c&&a!=b)

printf("isosceles");

else if(a*a+b*b==c*c||c*c+b*b==a*a||a*a+c*c==b*b)

printf("right angle triangle");

else

printf("triangle");

}
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