# Programming ## This C program is to check whether a given number is a prime number or not.For example 5 is a prime number and 8 is not a prime number.

c-program to check whether a given number is prime C #include<stdio.h> void main() { int n,i,c=0; printf(“Enter any numbern”); scanf(“%d”,&n); for(i=1;i<= n;i++) { if (n%i==0) { c++; } } if(c==2) { printf(“n%d is a Prime number”,n); } else { printf(“n%d is not a Prime number”,n); } } 1 2 3 4 5 6 7 8 … ## This C program is to convert a decimal number to a binary number.

c-program to convert a decimal number to a binary number C #include<stdio.h> void main() { int b,n,i,c; printf(“Enter the decimal non”); scanf(“%d”,&n); i=0; c=0; while(n!=0) { b[i]=n%2; n=n/2; i++; c++; } printf(“Binary number :-n”); for(i=c-1;i>=0;i–) printf(“%d “,b[i]); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 … ## This C program is to find the sum of first n natural numbers. Natural numbers are non-negative integers.

c-program to find sum of first n natural numbers C #include<stdio.h> void main() { int i,n,sum=0; printf(“Enter how many terms you want to addn”); scanf(“%d”,&n); for(i=0;i<=n;i++) { sum=sum+i; } printf(“Summation of first %d natural numbers = %dn”,n,sum); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include<stdio.h> void … ## c-program to find odd numbers of first n terms

c-program to find odd numbers of first n terms C <br /><br /> #include<stdio.h><br /><br /> void main()<br /><br /> {<br /><br /> int i,n;<br /><br /> printf(“enter a non”);<br /><br /> scanf(“%d”,&n);<br /><br /> printf(“Odd nos of %d terms are :- n”,n);<br /><br /> for(i=1;i<=2*n;i++)<br /><br /> {<br /><br /> if(i%2==0)<br /><br /> continue;<br … ## This C program is to check if the given number is odd or even.For eg 12 is an even number as it is divisible by 2.

c-program to check if the given number is even or odd C #include<stdio.h> void main() { int n; printf(“Enter a numbern”); scanf(“%d”,&n); if(n%2==0) { printf(“n%d is an even number”,n); } else { printf(“n%d is an odd number”,n); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 … ## This C program checks if the given year is a leap year or not.

c-program to check if the given year is a leap year or not C #include <stdio.h> void main() { int year; printf(“Enter a yearn”); scanf(“%d”,&year); if((year%4==0 && year%100!=0) || (year%4==0 && year%400==0)) { printf(“n%d is a leap year”,year); } else { printf(“n%d is not a leap year”,year); } } 1 2 3 4 5 6 … ## This C program is written to find the the area of a circle

c-program to find area of a circle C #include<stdio.h> void main() { float radius,area; printf(“nEnter the radius of the circlen”); scanf(“%f”,&radius); area=3.142*radius*radius; printf(“Area of the circle = %.3f”,area);// %.3f upto 3 decimal places } 1 2 3 4 5 6 7 8 9 10 11 #include<stdio.h>   void main() {    float radius,area;       … ## In this C program we find the maximum between three numbers using a ternary operator.For eg 8,4,10 the maximum of these numbers is 10.So 10 should be are output.

c-program to find the maximum between three numbers using ternary operator C #include<stdio.h> void main() { int a,b,c,t,max; printf(“enter 3 numbersn”); scanf(“%d%d%d”,&a,&b,&c); t=a>b?a:b; max=t>c?t:c; printf(“nmax value is %d”,max); } 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> void main() {     int a,b,c,t,max;     printf(“enter 3 numbersn”);     scanf(“%d%d%d”,&a,&b,&c);     t=a>b?a:b;     max=t>c?t:c;     printf(“nmax value is %d”,max); … ## In this C program we find the maximum between three numbers.For eg 8,4,10 the maximum of these numbers is 10.

C-program to find maximum betweeen three numbers C #include <stdio.h> void main() { int num1, num2, num3, maximum; /* Input three numbers from user */ printf(“Enter three numbers:n”); scanf(“%d%d%d”,&num1,&num2,&num3); if(num1 > num2) { if(num1 > num3) { maximum = num1; } else { maximum = num3; } } else { if(num2 > num3) { maximum … ## This C program is to use bitwise operators.In C Programming bitwise operators are &(AND) , |(OR) , ^(XOR) , >(RIGHT SHIFT),~(NEGATION).

c-program to use bitwise operators C #include<stdio.h> void main() { int a,b; printf(“Enter 2 numbersn”); scanf(“%d%d”,&a,&b); printf(“AND of %d and %d = %dn”,a,b,a&b); printf(“OR of %d and %d = %dn”,a,b,a|b); printf(“X0R of %d and %d = %dn”,a,b,a^b); printf(“%d << 2 = %dn”,a,a<<2); printf(“%d << 2 = %dn”,b,b<<2); printf(“%d >> 2 = %dn”,a,a>>2); printf(“%d >> 2 …