[go: up one dir, main page]

0% found this document useful (0 votes)
47 views7 pages

Write A C Program To Find The Simple Interest: SI (P T R) /100

The document contains 15 code snippets that demonstrate various calculations and data processing tasks in C programming. The snippets include programs to: 1) Calculate the area and perimeter of a triangle by reading input values and using formulas. 2) Calculate simple interest by reading input values and using the simple interest formula. 3) Convert between Fahrenheit and Celsius by reading a temperature and applying the conversion formula.

Uploaded by

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

Write A C Program To Find The Simple Interest: SI (P T R) /100

The document contains 15 code snippets that demonstrate various calculations and data processing tasks in C programming. The snippets include programs to: 1) Calculate the area and perimeter of a triangle by reading input values and using formulas. 2) Calculate simple interest by reading input values and using the simple interest formula. 3) Convert between Fahrenheit and Celsius by reading a temperature and applying the conversion formula.

Uploaded by

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

1. Write a C program to find the area and perimeter of triangle.

Read the input from


user.
void main()
{
//declaration the variables
float a,b,c,s area, peri;

//read the three side of a triangle from user (keyboard)


printf("Enter the three side of a triangle\n");
scanf("%f%f%f",&a,&b,&c);

//calculate area and perimeter of triangle


s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
peri=a+b+c;

//display the result


printf("Area of triangle is %f\n",area);
printf("Perimeter of triangle is %f\n",peri);
}

2. Write a C program to find the simple interest: SI= (P*T*R)/100.


#include <stdio.h>
void main()
{
//declaration the variables
float p, t, r, si;

//read the principle, time and rate from user (keyboard)


printf("Enter principle amount\n");
scanf("%f",&p); //To read input from keyboard use
printf("Enter Time\n"); printf(“enter the value for p,t,r\n”);
scanf("%f",&t); scanf(“%f%f%f”,&p,&t,&r);
printf("Enter Rate\n");
scanf("%f",&r);

//calculate simple interest


si=(p*t*r)/100;

//display the result


printf("Simple Interest: %f\n",si);
}

3. Write a C program to Convert Fahrenheit to Celsius: C=(f-32)*0.555


#include <stdio.h>
void main()
{
//declaration the variables
float C, F;
//read the priciple, time and rate from user (keyboard)
printf("Enter temperature in Fahrenheit\n");
scanf("%f",&F);

//Convert Fahrenheit to Celsius


C=(F-32)*0.555;

//display the result


printf("%f Fahrenheit = %f Celsius\n",F,C);
}

4. Write a C program to Exchange(Swap) the two numbers


#include <stdio.h>
void main()
{
//declaration the variables
int a, b, temp;
//read two numbers from user (keyboard)
printf("Enter the value of a and b\n");
scanf("%d%d",&a,&b);

printf("Before exchange\n");
printf("a=%d\t b=%d\n",a,b);

//exchange two numbers using temporary variable


temp=a; //assign value of a to temp variable
a=b; //assign value of b to a variable
b=temp; //assign value of temp to b variable
//display the result
printf("After exchange\n");
printf("a=%d\t b=%d\n",a,b);;
}

5. Write a C program to find the ASCII value of a character


In C programming, a character variable holds ASCII value (an integer number between 0 and
127) rather than that character itself. This integer value is the ASCII code of the character.

#include <stdio.h>
void main()
{
char ch;
printf(“enter the character\n”);
ch=getchar(); // or scanf("%c",&ch);
printf(“ASCII value of %c is %d\n”,ch,ch);
}

6. Write a C program to Program to Compute Quotient and Remainder (May 2019)


#include <stdio.h>
void main()
{
int a, b, quotient, remainder;
printf("Enter dividend: ");
scanf("%d", &a);
printf("Enter divisor: ");
scanf("%d", &b);

// Computes quotient
quotient = a / b;

// Computes remainder
remainder = a % b;

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


printf("Remainder = %d", remainder);
}

7. Write a C program to find the Size of Variables


#include<stdio.h>
void main()
{
int a;
float b;
double c;
char d;

// sizeof evaluates the size of a variable


printf("Size of int: %d bytes\n", sizeof(a));
printf("Size of float: %d bytes\n", sizeof(b));
printf("Size of double: %d bytes\n", sizeof(c));
printf("Size of char: %d byte\n", sizeof(d));
}

8. Write a C program to find the product of two floating-point numbers entered by the
user is calculated and printed on the screen.
#include <stdio.h>
void main()
{
float a, b, product;
printf("Enter two numbers: ");
scanf("%f %f", &a, &b);

// Calculating product
product = a * b;

// Result up to 2 decimal point is displayed using %.2lf


printf("Product = %.2f", product);
}

Output:
Enter two numbers: 2.4
1.12
Product = 2.69

9. C Program to accept a three digit number and find the sum of all the digits of
numbers using only arithmetic operators. (SEE Dec2018)

# include <stdio.h>
void main( )
{
int a,b,c,n,sum;
printf (“Enter a Three Digit Number:“);
scanf (“%3d”,&n);

a=n/100;
b=((n%100)/10);
c=n%10;
sum=a+b+c;

printf(“ Sum of Individual Digits of Given Numbers


is %d”, sum);
}

10. Write a program to accept two numbers of two digits each and find the sum and
difference of unit place digits and tens places digits separately of the numbers.
#include <stdio.h>
void main()
{
int n1, n2, sum1,sum2,a1,a2,b1,b2;
printf("Enter a two 2-Digit Numbers:");
scanf("%2d %2d",&n1,&n2);

/* a1,a2 is unit's place digit


b1,b2 is ten's place digit
*/
a1=n1/10;
b1=n1%10;

a2=n2/10;
b2=n2%10;

/* sum1: sum of unit's place digits of two numbers


sum2: sum of ten's place digits of two numbers
*/
sum1=a1+a2;
sum2=b1+b2;
printf("Sum of unit's place: %d\n",sum1);
printf("Sum of ten's place: %d",sum2);
}

11.Write a C program to find the hypotenuse of triangle. (or) Write a C program to


implement Pythagoras theorem.

#include <stdio.h>
#include <math.h>
void main()
{
float c,a,b;
printf("Enter the two sides of triangle\n");
scanf("%f%f",&a,&b);
c=sqrt((a*a)+(b*b));
printf("Hypotenuse of trinagle is %.2f",c);
}

12.Write a C program to convert days to months.

#include <stdio.h>
void main()
{
int days, m,d;
printf("Enter the number of days[min 30 days]\n");
scanf("%d",&days);
m=days/30;
d=days%30;
printf("%d month %d days\n",m,d);
}
13.Write a C program to convert a negative number to a positive number.

#include <stdio.h>
void main()
{
int n,p;
printf("Enter the negative number\n");
scanf("%d",&n);
p=n*-1; //multiply negative number by -1
printf("Positive number=%d\n",p);
}

14.Write a C program to find square root of a number.

#include <stdio.h>
#include <math.h>
void main()
{
float n,res;
printf("Enter the number\n");
scanf("%f",&n);
res=sqrt(n);
printf("Square root of %.2f is %.2f\n",n,res);
}

15.Write a C program to print last digit of a number.

#include <stdio.h>
void main( )
{
int last_digit, n,sum;
printf (“Enter a Number:“);
scanf (“%d”,&n);

last_digit=n%10;

printf(“ Last Digit of Given Numbers is %d”, last_digit);


}

You might also like