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

Moumitama'amassignment 3

The document contains C code snippets for performing various mathematical operations on numbers involving manipulating digits before and after the decimal point. The code snippets take a floating point number as input, perform integer operations to extract individual digits or groups of digits, perform calculations on those digits, and output a new number by recombining the digits or results of calculations. The operations include extracting, summing, doubling, exchanging, and inserting digits as well as combinations of these operations.

Uploaded by

AYAN PANJA
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

Moumitama'amassignment 3

The document contains C code snippets for performing various mathematical operations on numbers involving manipulating digits before and after the decimal point. The code snippets take a floating point number as input, perform integer operations to extract individual digits or groups of digits, perform calculations on those digits, and output a new number by recombining the digits or results of calculations. The operations include extracting, summing, doubling, exchanging, and inserting digits as well as combinations of these operations.

Uploaded by

AYAN PANJA
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/ 6

Second digit of fractional part

#include<stdio.h>
#include<math.h>
int main()
{
int a,c,d;
float p,q,r;
printf("enter the number : ");
scanf("%f", &p);
a=p;
q=p-a;
r=q*100;
c=r;
d=c%10;
printf("the answer is : %d", d);

return 0;
}

Delete digit before decimal

#include<stdio.h>
#include<math.h>
int main ()
{
int a,b,c,d;
float p,q,r;
printf("enter the number : ");
scanf("%f", &p);
a=p;
q=p-a;
b=a%10;
c=a-b;
d=c/10;
r=d+q;
printf("the answer is : %f",r);
return 0;
}
Delete first digit after decimal
#include<stdio.h>
#include<math.h>
int main ()
{
int a,b;
float p,q,r,s,t;
printf("enter the number : ");
scanf("%f", &p);
a=p;
q=p-a;
r=q*10;
b=r;
s=r-b;
t=a+s;
printf("the answer is : %f" , t);

return 0;
}

Delete 2nd digit after decimal


#include<stdio.h>
#include<math.h>
int main ()
{
int a,b,c;
float p,q,r,s,t,v,w,u,x;
printf("enter the number : ");
scanf("%f", &p);
a=p;
q=p-a;
r=10*q;
b=r;
s=r-b;
t=10*s;
c=t;
v=t-c;
w=0.1*v;
u=0.1*b;
x=a+w+u;
printf("the answer is : %f",x);

return 0;
}
Insert 1 as digit before decimal

#include<stdio.h>
#include<math.h>
int main ()
{
int a,b,c;
float p,q,r;
printf("enter the number : ");
scanf("%f", &p);
a=p;
q=p-a;
b=a*10;
c=b+1;
r=c+q;
printf("the answer is : %f" , r);

return 0;
}

Double the digit after decimal

#include<stdio.h>
#include<math.h>
int main ()
{
int a,b;
float p,q,r,u,v;
printf("enter the number : ");
scanf("%f", &p);
a=p;
q=p-a;
r=10*q;
b=r;
printf("ans %d\n",b);
u=0.1*b;
v=p+u;
printf("the answer is : %f" ,v);

return 0;
}
Exchange the two digits before decimal
#include<stdio.h>
#include<math.h>
int main ()
{
int a,c,d,e,f,g,h;
float p,q,r;

printf("enter the number : ");


scanf("%f", &p);
a=p;
q=p-a;
c=a%10;
d=(a-c)/10;
e=d%10;
f=a%100;
g=a-f;
h=(10*c)+e;
r=g+h+q;

printf("the answer is : %f" , r);

return 0;
}

Sum of digits around decimal


#include<stdio.h>
#include<math.h>
int main ()
{
int a,b,c,d;
float p,q,r;
printf("enter the number : ");
scanf("%f", &p);
a=p;
q=p-a;
b=a%10;
r=10*q;
c=r;
d=b+c;
printf("the answer is : %d" , d);
return 0;
}
Exchange digits around decimal
#include<stdio.h>
#include<math.h>
int main ()
{
int a,b,c,d,e;
float p,q,r,s,t,u,v;
printf("enter the number : ");
scanf("%f", &p);
a=p;
b=a%10;
c=a-b;
printf("ans is %d\n",c);
q=p-a;
r=q*10;
d=r;
e=c+d;
s=0.1*b;
t=r-d;
u=0.01*t;
v=e+s+u;
printf("the answer is : %f" , v);

return 0;
}

Sum of first two digits after decimal


#include<stdio.h>
#include<math.h>
int main ()
{
int a,b,c,d,e;
float p,q,r;
printf("enter the number : ");
scanf("%f", &p);
a=p;
q=p-a;
r=100*q;
b=r;
c=b%10;
d=(b-c)/10;
e=c+d;
printf("the answer is : %d" , e);
return 0;
}

You might also like