Sei sulla pagina 1di 20

Name-Tanzir Ahmed

ID-201002030
Section-DG

//write a c programme to display primes numbers bewteen intervels using function

#include <stdio.h>

int checkPrimeNumber(int n);

int main() {

int a, b, i, temp;

printf("Input two positive integers:\n ");

scanf("%d %d", &a, &b);

printf("Prime numbers between %d and %d are: ", a, b);

for (i = a + 1; i < b; ++i) {

temp = checkPrimeNumber(i);

if (temp == 1)

printf("%d ", i);

return 0;

int checkPrimeNumber(int n) {

int j, temp = 1;
for (j = 2; j <= n / 2; ++j) {

if (n % j == 0) {

temp = 0;

break;

return temp;

//c programming to wheather a number can be expressed as sum of two prime numbers

#include <stdio.h>

int checkPrime(int n);

int main() {

int n, i, temp = 0;

printf("Enter a positive integer: ");

scanf("%d", &n);

for (i = 2; i <= n / 2; ++i)

if (checkPrime(i) == 1) {

if (checkPrime(n - i) == 1) {

printf("%d = %d + %d\n", n, i, n - i);

temp = 1;

if (temp == 0)

printf("%d cannot be expressed as the sum of two prime numbers.", n);


return 0;

int checkPrime(int n) {

int i, Prime = 1;

for (i = 2; i <= n / 2; ++i) {

if (n % i == 0) {

Prime = 0;

break;

return Prime;

//find sum of natural numbers using recrusion

#include<stdio.h>

long int Numbers(int n);

int main() {

int n;

printf("Input the number : ");

scanf("%d",&n);

printf("%ld", Numbers(n));

return 0;

long int Numbers(int n) {

if (n>=1)

return n*Numbers(n-1);
else

return 1;

//to enter any numbers and calculate ist factorial using recrusion

#include<stdio.h>

long int Numbers(int n);

int main() {

int n;

printf("Enter a positive integer: ");

scanf("%d",&n);

printf("%d",Numbers(n));

return 0;

long int Numbers(int n) {

if (n>=1)

return n*Numbers(n-1);

else

return 1;

//find GCD of two numbers using recrusion

#include <stdio.h>

int gcd(int a, int b);

int main() {

int a, b;

printf("Enter integers: ");

scanf("%d %d", &a, &b);


printf("G.C.D is %d.", gcd(a, b));

return 0;

int gcd(int a, int b) {

if (b != 0)

return gcd(b, a % b);

else

return a;

// C program to find LCM of two numbers using recursion

#include <stdio.h>

int lcm(int a, int b);

int main()

int x, y, LCM;

printf("Enter any two numbers to find lcm: ");

scanf("%d%d", &x, &y);

if(x > y)

LCM = lcm(y, x);

else

LCM = lcm(x, y);

printf("LCM = %d",LCM);

return 0;
}

int lcm(int a, int b)

static int multiple = 0;

multiple += b;

if((multiple % a == 0) && (multiple % b == 0))

return multiple;

else

return lcm(a, b);

// to print fibbonanci series up to n terms using recrutions

#include<stdio.h>

int Fibonacci(int);

int main()

int n, i = 0, c;

scanf("%d",&n);

printf("Fibonacci series\n");

for ( c = 1 ; c <= n ; c++ )


{

printf("%d\n", Fibonacci(i));

i++;

return 0;

int Fibonacci(int n)

if ( n == 0 )

return 0;

else if ( n == 1 )

return 1;

else

return ( Fibonacci(n-1) + Fibonacci(n-2) );

// to convert decimal to bionary numbers using recrusion

#include <stdio.h>

int find(int decimal_number)

if (decimal_number == 0)

return 0;

else

return (decimal_number % 2 + 10 *

find(decimal_number / 2));

int main()
{

int decimal_number = 10;

printf("%d", find(decimal_number));

return 0;

//perform input/output of all basic data types.

#include<stdio.h>

int main (){

int num ;

float x ;

char c ;

printf("enter the number :");

scanf("%d",&num);

printf("the intger value is : %d\n");

printf("Float :");

scanf("%f",&x);

printf("the float type value is : %f",x);

printf("Charectar :");

scanf("%c",&c);

printf("the intger value is : %c",c);

// enter two numbers and find their sum.


#include <stdio.h>

int main()

int a,b, sum;

printf("Input: ");

scanf("%d", &a);

printf("Input:");

scanf("%d", &b);

sum = a + b;

printf("summation= %d",sum);

return 0;

// enter two numbers and perform all arithmetic operations

#include<stdio.h>

int main()

int a ,b ,sum, diff, mult ,mod ;

printf("Enter : " );

scanf("%d \n %d",&a,&b);

sum=a+b;

diff=a-b;

mult=a*b;

float qua=a/b ;

mod=a%b;
printf("Sum=%d\n",sum);

printf("Difference=%d\n",diff);

printf("Multiplication=%d\n",mult);

printf("Division=%f\n",qua);

printf("Mod=%d\n",mod);

// enter length and breadth of a rectangle and find its perimeter.

#include<stdio.h>

int main()

int l,b,p;

printf("input:- ");

scanf("%d",&l);

printf("input:- ");

scanf("%d",&b);

p=l+b;

printf(" perimeter: %d",p);

// enter length and breadth of a rectangle and find its area.

#include<stdio.h>

int main()

int l,b,a;

printf("Enter leanth:- ");

scanf("%d",&l);
printf("Enter breath:- ");

scanf("%d",&b);

a=l*b;

printf("the Area is: %d",a);

// enter radius of a circle and find its diameter, circumference and

area

#include<stdio.h>

int main()

float r,diameter, circumference ,area ;

printf("input:- ");

scanf("%f",&r);

diameter=2*r;

circumference=2*3.1416*r ;

area=2*3.1416*(r*r);

printf("diameter=%f\n",diameter);

printf("circumference=%f\n",circumference);

printf("area=%f\n",area);

return 0;

// enter length in centimeter and convert it into meter and kilometer.

#include<stdio.h>

int main(){

float cm,m,km ;

printf("Enter : ");

scanf("%f",&cm);
m=cm/100;

km=m/100;

printf("Converted to meter :%.3f\n ",m);

printf("Converted to kilometer :%f ",km);

// enter temperature in Celsius and convert it into Fahrenheit.

#include<stdio.h>

int main()

float ce , fe ;

printf("input temperature(celcious): ");

scanf("%f",&ce);

fe=(ce*9/5)+32 ;

printf("Temperature(fehrenheit) :%.2f ",fe);

// enter temperature in Fahrenheit and convert to Celsius

#include<stdio.h>

int main()

float ce , fe ;

printf("input temperature(fehrenheit): ");

scanf("%f",&fe);

ce=(fe-32)*5/9;
printf("Temperature(celcious) :%.2f ",ce);

// convert days into years, weeks and days.

#include<stdio.h>

int main()

int years ,weeks,days ;

printf(" Input(days): ");

scanf("%d",&days);

years=(days / 365);

weeks =(days % 365)/7;

days=days-((years*365)+(weeks*7));

printf("Years :%d\n",years);

printf("Weeks :%d\n",weeks);

printf("Days :%d",days);

//find power of any number x ^ y.

#include<stdio.h>

#include<math.h>

int main()

int x,y, power ;


printf("Input base : ");

scanf("%d",&x);

printf("Input : ");

scanf("%d",&y);

power= pow (x,y);

printf("Output :%d ", power);

// enter any number and calculate its square root.

#include<stdio.h>

#include<math.h>

int main()

double x,sqr;

printf(" Input : ");

scanf("%lf",&x);

sqr = sqrt(x);

printf(" Root value (%lf) :%.2f ",x,sqr);

// enter two angles of a triangle and find the third angle.

#include <stdio.h>

int main()

int x,y,z ;

printf("Input : \n ");
scanf("%d %d",&x,&y);

z=180-(x+y);

printf(" 3rd angle :%d ",z);

// enter base and height of a triangle and find its area.

#include <stdio.h>

int main()

float h,b,a ;

printf("Input (hight,base) : \n ");

scanf("%f %f",&h,&b);

a=(h*b)/2;

printf(" Area :%.2f ",a);

// enter marks of five subjects and calculate total, average and

percentage.

#include<stdio.h>

int main(){

int x,y,z,j,k,total;

float avg,per ;

printf("Input 5 subject number: ");

scanf("%d%d%d%d%d",&x,&y,&z,&j,&k);

total=x+y+z+j+k;
avg=total/5;

per=total/500*100;

printf("Output\ntotal:%d\naverage:%f\npercentage:%.2f%%",total,avg,avg);

//display the n terms of even natural number and their

sum.

#include <stdio.h>

void main()

int i,n,sum=0;

printf("Input: ");

scanf("%d",&n);

printf("\n Even numbers :");

for(i=1;i<=n;i++)

printf("%d ",2*i);

sum=sum+2*i;

printf("\nThe Sum of even Natural Number : %d \n",n,sum);

// to display the sum of the series

#include <stdio.h>
void main()

{ int n,i,x=9;

int sum =0;

printf("Input :");

scanf("%d",&n);

for (i=1;i<=n;i++)

{ sum +=x;

printf("%ld ",x);

x=x*10+9;

printf("\nThe sum is = %d \n",sum);

//print the Floyd Triangle.

#include <stdio.h>

void main()

int i,j,n,p,q;

printf("Input : ");

scanf("%d",&n);

for(i=1;i<=n;i++)

if(i%2==0)

{ p=1;q=0;}

else

{ p=0;q=1;}

for(j=1;j<=i;j++)

if(j%2==0)

printf("%d",p);
else

printf("%d",q);

printf("\n");

// to display the sum of the series

#include <stdio.h>

void main()

float x,sum,y;

int i,n;

printf("Input the value of x :");

scanf("%f",&x);

printf("Input number of terms : ");

scanf("%d",&n);

sum =1; y = 1;

for (i=1;i<n;i++)

y = y*x/(float)i;

sum =sum+ y;

printf("\nThe sum is : %f\n",sum);

//find the sum of the series

#include <stdio.h>

#include <math.h>

void main()

{
int x,sum,ctr;

int i,n,m,mm,nn;

printf("Input x value :");

scanf("%d",&x);

printf("Input number : ");

scanf("%d",&n);

sum =x; m=-1;

printf(" the series: \n");

printf("%d\n",x);

for (i = 1; i < n; i++)

ctr = (2 * i + 1);

mm = pow(x, ctr);

nn = mm * m;

printf("%d \n",nn);

sum = sum + nn;

m = m * (-1);

printf("\nThe sum = %d\n",sum);

// display the n terms of square natural number and

their sum

#include <stdio.h>

void main()

int i,n,sum=0;

printf("Input the number of terms : ");


scanf("%d",&n);

for(i=1;i<=n;i++)

printf("%d ",i*i);

sum+=i*i;

printf("\nThe Sum = %d \n",sum);

Potrebbero piacerti anche