1. Write a program to find given number
is even or odd using C program .
Solutions:
#include<stdio.h>
int main(){
int a;
printf("Enter a number to know it is evenr or odd
\n");
scanf("%d",&a);
if(a%2==0){
printf("%d is even number",a);
}
else{
printf("%d is odd number",a);
}
return 0;
}
Don't Miss the Important Question/Past Year Question & everything you need in your exam preparation.
2.Write a program to print whether a
given number is prime or composite
number .
Solutions:
#include<stdio.h>
int main(){
int a;
printf("Enter a number to check \n");
scanf("%d",&a);
int b;
int c=0;
for(b=1;b<=a;b++){
if(a%b==0){
c=c+1;
}
}
if(c==2){
printf("It is prime number");
}
else{
printf("It is composite number");
}
return 0;
}
3. Write a program to print
multiplication table of given number
using C program.
Solutions:
#include<stdio.h>
void main()
{
int a=1,b,c;
printf("Enter a number to find table:");
scanf("%d",&b);
do{
c=b*a;
printf("%d * %d = %d \n",b,a,c);
a++;
}
while(a<=10);
}
4. Write a to display fibonacii series
using C program with functions.
Solutions:
#include<stdio.h>
void fibonacciSeries(int range)
{
int a=0, b=1, c;
while (a<=range)
{
printf("%d\t", a);
c = a+b;
a = b;
b = c;
}
}
int main()
{
int range;
printf("Enter range: ");
scanf("%d", &range);
printf("The fibonacci series is: \n");
fibonacciSeries(range);
return 0;
}
5. Write a program to print prime
numbers between 1 to 100 .
Solutions :
#include<stdio.h>
int main(){
int a;
int b;
int c;
printf("Prime number from 1 to 100 :");
for(a=1;a<=100;a++){
c=0;
for(b=1;b<=a;b++){
if(a%b==0){
c++;
}
}
if(c==2){
printf("\n%d",a);
}
}
return 0;
}
6. Write a program to find factorial of
given number using recursive function.
Solutions:
#include<stdio.h>
#include<conio.h>
int fact(int);
void main(){
int n,f;
printf("Enter no. for finding factorial :");
scanf("%d",&n);
f=fact(n);
printf("factorial is %d",f);
getch();
}
int fact(int n){
if(n==0){
return(1);
}
else{
return(n*fact(n-1));
}
}
7.Write a program to find sum of given
‘n’ numbers in array using function .
Solutions :
#include <stdio.h>
int sumofarray(int a[],int n)
{
int i,sum=0;
for(i=0; i<n; i++)
{
sum+=a[i];
}
return sum;
}
int main()
{
int a[1000],i,n,sum;
printf("Enter size of the array : ");
scanf("%d", &n);
printf("Enter number to do sum : ");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
sum=sumofarray(a,n);
printf("sum of array is :%d",sum);
}
8. Write a display to Sunday to Saturday
when user enters a number using switch
case in c program .
Solutions :
#include <stdio.h>
int main() {
int a ;
printf("Enter a day number\n");
scanf("%d",&a);
switch(a){
case 1 : printf("This means Sunday");
break;
case 2: printf("This means Monday");
break;
case 3: printf("This means Tuesday");
break;
case 4: printf("This means Wednesday");
break;
case 5 :printf("This means Thursday");
break;
case 6:printf("This means Friday");
break;
case 7: printf("This means Saturday");
break;
default: printf("This is Invalid number");
}
return 0;
}
9. Write a program to find power using
pow() function in c .
Solutions :
#include<stdio.h>
#include<math.h>
int main()
{
int num1, num2;
printf("Enter base and power: ");
scanf("%d %d",&num1, &num2);
printf("Result = %.2f",pow(num1, num2));
return 0;
}
10. Write a c program to find greatest
number among different numbers using
array with functions .
Solutions :
#include<stdio.h>
void main()
{
int maximum(int a[],int n);
int max,i,n;
int a[50];
printf("Enter how many no. to check:");
scanf("%d",&n);
printf("Enter the numbers:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
max=maximum(a,n);
}
printf("The largest number is %d",max);
}
int maximum(int a[],int n)
{
int i,m=0;
for(i=0;i<n;i++)
{
if(a[i]>m)
m=a[i];
}
return m;
}
11. Write a c program to find whether a
given number is plaindrome or not .
Solutions:
#include <stdio.h>
int main() {
int n;
int original;
int remainder;
int reversed=0;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}
if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.", original);
return 0;
}
12. Write a c program to find whether a
given string is plaindrome or not .
Solutions :
#include<stdio.h>
#include<string.h>
int main()
{
char s1[1000],s2[1000];
printf("Enter the string: ");
gets(s1);
strcpy(s2,s1);
strrev(s2);
if(!strcmp(s1,s2))
printf("string is palindrome");
else
printf("string is not palindrome");
return 0;
}
13. Write a c program to input 2*2
matrix element and display the
transpose of matrix.
Solutions:
#include<stdio.h>
void main()
{
int mat[2][2],transpose[2][2];
int i;
int j;
printf("Transpose of 2*2 matrix\n");
printf("Enter the elements of the matrix\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&mat[i][j]);
}
}
printf("The matrix\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",mat[i][j]);
}
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
transpose[j][i]=mat[i][j];
}
}
printf("The transpose of the matrix is\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",transpose[i][j]);
}
printf("\n");
}
}
14.WAP to enter the 20 employee’s
name, age, and salary using structure
and print them.
Solutions :
#include<stdio.h>
struct emp
{
char n[100];
int age;
int sal;
};
struct emp e[20];
int main()
{
int i;
printf("Enter employee name age and salary\n");
for(i=0;i<20;i++)
{
scanf("%s %d %d",e[i].n,&e[i].age,&e[i].sal);
}
printf("Name \t Age \t Salary");
for(i=0;i<20;i++)
{
printf("%s\t %d\t %d\t",e[i].n,e[i].age,e[i].sal);
}
return 0;
}
15. Write a c program to find whether a
given number is Armstrong or not .
Solutions:
#include<stdio.h>
int isArmstrong(int number)
{
int lastDigit = 0;
int power = 0;
int sum = 0;
int n = number;
while(n!=0) {
lastDigit = n % 10;
power = lastDigit*lastDigit*lastDigit;
sum += power;
n /= 10;
}
if(sum == number) return 0;
else return 1;
}
int main()
{
int number;
printf("Enter number: ");
scanf("%d",&number);
if(isArmstrong(number) == 0)
printf("%d is an Armstrong number.\n", number);
else
printf("%d is not an Armstrong number.", number);
return 0;
}
Don't Miss the Important Question/Past Year Question & everything you need in your exam preparation.