Vous êtes sur la page 1sur 6

This piece of trash was written

by Muhtasim Al Farabi -_-


Best of luck for tomorrow :p

Addition: Area: Triangle:


#include <stdio.h> For Height and Base:
#include <conio.h> main()
main() {
{ int h,b;
int a,b,sum=0; float area;
printf("Please enter your numbers:"); printf("Please enter the height and the
base:");
scanf("%d %d",&a,&b);
scanf("%d %d",&h,&b);
sum=a+b;
area=0.5*h*b;
printf("Sum is %d",sum);
printf("Area is %f",area);
getch();
getch();
}
}
Average:
For 3 arms:
main()
#include <math.h>
{
main()
float a,b,avg;
{
printf("Please enter your numbers:");
int a,b,c;
scanf("%f %f",&a,&b);
float s,area;
avg=(a+b)/2;
printf("Enter the value of three arms:");
printf("Average is %.4f",avg);
scanf("%d %d %d",&a,&b,&c);
getch();
s=(a+b+c)/2;
}
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area is %.4f",area);

getch();

Circle: Fahrenheit to Celsius:

main()
main()
{
{
float cel,far;
int r;
printf("Enter the value in fahrenheit:");
float area;
scanf("%f",&far);
printf("Please enter the radius:");
cel=5*(far-32)/9;
scanf("%d",&r);
printf("Temperature in celsius is %f",cel);
area=3.1416*r*r;
getch();
printf("Area is %f",area);
}
getch();

} Even Odd:
Temperature: main()

{
Celsius to Fahrenheit :
int num;
main()
printf("Enter the number:");
{
scanf("%d",&num);
float cel,far;
if(num%2==0){
printf("Enter the value in celcius:");
printf("%d is even",num);
scanf("%f",&cel);
}
far=(cel*9/5)+32;
else{
printf("Temperature in farenheit is
%f",far); printf("%d is odd",num);
getch(); }
} getch();
} printf("%d is the largest number",b);

else

printf("%d is the largest number",c);

Positive negative:
getch();
main()
}
{

int num; Smallest number:


printf("Enter the number:"); if(a<b && a<c)

scanf("%d",&num); printf("%d is the smallest


number",a);
if(num>=0){
else if(b<c && b<a)
printf("%d is positive",num);
printf("%d is the smallest
} number",b);
else{ else
printf("%d is negative",num); printf("%d is the smallest number",c);
}
Largest and Smallest:
getch();
if(a>b && a>c)
}
printf("%d is the largest number\n",a);
Largest number: else if(a<b && a<c)
main() printf("%d is the smallest number\n",a);
{ if(b>c && b>a)
int a,b,c; printf("%d is the largest number\n",b);
printf("Enter the 3 numbers:"); else if(b<c && b<a)
scanf("%d %d %d",&a,&b,&c); printf("%d is the smallest number\n",b);
if(a>b && a>c) if(c>a && c>b)
printf("%d is the largest number",a); printf("%d is the largest number\n",c);
else if(b>c && b>a) else if(c<a && c<b)
printf("%d is the smallest number\n",c);

Leap Year:
int lp;
Prime number:
printf("Enter the year:"); (In the book this program is written with
while loop, I’ve used for loop)
scanf("%d",&lp);
int i,n;
if(lp%400==0)
printf("Enter a number:");
printf("%d is a leap year",lp);
scanf("%d",&n);
else if(lp%4==0 && lp%100!=0)
for(i=2;i<=n-1;i++){
printf("%d is a leap year",lp);
if(n%i==0){
else
printf("%d is not a prime number.",n);
printf("%d is not a leap year",lp);
break;
getch();
}
Factorial: }
int n,i,factorial=1; if(n==i)
printf("Enter the number:"); printf("%d is a prime number.",n);
scanf("%d",&n); getch();
for(i=1;i<=n;i++){ }
factorial=factorial*i;

printf("%d! is %d",n,factorial);

getch();
printf("L.C.M is %d",lcm);

getch();

GCD: Series:
(the code written in the book is wrong -_- ) 1+2+3+….+n:

int n1, n2, i, gcd; int n,i,s=0;

printf("Enter two integers: "); printf("Enter the number: ");

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

for(i=1; i <= n1 && i <= n2; i++) for(i=1;i<=n; i++)

{ s=s+i;

if(n1%i==0 && n2%i==0) printf("The sum is %d",s);

gcd = i; getch();

} 2+4+6+…+n:

printf("G.C.D is %d",gcd); for(i=2;i<=n; i=i+2)

getch(); s=s+i;

LCM: 1+3+5+…+n:

for(i=1;i<=n; i=i+2)
int n1, n2, i, gcd,lcm;
s=s+i;
printf("Enter two integers: ");
-1-2-3-…-n:
scanf("%d %d", &n1, &n2);
for(i=-1; i>=n; i--)
for(i=1; i <= n1 && i <= n2; i++)
s=s+i;
{
1*2*3*..*n:
if(n1%i==0 && n2%i==0)
int n,i,s=1;
gcd = i;
printf("Enter the number: ");
}
scanf("%d",&n);
lcm=(n1*n2)/gcd;
for(i=1;i<=n;i++)

s=s*i;

printf("The sum is %d",s);

getch();

1+1/2+1/3+…+1/n:

float i,n,s=0;

printf("Enter the number: ");

scanf("%f",&n);

for(i=1;i<=n;i++)

s=s+(1/i);

printf("The sum is %f",s);

getch();

1+1/22+1/32+…+1/n2:

for(i=1;i<=n;i++)

s=s+(1/(i*i));

23+21+19+….n:

for(i=23;i>=n;i=i-2)

s=s+i;

1*2+2*3+3*4+…+n*(n+1):

for(i=1;i<=n;i++)

s=s+i*(i+1);

12+22+32+…+n2:

for(i=1;i<=n;i++)

s=s+(i*i);

Vous aimerez peut-être aussi