1-10 Exp Ip Correct

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

1.

Writing simple programs using printf(), scanf()


Aim: Writing simple programs using printf(), scanf()
Program:
#include <stdio.h>
int main()
{
int a;
printf("Hello World");
printf("enter a number");
scanf("%d",&a);
printf("the entered number is:%d",a);
return 0;
}
Output:
Hello Worldenter a number23
the entered number is:23

2. Sum and average of 3 numbers


Aim: Write a program to calculate sum and average of 3 numbers.
Program:
#include <stdio.h>
int main()
{
int a,b,c,sum;
float avg;
printf("enter 3 numbers");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
avg=sum/3.0;
printf("sum of 3 numbers=%d",sum);
printf("average of 3 numbers=%f",avg);
return 0;
}
Output:
enter 3 numbers4 6 7
sum of 3 numbers=17average of 3 numbers=5.666667

3. Conversion of Fahrenheit to Celsius and vice versa


Aim: Write a C program for Conversion of Fahrenheit to Celsius and vice
versa.
Program:
#include<stdio.h>
int main()
{
float f,c;
printf("Enter Fahrenheit:");
scanf("%f",&f);
c=(f-32)/1.8;
printf("Celsius: %f",c);
printf("Enter Celsius:");
scanf("%f",&c);
f=(c*1.8)+32;
printf("fahrenheit: %f",f);
return 0;
}
Output:
Enter Fahrenheit:102.3
Celsius: 39.055557
Enter Celsius:38.3
fahrenheit: 100.940002

4. Write a C program to perform simple interest calculation.

# include <stdio.h>
int main()
{
//Simple interset program
int P, R, T;
float SI;
printf("Enter the principal: ");
scanf("%d", &P);
printf("Enter the rate: ");
scanf("%d", &R);
printf("Enter the time: ");
scanf("%d", &T);
SI = (P * R * T) / 100;
printf("The Simple interest is %f", SI);
return 0;
}
Output:
Enter the principal: 12000
Enter the rate: 10
Enter the time: 3
The Simple interest is 3600.000000

5. Finding the square root of a given


number
Aim: Write a C program to find the square root of a given number
Program:
#include <stdio.h>
#include <math.h>
int main(){
float num, root;

// Asking for Input


printf("Enter an integer: ");
scanf("%f", &num);

root = sqrt(num);
printf("The Square Root of %f is %f.", num, root);
return 0;
}
Output:
Enter an integer: 36
The Square Root of 36.000000 is 6.000000.
6. Finding compound interest
Aim: Write a C program to find compound interest
Program:
#include <stdio.h>
#include <math.h>

int main()
{
float p, r, t, ci;
printf("Enter the principle :");
scanf("%f", &p);
printf("Enter the rate :");
scanf("%f", &r);
printf("Enter the time :");
scanf("%f", &t);

ci = p * pow((1 + r / 100), t) - p;

printf("\nThe compound interest is %0.2f", ci);

return 0;
}
Output:
Enter the principle :12000
Enter the rate :12
Enter the time :3
The compound interest is 4859.14
7. Area of a triangle using heron’s
formulae
Aim: Write a C program to find Area of a
triangle using heron’s formulae
Program:
#include<stdio.h>
#include<math.h>

int main()
{
float a, b, c, s, area;
printf("\nEnter three sides of triangle\
n");
scanf("%f%f%f",&a,&b,&c);
s = (a+b+c)/2;
//Calculate area of triangle
area = sqrt(s*(s-a)*(s-b)*(s-c));

printf("\n Area of triangle: %f\n",area);

return 0;
}
Output:
Enter three sides of triangle
563
Area of triangle: 7.483315
8. Distance travelled by an object
Aim: Write a C program to find Distance travelled by an object.
Program:
#include<stdio.h>

int main() {
float u, a, d;
int t;

printf("\nEnter the value of a : ");


scanf("%f", & a);

printf("\nEnter the value of u : ");


scanf("%f", & u);

printf("\nEnter the value of t : ");


scanf("%d", & t);

d = (u * t) + (a * t * t) / 2;

printf("\n The Distance : %.2f", d);

return 0;
}

Output:
Enter the value of a : 3
Enter the value of u : 5
Enter the value of t : 2
The Distance : 16.00
9. Evaluate the following expressions.
a. A+B*C+(D*E) + F*G
b. A/B*C-B+A*D/3
c. A+++B---A
d. J= (i++) + (++i)

a. Write a C program to evaluate A+B*C+(D*E) + F*G


Program:
#include<stdio.h>
int main()
{
int A,B,C,D,E,F,G,RES;
printf("enter values of A,B,C,D,E,F,G");
scanf("%d%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F,&G);
RES=A+B*C+(D*E) + F*G;
printf("result=%d",RES);
return 0;
}
Output:
enter values of A,B,C,D,E,F,G2 3 4 2 5 6 6
result=60
b. Write a C program to evaluate A/B*C-B+A*D/3.
Program:
#include<stdio.h>
int main()
{
int A,B,C,D,RES;
printf("enter values of A,B,C,D");
scanf("%d%d%d",&A,&B,&C,&D);
RES=A/B*C-B+A*D/3;
printf("result=%d",RES);
return 0;
}
Output:
enter values of A,B,C,D2 4 3 5
result=-1
c. Write a C program to evaluate A+++B---A
Program:
#include<stdio.h>
int main()
{
int A,B,RES;
printf("enter values of A,B");
scanf("%d%d",&A,&B);
RES=A+++B---A;
printf("result=%d",RES);
return 0;
}
Output:
enter values of A,B3 4
result=3

d. Write a C program to evaluate J= (i++) + (++i)


Program:
#include<stdio.h>
int main()
{
int i,j;
printf("enter value i");
scanf("%d",&i);
j=(i++) + (++i);
printf("result=%d",j);
return 0;
}
Output:
enter value i 4
result=10
10. Find the maximum of three numbers
using conditional operator
Aim: Write a C program to Find the
maximum of three numbers using
conditional operator.
Program:
# include <stdio.h>

void main()
{
int a, b, c, big ;

printf("Enter three numbers : ") ;

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

big = a > b ? (a > c ? a : c) : (b > c ? b :


c) ;

printf("\nThe biggest number is : %d",


big) ;
}
Output:
Enter three numbers : 3 5 8
The biggest number is : 8

You might also like