You are on page 1of 5

INTRODUCTION TO COMPUTER

PROGRAMMING (CSE-271)
PREPARED BY
MD. ATIQUL ISLAM RIZVI
LECTURER, DEPT. OF CSE, CUET.
Series
#include<stdio.h>
float eseries(float, int)  e^x = 1 + x + x 2
/2! + x 3
/3! ........
int main() {
    int n; float x;
    scanf("%f", &x);
    scanf("%d", &n);
      float eseries(float x, int n) {
    printf("\nThe Exponential series value of int i; float t=1, sum=1;
%f = %0.4f", x, eseries(x, n)); for(i=1; i<=n; i++) {
}          t = t*x/i;
         sum = sum+t;
     }
return sum;
}
Series
#include<stdio.h> sin x = x - x3/3! + x5/5! - x7/7! + x9/9! ........
float sineseries(float, int) float sineseries(float x, int n) {
long long fact(int)  int i; float t, sum;
int main() { t = x; sum = x;
    int n; float x; for(i=1; i<=n; i++) {
    scanf("%f", &x);          t = (t*(-1)*x*x)/fact(2*i + 1));
    scanf("%d", &n);          sum = sum+t;
     //x = x*(3.1415/180);      }
    printf("\nThe Sine series value of return sum;
%f = %0.4f", x, sineseries(x, n)); }
} long long fact(int n) {
long long f =1; int i;
for(i=1; i<=n; i++) {
f = f * i; }
return f;
}
Series
#include<stdio.h> cos x = 1 - x2/2! + x4/4! – x6/6! + x8/8! ........
float cosineseries(float, int) float cosineseries(float x, int n) {
long long fact(int)   int i; float t, sum;
int main() { t = 1; sum = 1;
    int n; float x; for(i=1; i<=n; i++) {
    scanf("%f", &x);          t = (t*(-1)*x*x)/fact(2*i));
    scanf("%d", &n);          sum = sum+t;
     //x = x*(3.1415/180);      }
    printf("\nThe Sine series value of return sum;
%f = %0.4f", x, cosineseries(x, n)); }
} long long fact(int n) {
long long f =1; int i;
for(i=1; i<=n; i++) {
f = f * i; }
return f;
}
Swap
 Uses two variable
 Uses three variable
#include<stdio.h>
#include<stdio.h>
int main() {
int main() {
    int n, x;
    int n, x, temp;
    scanf("%d %d", &n, &x);
    scanf("%d %d", &n, &x);
    printf(“Before swap, n = %d, x =
    printf(“Before swap, n = %d, x =
%d", n, x);
%d", n, x);
n = n + x; //*
temp = n; n = x; x = temp;
x = n – x; //,/
printf(“After swap, n = %d, x =
n = n – x; //,/
%d", n, x);
printf(“After swap, n = %d, x = %d",
}
n, x);
}

You might also like