Assignment 02
Assignment 02
NAME : L.Sampath
REG-NO : 23BCB7136
1) program to check the entered number is positive or negative
#include<stdio.h>
int main()
{
int n;
printf("enter a number");
scanf("%d",&n);
if(n>=0)
{
printf("the number is positive");
}
else{
printf("the number is negative");
}
return 0;
}
Output:-
2)To check the number is odd or even
#include<stdio.h>
int main()
{
int n;
printf("enter a number");
scanf("%d",&n);
if(n%2==0)
{
printf("the number is even");
}
else
{
printf("the number is odd");
}
return 0;
}
Output:-
}
6)program greatest among 3 numbers
#include<stdio.h>
void main()
{
int a,b,c;
printf("enter 3 number");
scanf("%d %d %d",&a,&b,&c);
if(a>c&&a>b)
{
printf("a is the greatest");
}
else if(b>a&&b>c)
{
printf("b is the greatest");
}
else
{
printf("c is the greatest");
} }
int main() {
int marks[5];
float total_marks = 0, percentage;
char grade;
return 0;
}
a) program to calculate the root of a quadratic equation
#include <stdio.h>
#include <math.h>
int main() {
double a, b, c, determinant, real_part, imaginary_part;
determinant = b * b - 4 * a * c;
if (determinant > 0) {
real_part = (-b + sqrt(determinant)) / (2 * a);
imaginary_part = (-b - sqrt(determinant)) / (2 * a);
printf("Roots are %.2lf and %.2lf\n", real_part, imaginary_part);
} else if (determinant == 0) {
real_part = -b / (2 * a);
printf("Root is %.2lf\n", real_part);
} else {
real_part = -b / (2 * a);
imaginary_part = sqrt(-determinant) / (2 * a);
printf("Roots are %.2lf + %.2lfi and %.2lf - %.2lfi\n", real_part,
imaginary_part, real_part, imaginary_part);
}
return 0;
}
b) Write a C program to read the roll no, name and marks of three
subjects and calculate the total, percentage and division.
#include <stdio.h>
int main() {
int roll_no, marks[3];
char name[100];
float total, percentage;
char division;
return 0;
}
int main() {
int angle1, angle2, angle3;
return 0;
}
d)program to compute the sum of the first “N” natural numbers
#include <stdio.h>
int main() {
int N, sum = 0;
return 0;
}
e)program in C to display the multiplication table for a given integer
#include <stdio.h>
int main() {
int number, i;
return 0;
}
f)program to calculate the factorial of a given number.
#include <stdio.h>
#include <stdio.h>
int main() {
int number, i, fact = 1;
int main() {
int number, sum = 0, digits;
int temp = number;
while(temp != 0) {
temp /= 10;
digits++;
}
temp = number;
while(temp != 0) {
int remainder = temp % 10;
sum += pow(remainder, digits);
temp /= 10;
}
if(sum == number) {
printf("%d is an Armstrong number.\n", number);
} else {
printf("%d is not an Armstrong number.\n", number);
}
return 0;
}
int main() {
int n;
if(check_prime(n) == 1)
printf("%d is a prime number\n", n);
else
printf("%d is not a prime number\n", n);
return 0;
}
int check_prime(int n) {
int i;
if(n <= 1)
return 0;
return 1;
}