Aauyusha C
Aauyusha C
Solution:
#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
if (a < b) {
printf("%d is the smallest number.\n", a);
} else if (b < a) {
printf("%d is the smallest number.\n", b);
} else {
printf("Both numbers are equal.\n");
}
return 0;
}
Output:
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("\n Enter a number:");
scanf("%d", &n);
if (n % 2 == 0)
printf("Even Number");
else
printf("Odd Number");
return 0;
}
Output:
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b;
printf("\n Enter two numbers:");
scanf("%d %d", &a, &b);
if (a > b)
printf("%d is largest", a);
else
printf("%d is largest", b);
return 0;
}
4. WAP to find the sum of first 50 natural numbers
Solution:
#include<stdio.h>
#include<conio.h>
int main()
{
int i, sum = 0;
for(i = 1; i <= 50; i++)
{
sum = sum + i;
}
printf("\n The sum is %d", sum);
return 0;
}
5. WAP to display multiplication table of a number
Solution:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, i;
printf("\n Enter a number:");
scanf("%d", &n);
for(i = 1; i <= 10; i++)
{
printf("%d x %d = %d\n", n, i, n*i);
}
return 0;
}
int main()
{
int n, i, fact = 1;
printf("\n Enter a number:");
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
fact = fact * i;
}
printf("\n Factorial = %d", fact);
return 0;
}
int main()
{
int a, b;
printf("\n Enter two numbers:");
scanf("%d %d", &a, &b);
a = a + b;
b = a - b;
a = a - b;
printf("\n After swapping: a = %d, b = %d", a,
b);
return 0;
}
8. WAP to display the reverse of a number
Solution:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, r;
printf("\n Enter a number:");
scanf("%d", &n);
printf("\n Reverse of the number is: ");
while(n > 0)
{
r = n % 10;
printf("%d", r);
n = n / 10;
}
return 0;
}
9. WAP to find the sum of digits of a number
Solution:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, sum = 0, r;
printf("\n Enter a number:");
scanf("%d", &n);
while(n > 0)
{
r = n % 10;
sum = sum + r;
n = n / 10;
}
printf("\n Sum of digits = %d", sum);
return 0;
}
10. WAP to check a number is positive, negative,
or zero
Solution:
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("\n Enter a number:");
scanf("%d", &n);
if(n > 0)
printf("Positive number");
else if(n < 0)
printf("Negative number");
else
printf("Zero");
return 0;
}
11. WAP to calculate the average of three
numbers
Solution:
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b, c;
float avg;
printf("\n Enter three numbers:");
scanf("%d %d %d", &a, &b, &c);
avg = (a + b + c) / 3.0;
printf("\n Average = %.2f", avg);
return 0;
}
12. WAP to check whether a number is a
palindrome or not
Solution:
#include <stdio.h>
int main() {
int num, reversed = 0, remainder, original;
printf("Enter a number: ");
scanf("%d", &num);
original = num;
while (num != 0) {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num /= 10;
}
if (original == reversed) {
printf("%d is a palindrome.\n", original);
} else {
printf("%d is not a palindrome.\n", original);
}
return 0;
}
13. WAP to print the Fibonacci series
Solution:
#include <stdio.h>
int main() {
int n, first = 0, second = 1, next, i;
printf("Enter the number of terms: ");
scanf("%d", &n);
return 0;
}
14. WAP to print multiplication of the matrix
Solution:
#include <stdio.h>
int main() {
int a[10][10], b[10][10], mul[10][10];
int r1, c1, r2, c2, i, j, k;
if (c1 != r2) {
printf("Matrix multiplication not possible.\n");
return 0;
}
// Multiplying matrices
for (i = 0; i < r1; i++) {
for (j = 0; j < c2; j++) {
for (k = 0; k < c1; k++) {
mul[i][j] += a[i][k] * b[k][j];
}
}
}
printf("Resultant Matrix:\n");
for (i = 0; i < r1; i++) {
for (j = 0; j < c2; j++) {
printf("%d ", mul[i][j]);
}
printf("\n");
}
return 0;
}
15. WAP to print the matrix addition
Solution:
#include <stdio.h>
#include <conio.h>
int main() {
int a[3][3], b[3][3], c[3][3];
int i, j;
printf("Sum of matrices:\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
c[i][j] = a[i][j] + b[i][j];
printf("%d ", c[i][j]);
}
printf("\n");
}
return 0;
}
16. WAP to print the days of the week using the
switch case
Solution:
#include <stdio.h>
#include <conio.h>
void main() {
int day;
printf("Enter day number (1-7): ");
scanf("%d", &day);
switch(day) {
case 1: printf("Sunday"); break;
case 2: printf("Monday"); break;
case 3: printf("Tuesday"); break;
case 4: printf("Wednesday"); break;
case 5: printf("Thursday"); break;
case 6: printf("Friday"); break;
case 7: printf("Saturday"); break;
default: printf("Invalid day");
}
getch();
}
int main() {
char ch;
printf("Enter an alphabet: ");
scanf("%c", &ch);
int main() {
float principal, rate, time, interest;
printf("Enter principal amount, rate of interest,
and time (in years): ");
scanf("%f %f %f", &principal, &rate, &time);
return 0;
}
19. WAP to calculate the power of a number (using
for loop)
Solution:
#include <stdio.h>
int main() {
int base, exponent;
long long result = 1;
printf("Enter base and exponent: ");
scanf("%d %d", &base, &exponent);
return 0;
}
20. WAP to find the sum of digits of a number
Solution:
#include <stdio.h>
int main() {
int num, sum = 0, digit;
while (num != 0) {
digit = num % 10;
sum += digit;
num /= 10;
}
return 0;
}