0% found this document useful (0 votes)
45 views5 pages

Assignment No 2

The document contains 11 questions related to C programming. Question 1 prints the name, date of birth, and age of a person. Question 2 defines functions to calculate the sum, subtraction, multiplication, and division of input numbers. Question 3 defines functions to calculate the area of a circle and triangle. The remaining questions cover a variety of C programming concepts like simple interest calculation, swapping values, conditional statements, data types, and increment/decrement operators.

Uploaded by

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

Assignment No 2

The document contains 11 questions related to C programming. Question 1 prints the name, date of birth, and age of a person. Question 2 defines functions to calculate the sum, subtraction, multiplication, and division of input numbers. Question 3 defines functions to calculate the area of a circle and triangle. The remaining questions cover a variety of C programming concepts like simple interest calculation, swapping values, conditional statements, data types, and increment/decrement operators.

Uploaded by

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

ASSIGNMENT NO 2

Q.1.

#include <stdio.h>
int main()
{
printf("Name : Chandrakant Kamble\n");
printf("DOB :8/11/2003\n");
printf("age : 18");
}

Q.2.

#include <stdio.h>

float sum1()
{
float a, b, c, sum;
printf("Enter a number : ");
scanf("%f", &a);
printf("Enter a number : ");
scanf("%f", &b);
printf("Enter a number : ");
scanf("%f", &c);
sum = a + b + c;
return sum;
}

float sub()
{
float a, b, subs;
printf("Enter a number : ");
scanf("%f", &a);
printf("Enter a number : ");
scanf("%f", &b);
subs = a - b;
return subs;
}

float mult()
{
float a, b, c, mul;
printf("Enter a number : ");
scanf("%f", &a);
printf("Enter a number : ");
scanf("%f", &b);
printf("Enter a number : ");
scanf("%f", &c);
mul = a * b * c;
return mul;
}

float div()
{
float a, b, divi;
printf("Enter a number : ");
scanf("%f", &a);
printf("Enter a number : ");
scanf("%f", &b);
divi = a / b;
return divi;
}

int main()
{

printf("The sum is %.2f\n", sum1());


printf("The subtraction is %.2f\n", sub());
printf("The multiplication is %.2f\n", mult());
printf("The division is %.2f\n", div());
}

Q.3.

#include <stdio.h>
float arofcir()
{
float r, areac;
printf("Enter the radius of circle : ");
scanf("%f", &r);
areac = 3.142 * r * r;
return areac;
}

float aroftri()
{
float b, h, area;
printf("Enter the base of triangle : ");
scanf("%f", &b);
printf("Enter the height of triangle : ");
scanf("%f", &h);
area = 0.5 * b * h;
return area;
}

int main()
{
printf("The area of cirlce is %.2f\n", arofcir());
printf("\n");
printf("The area of triangle is %.2f\n", aroftri());
}

Q.4.

#include <stdio.h>
#include <string.h>
int main()
{
float principle, time, rate, SI;

printf("Enter principle (amount): ");


scanf("%f", &principle);

printf("Enter time: ");


scanf("%f", &time);

printf("Enter rate: ");


scanf("%f", &rate);

SI = (principle * time * rate) / 100;

printf("Simple Interest = %f", SI);

return 0;
}

Q.5.

#include <stdio.h>
int main()
{
int litre, bill;
printf("Enter the number of litres of milk purchased in this month : ");
scanf("%d", &litre);
printf("The rate of milk per litre is 60rs.");
bill = litre * 60;
printf("\nThe bill of this month is %d", bill);
}

Q.6.

#include <stdio.h>
int main()
{
float sal, da, ta, ts;
printf("Enter your salary : ");
scanf("%f", &sal);
da = 0.8 * sal;
ta = 0.2 * sal;
ts = da + ta + sal;
printf("\nYour total salary is %.2f", ts);

Q.7.

#include <stdio.h>
int main()
{
int c, d;
int temp;
printf("Enter first number : ");
scanf("%d", &c);
printf("The value of c before swaping is %d\n", c);
printf("Enter second number : ");
scanf("%d", &d);
printf("The value of d before swaping is %d\n", d);
temp = c;
c = d;
d = temp;
printf("The value of c after swapping is %d", c);
printf("\nThe value of d after swapping is %d", d);
}

Q.8.

#include <stdio.h>
int main()
{
int x, y;
printf("Enter the numbers : ");
scanf("%d %d", &x, &y);
printf("%d", (x + y) / (x - y));
printf(" %d", (x + y) * (x - y));
}

Q.9.

#include<stdio.h>
int main()
{
int x = 20 , y = 10;
int ans;

ans = (x > y) ? x : y;
printf("%d",ans);

Q.10.

#include<stdio.h>
int main()
{
int a =10;
char c = 'c';
float b = 10.6;
printf("%d\n",sizeof(a));
printf("%d\n",sizeof(c));
printf("%d",sizeof(b));
}

Q.11.

#include <stdio.h>
int main()
{
int m;
int n , c, d ;
m = 10;
n = 12;
++m;
n++;
c=m+1;
d = n + 2;
printf("The value of c is %d\n",c);
printf("The value of d is %d\n",d);
printf("The value of m for preincrement is %d\n",m);
printf("The value of m for postincrement is %d",n);

You might also like