Q1. Write a program in C to find the given number is odd or even.
Q2. Write a program in C to find the greater number between two numbers.
Q3. Write a program in C to find whether the given number is Armstrong or not.
Q4. Write a program in C to find the series 2, 4, 6, …, 10th terms.
Q5 . Write a program in C to find the series 1, 3, 5, …, 10th terms.
Solutions
Q1. Write a program in C to find the given number is odd or even.
#include<stdio.h>
int main(){
int n;
printf("Enter the number:");
scanf("%d",&n);
if (n%2==0){
printf("%d is a even number",n);
}
else{
printf("%d is a odd number",n);
}
return 0;
}
Output
Enter the number:4
4 is a even number
--------------------------------
Process exited after 3.104 seconds with return value 0
Press any key to continue . . .
Q2. Write a program in C to find the greater number between two numbers.
Solution
#include<stdio.h>
int main(){
int a,b;
printf("Enter the number a:");
scanf("%d",&a);
printf("Enter the number b:");
scanf("%d",&b);
if(a>b){
printf("%d is the greater number",a);
}else if(b>a){
printf("%d is the greater number",b);
}else{
printf("%d and %d is equal.",a,b);
}
return 0;
}Ot
Output
Enter the number a:4
Enter the number b:6
6 is the greater number
--------------------------------
Process exited after 1.845 seconds with return value 0
Press any key to continue . . .
Q3. Write a program in C to find whether the given number is Armstrong or not.
#include <stdio.h>
#include <math.h>
int main() {
int n, n1, temp, count = 0, rem;
int arm = 0;
printf("Enter the number: ");
scanf("%d", &n);
temp = n;
n1 = n;
while (n != 0) {
n /= 10;
count++;
}
while (n1 != 0) {
rem = n1 % 10;
arm += pow(rem, count);
n1 /= 10;
}
if (arm == temp) {
printf("The given number is an Armstrong number\n");
} else {
printf("The given number is not an Armstrong number\n");
}
return 0;
}
Output
Enter the number: 153
The given number is an Armstrong number
--------------------------------
Process exited after 1.791 seconds with return value 0
Press any key to continue . . .
Q4. Write a program in C to find the series 2, 4, 6, …, 10th terms.
Solution
#include <stdio.h>
int main() {
int i;
for(i = 1; i <= 10; i++) {
printf("%d ", 2 * i);
}
return 0;
}
Output
2 4 6 8 10 12 14 16 18 20
--------------------------------
Process exited after 0.1257 seconds with return value 0
Press any key to continue . . .
Q5 . Write a program in C to find the series 1, 3, 5, …, 10th terms.
#include <stdio.h>
int main() {
int i;
for(i = 1; i <= 10; i++) {
printf("%d ", (2 * i) - 1);
}
return 0;
}
Output
1 3 5 7 9 11 13 15 17 19
--------------------------------
Process exited after 0.1487 seconds with return value 0
Press any key to continue . . .
This site uses cookies to enhance your browsing experience, remember your preferences,
and deliver faster, more personalized content. By continuing, you agree to our use of cookies.