/* 1) C Program to check whether a given number is even or odd */
#include<stdio.h>
#include<conio.h>
main()
int num;
printf("\n\t Enter an integer: ");
scanf("%d",&num);
if(num%2==0)
printf("\n\t %d = Even no.",num);
else
printf("\n\t %d = Odd no.",num);
getch();
}
/* 2) C Program to check whether a given number is even or odd */
#include<stdio.h>
#include<conio.h>
main()
int num,choice=1;
do
printf("\n\t Enter an integer: ");
scanf("%d",&num);
if(num%2==0)
printf("\n\t %d = Even no.",num);
else
printf("\n\t %d = Odd no.",num);
printf("\n\t Press 1 to continue(Press 0 to exit)?: ");
scanf("%d",&choice);
}while(choice!=0);
getch();
/* 3) C program to print multiplication table of a given no. */
#include<stdio.h>
#include<conio.h>
main()
int i,num;
printf("\n\t Enter a number to print table: ");
scanf("%d",&num);
for(i=1;i<=10;i++)
printf("\n\t %d*%d = %d",num,i,(num*i));
getch();
}
/* 4) C Program to accept two numbers and tell whether the product of two numbers
is equal to or greater than 100 */
#include<stdio.h>
#include<conio.h>
main()
int num1,num2,prod;
printf("\n\t Enter num1 and num2: ");
scanf("%d%d",&num1,&num2);
prod=num1*num2;
if(prod==100)
printf("\n\t Product(%d) is equal to 100",prod);
else if(prod>100)
printf("\n\t Product(%d) is greater than 100",prod);
else
printf("\n\t Product(%d) is less than 100",prod);
getch();
Run 1:
Run 2:
/* 5)To print all the divisors of a given no.- Divisors.c */
#include<stdio.h>
#include<conio.h>
main()
int i,n;
printf("\n\t Enter a number: ");
scanf("%d",&n);
printf("\n\t The divisors are: ");
for(i=1;i<=n;i++)
if(n%i==0)
printf("\t %d\t",i);
getch();
}
/* 6) C program for reversing an integer - Reverse.c */
#include<stdio.h>
#include<conio.h>
main()
long n,r,s=0;
printf("\n\t Enter a number: ");
scanf("%ld",&n);
while(n>0)
r=n%10;
s=r+s*10;
n=n/10;
}
printf("\n\t The reversed no is : %ld",s);
getch();
/* 7) C Program to find the sum of digits of an integer */
#include<stdio.h>
#include<conio.h>
main()
int n,r,s=0;
printf("\n\t Enter a number: ");
scanf("%d",&n);
while(n>0)
r=n%10;
s=s+r;
n=n/10;
printf("\n\t The sum of digits is : %d",s);
getch();
/* 8) C program to find largest among 3 numbers */
#include<stdio.h>
#include<conio.h>
main()
float n1,n2,n3;
printf("\n\t Enter three numbers: ");
scanf("%f%f%f",&n1,&n2,&n3);
if(n1>n2 && n1>n3)
printf("\n\t %f is largest no",n1);
if(n2>n1 && n2>n3)
printf("\n\t %f is largest no",n2);
if(n3>n1 && n3>n2)
printf("\n\t %f is largest no",n3);
getch();
}
/* 9) C program to print fibonacci series: 1 1 2 3 5 8 13 . . . */
#include<stdio.h>
#include<conio.h>
main()
int num1=1,num2=1,sum,term,counter=0;
printf("\n\t Enter the terms of fibonacci series: ");
scanf("%d",&term);
printf("\n\t Fibonacci series upto % numbers: ",term);
printf("%d %d ",num1,num2);
while(counter<term-2)
sum=num1+num2;
printf("%d ",sum);
num1=num2;
num2=sum;
counter++;
}
getch();