Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
46 views

Programming Assignment

The document is an assignment submission by a student named Animesh Mandal for their Programming Fundamentals Practical course. It includes the student's code for 8 programming questions to convert between decimal, binary, and other number systems, check number properties, and design a basic calculator using switch statements. The student provides the required code and output for each question asked in the assignment.

Uploaded by

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

Programming Assignment

The document is an assignment submission by a student named Animesh Mandal for their Programming Fundamentals Practical course. It includes the student's code for 8 programming questions to convert between decimal, binary, and other number systems, check number properties, and design a basic calculator using switch statements. The student provides the required code and output for each question asked in the assignment.

Uploaded by

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

Maulana Abul Kalam Azad

University Of Technology
MAKAUT WB

Name: Animesh Mandal


Department Of It
Course: BCA (1st Year, 1st Sem)
Subject: Programming Fundamentals Practical
Assignment: Practical Assignment for CET I students: Deadline
02.12.2022
Registration Number: 223001010640
Roll no: 30001222039
Date of Assignment Given: 30.11.2022
Date Code Executed: 30.12.2022
Date Assignment Submitted: 01.12.2022
*****QUESTION-1: Write a program to convert a
decimal number to binary.*****

CODE:

#include<stdio.h> int
main(){
int i, n, x, r; x=0;
printf("Enter the value of n: ");
scanf("%d",&n); while(n!=0){
r=n%2; n=n/2;
x=(x*10)+r;
}
printf("binary converted value is: %d",x);
}

OUTPUT:
*****QUESTION-2: Write a program to convert a
binary number to decimal.*****

CODE:

#include<stdio.h> #include<math.h> int


main(){ int n,r,x=0,decimal_no=0;
printf("Enter the value of n: ");
scanf("%d",&n); while(n!=0){
r=n%10; n=n/10;
decimal_no=(decimal_no+r)*pow(2,x);
x++;
}
printf("The corosponding decimal value is: %d",decimal_no);
}

OUTPUT:
*****QUESTION-3: Write a program to check whether
a number is Armstrong number or not.*****

CODE:

#include<stdio.h> int main(){


int n, r, arm=0; printf("Enter
the value of n: ");
scanf("%d",&n); int c=n;
while (n!=0){ r=n%10;
arm=arm+(r*r*r); n=n/10;
}
(c==arm)?printf("That's a armstrong number"):printf("That's
not a armstrong number");
}

OUTPUT:
*****QUESTION-4: Write a program to find all prime
numbers from 1 to n.*****

CODE:

#include <stdio.h> int


main()
{ int i, n; int c = 0;
printf("enter the value of n: ");
scanf("%d", &n); for (i = 1; i
<= n; i++)
{ if (n % i
== 0)
{
c++;
}
}
(c == 2) ? printf("That's a prime number") : printf("That's not a
prime number");
}

OUTPUT:
*****QUESTION-5: Write a program to find the sum of
all prime numbers from 1 to n.*****

CODE:

#include <stdio.h> int


main()
{ int i, j, n, sum = 0;
printf("Enter the value of n: ");
scanf("%d", &n); for (i = 2; i
<= n; i++)
{ int c = 0; for
(j = 1; j <= i; j++)
{ if (i % j
== 0)
{
c++;
} }
if (c == 2)
{
printf(" prime numbers are : %d\n", i);
sum += i;

}
}
printf("Sum of those prime numbers are: %d\n", sum);
return 0;
}

OUTPUT:
*****QUESTION-6: Write a program to check whether
a number is perfect number or not.*****

CODE:

#include<stdio.h> int
main(){ int i, n,
sum=0,x=0; printf("Enter
a number: ");
scanf("%d",&n); for
(i=1;i<n;i++){
sum=sum+i; if (n%i ==
0)
{
x= x+i;
}
}
(x==n)?printf("That's a perfect number"):printf("That's not a
perfect number");
}

OUTPUT:
*****QUESTION-7: Write a program to print all ascii
values using for loop.*****

CODE:

#include<stdio.h> int
main(){
int i;
for(i=0; i<=255; i++){ printf("Ascii Value of
charecter %c = %d\n",i,i);
}
return 0;
}

OUTPUT:
*****QUESTION-8: Write a program to design a
calculator using switch case that can perform addition,
subtraction, multiplication, division, remainder, gcd, sin
(theta), cos(theta), tan (theta), pow, sqrt, degree to
radian, radian to degree etc.*****

CODE:

#include <stdio.h>
#include <math.h>
int main()
{
char operator;
int ans, GCD;
int x, z;
printf("enter operator: ");
scanf("%c", &operator);
switch (operator)
{
case '+':
printf("Enter 1st Number: ");
scanf("%d", &x);
printf("Enter 2nd Number: ");
scanf("%d", &z);
ans = x + z;
printf("The Addition Is = %d", ans);
break;
case '-':
printf("Enter 1st Number: ");
scanf("%d", &x);
printf("Enter 2nd Number: ");
scanf("%d", &z);
ans = x - z;
printf("The Subtraction Is = %d", ans);
break;
case '*':
printf("Enter 1st Number: ");
scanf("%d", &x);
printf("Enter 2nd Number: ");
scanf("%d", &z);
ans = x * z;
printf("The Multiplication Is = %d", ans);
break;
case '/':
printf("Enter 1st Number: ");
scanf("%d", &x);
printf("Enter 2nd Number: ");
scanf("%d", &z);
ans = x / z;
printf("The Division Value Is = %d", ans);
break;
case '^':
printf("Enter 1st Number: ");
scanf("%d", &x);
printf("Enter 2nd Number: ");
scanf("%d", &z);
ans = (pow(x, z));
printf("The POW Value Is = %d", ans);
break;
case '%':
printf("Enter 1st Number: ");
scanf("%d", &x);
printf("Enter 2nd Number: ");
scanf("%d", &z);
ans = x % z;
printf("The Remainder Value Is = %d", ans);
break;
case ':':
printf("Enter 1st Number: ");
scanf("%d", &x);
printf("Enter 2nd Number: ");
scanf("%d", &z);
for (int i = 1; i <= x && i <= z; ++i)
{
if (x % i == 0 && z % i == 0)
GCD = i;
}
printf("GCD of %d And %d = %d", x, z, GCD);
break;
case 's':
double sin_theata;
printf("Enter the number: ");
scanf("%d", &x);
sin_theata = sin(x);
printf("The sin Value of %d is %lf ", x, sin_theata);
break;
case 'c':
double cos_theata;
printf("Enter the number: ");
scanf("%d", &x);
cos_theata = cos(x);
printf("The cos Value Of %d Is %lf ", x, cos_theata);
break;
case 't':
double tan_theata;
printf("Enter the number: ");
scanf("%d", &x);
tan_theata = tan(x);
printf("The tan Value Of %d Is %lf ", x, tan_theata);
break;
case 'Q':
double square_root;
printf("Enter the number: ");
scanf("%d", &x);
square_root = sqrt(x);
printf("%d'S Square Root = %lf ", x, square_root);
break;
case 'd':
double degreetoradian;
printf("Enter the number: ");
scanf("%d", &x);
degreetoradian = x * 3.14 / 180;
printf("Degree %d = Radian %lf ", x, degreetoradian);
break;
case 'r':
double radiantodegree;
printf("Enter the number: ");
scanf("%d", &x);
radiantodegree = x * 180 / 3.14;
printf("Radian %d = Degree %lf ", x, radiantodegree);
break;
default:
printf(" ERROR !!");
break;
}
return 0;
}

OUTPUT:

You might also like