Professional Documents
Culture Documents
/*
Name: Joy Chandra Mukherjee
Roll No: T160016
Assignment No: I
Laboratory: Programming and Data Structure
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void Q1();
void Q2();
void Q3();
void Q4();
void Q5();
void Q6();
void Q7();
void Q8();
void Q9();
void Q10();
void Q11();
void Q12();
void Q13();
void Q14();
void Q15();
void Q16();
void Q17();
int main()
{
int choice;
while(1) {
printf("Enter Question Number: ");
scanf("%d", &choice);
switch(choice) {
1
case 1: Q1(); break;
case 2: Q2(); break;
case 3: Q3(); break;
case 4: Q4(); break;
case 5: Q5(); break;
case 6: Q6(); break;
case 7: Q7(); break;
case 8: Q8(); break;
case 9: Q9(); break;
case 10: Q10(); break;
case 11: Q11(); break;
case 12: Q12(); break;
case 13: Q13(); break;
case 14: Q14(); break;
case 15: Q15(); break;
case 16: Q16(); break;
case 17: Q17(); break;
default: return 0;
}
}
return 0;
}
void Q1()
{
int year, yr;
do {
printf("Enter a year: ");
scanf("%d", &year);
} while(year < 1000 || year > 10000);
yr = year;
if(year % 100 == 0) {
year = year/100;
}
if(year % 4 == 0)
printf("%d is a Leap Year", yr);
else
printf("%d is not a Leap Year", yr);
2
printf("\n\n");
}
void Q2()
{
int amount, hundred, fifty, ten;
printf("Enter amount: ");
scanf("%d", &amount);
hundred = amount / 100;
amount = amount % 100;
fifty = amount / 50;
amount = amount % 50;
ten = amount / 10;
printf("Number of 100 notes = %d\n Number of 50 notes = %d\n
void Q3()
{
double x1, y1, x2, y2, x3, y3;
double area, a, b, c, perimeter;
if((y2-y1)*(x3-x2) == (y3-y2)*(x2-x1))
printf("The given points are collinear\n");
else
{
a = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
b = sqrt((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2));
c = sqrt((x1-x3)*(x1-x3) + (y1-y3)*(y1-y2));
perimeter = a + b + c;
printf("Perimeter of the triangle = %lf\n", perimeter);
area = (x1 * (y2-y3) + x2 * (y3-y1) + x3 * (y1-y2)) / 2.0;
if(area < 0)
area = -area;
3
printf("Area of the triangle = %lf\n", area);
}
}
void Q4()
{
char x;
printf("\nEnter a character : ");
scanf(" %c",&x);
void Q5()
{
int yr, i, sum = 0, rem = 0, x;
printf("Enter the year:");
scanf("%d", &yr);
switch(rem) {
case 0:printf("Monday");break;
case 1:printf("Tuesday");break;
case 2:printf("Wednesday");break;
4
case 3:printf("Thursday");break;
case 4:printf("Friday");break;
case 5:printf("Saturday");break;
case 6:printf("Sunday");break;
}
printf("\n");
}
void Q6()
{
int n, num, sum = 0;
do{
printf("Enter a non-zero positive integer: ");
scanf("%d", &n);
}while(n <= 0);
void Q7()
{
int n, num, sum = 0;
do{
printf("Enter a non-zero positive integer: ");
scanf("%d", &n);
}while(n <= 0);
void Q8()
{
int remainder;
int binary, i, n ,num;
5
printf("Enter a number: ");
scanf("%d", &n);
void Q9()
{
int n, i, j, k;
printf("Enter a number: ");
scanf("%d", &n);
void Q10()
{
int i, n, rem, curr, sum;
6
printf("Armstrong Number Program\n");
do {
printf("Enter a non-zero positive integer: ");
scanf("%d", &n);
}while(n <= 0 || n >= 1001);
void Q11()
{
int i, positive = 0, negative = 0, zero = 0, ch = y;
while (ch == y || ch == Y)
{
printf("Enter a number\n");
scanf("%d", &i);
if (i > 0) positive++;
if (i < 0) negative++;
if (i == 0) zero++;
printf("Press y to enter, n to exit\n");
scanf(" %c", &ch);
if (ch == n || ch == N)
break;
}
printf("Positive Numbers = %d\n", positive);
printf("Negative Numbers = %d\n", negative);
printf("Zeroes = %d\n", zero);
}
void Q12()
{
printf("Sin(x) Program\n");
7
int i = 1;
double y, x, sum, term;
printf("Enter value of angle: ");
scanf("%lf", &x);
y = x;
x = (x * 22) / (7*180);
void Q13()
{
int i, j, n;
do {
printf("Enter a non-zero positive integer: ");
scanf("%d", &n);
}while(n <= 0);
8
printf("\n");
}
void Q14()
{
int i, j;
char ch;
printf("ABCD Program\n");
do {
printf("Enter a upper-case alphabet [A - Z]: ");
scanf(" %c", &ch);
}while(ch < A || ch > Z);
printf("\n");
}
void Q15()
{
int i, n, curr, prev, next;
do {
printf("Enter a non-zero positive integer: ");
scanf("%d", &n);
9
}while(n <= 0);
}
}
printf("\n");
}
void Q16()
{
int i, j, k, n, div, sum;
long long int nCr;
printf("Pascals Triangle Program\n");
do {
printf("Enter a non-zero positive integer: ");
scanf("%d", &n);
}while(n <= 0);
div = n/2;
nCr = 1;
for(k = n; k >= div+1; k--)
nCr = nCr * k;
for(k = div; k >= 1; k--)
nCr = nCr / k;
sum = 0;
while(div != 0) {
div = div/2;
sum++;
}
10
for(k = 1; k <= sum; k++)
printf(" ");
for(j = 0; j <= i; j++) {
nCr = 1;
if(j <= i-j) {
for(k = i; k >= i-j+1; k--)
nCr = nCr * k;
for(k = j; k >= 1; k--)
nCr = nCr / k;
printf("%-*ld", sum*2, nCr);
}
else {
for(k = i; k >= j+1; k--)
nCr = nCr * k;
for(k = i-j; k >= 1; k--)
nCr = nCr / k;
printf("%-*Ld", sum*2, nCr);
}
}
printf("\n");
}
printf("\n");
}
void Q17()
{
int i, j, n;
do {
printf("Enter a non-zero positive integer: ");
scanf("%d", &n);
}while(n <= 0);
11
else
for(j = n-i+1; j >= 1; j--)
printf("%d ", j);
printf("\n");
}
printf("\n");
}
12