Submitted to
Tanjina Alamgir
Lecturer,
Dept. of Computer Science
Southern University
Source:
// C program to get the sum of the series
#include <math.h>
#include <stdio.h>
// Function to get the series
double Series(double x, int n)
{
double sum = 1, term = 1, fct, j, y = 2, m;
// Sum of n-1 terms starting from 2nd term
int i;
for (i = 1; i < n; i++) {
fct = 1;
for (j = 1; j <= y; j++) {
fct = fct * j;
}
term = term * (-1);
m = term * pow(x, y) / fct;
sum = sum + m;
y += 2;
}
return sum;
}
// Driver Code
int main()
{
double x = 9;
int n = 10;
printf("%.4f", Series(x, n));
return 0;
}
Here is the code preview and output view
Source:
#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("S ");
}
printf("n");
}
return 0;
}
Source :
#include <stdio.h>
void main()
{
int array[100], i, num;
printf("Enter the size of an array n");
scanf("%d", &num);
printf("Enter the elements of the array n");
for (i = 0; i < num; i++)
{
scanf("%d", &array[i]);
}
printf("Even numbers in the array are - ");
for (i = 0; i < num; i++)
{
if (array[i] % 2 == 0)
{
printf("%d t", array[i]);
}
}
}
Source:
#include <stdio.h>
int main()
{
int c, n, fact = 1;
printf("Enter a number to calculate its factorialn");
scanf("%d", &n);
for (c = 1; c <= n; c++)
fact = fact * c;
printf("Factorial of %d = %dn", n, fact);
return 0;
}
Source:
#include <stdio.h>
int main()
{
int num1, num2;
//Reading two numbers from user
printf("Enter two numbers to find smallest number: ");
scanf("%d%d", &num1, &num2);
//Condition to check smallest number
switch(num1 < num2)
{
case 0: printf("%d is smallest number", num2);
break;
case 1: printf("%d is smallest number", num1);
break;
}
return 0;
}
Source :
// C program to calculate the following series
#include <math.h>
#include <stdio.h>
// Function to calculate the following series
double Series(int n)
{
int i;
double sums = 0.0, ser;
for (i = 1; i <= n; ++i) {
ser = 1 / pow(i, i);
sums += ser;
}
return sums;
}
// Driver Code
int main()
{
int n = 3;
double res = Series(n);
printf("%.5f", res);
return 0;
}
Source :
#include <stdio.h>
int main()
{
int i,arr[10],sum=0;
printf("Enter 10 elements:");
for(i=0;i<10;++i)
scanf("%d",&arr[i]);
for(i=0;i<10;++i)
sum=sum+arr[i];
printf("Sum of numbers is:%d",sum);
return 0;
}
Source:
#include <stdio.h>
#include <math.h>
int main()
{
int x,n;
int result;
printf("Enter the value of base: ");
scanf("%d",&x);
printf("Enter the value of power: ");
scanf("%d",&n);
result =pow((double)x,n);
printf("%d to the power of %d is= %d", x,n, result);
getch();
return 0;
}
Source:
#include <stdio.h>
int main()
{
int x, y, t;
printf("Enter two integersn");
scanf("%d%d", &x, &y);
printf("Before SwappingnFirst integer = %dnSecond integer = %dn", x, y);
t = x;
x = y;
y = t;
printf("After SwappingnFirst integer = %dnSecond integer = %dn", x, y);
return 0;
}
Source:
#include<stdio.h>
{
Int array[100},I,num;
Printf(“Enter the size of an array n”)
Scanf(“%d”, &num);
Printf(“Enter the elements of the array”)
For(i=0; 1<num; i++)
{scanf(“%d”,&array[i]);
Printf(“n odd numbers in the array are=”);
For(i=0; i<num; i++ {
If(array[i] %2 !=0){
Printf (“%dt”,arrai[i]);}
}
}
Source:
/* C program to Print Square Star Pattern */
#include<stdio.h>
int main()
{
int i, j, Side;
printf("Please Enter Any Side of a Squaren");
scanf("%d", &Side);
for(i = 0; i < Side; i++)
{
for(j = 0; j < Side; j++)
{
printf("S");
}
printf("n");
}
return 0;
}
Source:
#include <stdio.h>
int main()
{
int num1, num2;
//Reading two numbers from user
printf("Enter two numbers to find smallest number: ");
scanf("%d%d", &num1, &num2);
//Condition to check smallest number
switch(num1 < num2)
{
case 0: printf("%d is smallest number", num2);
break;
case 1: printf("%d is smallest number", num1);
break;
}
return 0;
}
Source:
// C program to find sum of series
// 1 + x/1 + x^2/2 + x^3/3 + ....+ x^n/n
#include <math.h>
#include <stdio.h>
double sum(int x, int n)
{
double i, total = 1.0;
for (i = 1; i <= n; i++)
total = total +
(pow(x, i) / i);
return total;
}
// Driver code
int main()
{
int x = 2;
int n = 5;
printf("%.2f", sum(x, n));
return 0;
}
Program presentation
Program presentation

Program presentation

  • 1.
    Submitted to Tanjina Alamgir Lecturer, Dept.of Computer Science Southern University
  • 2.
    Source: // C programto get the sum of the series #include <math.h> #include <stdio.h> // Function to get the series double Series(double x, int n) { double sum = 1, term = 1, fct, j, y = 2, m; // Sum of n-1 terms starting from 2nd term int i; for (i = 1; i < n; i++) { fct = 1; for (j = 1; j <= y; j++) { fct = fct * j; } term = term * (-1); m = term * pow(x, y) / fct; sum = sum + m; y += 2; } return sum; } // Driver Code int main() { double x = 9; int n = 10; printf("%.4f", Series(x, n)); return 0; }
  • 3.
    Here is thecode preview and output view
  • 4.
    Source: #include <stdio.h> int main() { inti, j, rows; printf("Enter number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; ++i) { for(j=1; j<=i; ++j) { printf("S "); } printf("n"); } return 0; }
  • 6.
    Source : #include <stdio.h> voidmain() { int array[100], i, num; printf("Enter the size of an array n"); scanf("%d", &num); printf("Enter the elements of the array n"); for (i = 0; i < num; i++) { scanf("%d", &array[i]); } printf("Even numbers in the array are - "); for (i = 0; i < num; i++) { if (array[i] % 2 == 0) { printf("%d t", array[i]); } } }
  • 8.
    Source: #include <stdio.h> int main() { intc, n, fact = 1; printf("Enter a number to calculate its factorialn"); scanf("%d", &n); for (c = 1; c <= n; c++) fact = fact * c; printf("Factorial of %d = %dn", n, fact); return 0; }
  • 10.
    Source: #include <stdio.h> int main() { intnum1, num2; //Reading two numbers from user printf("Enter two numbers to find smallest number: "); scanf("%d%d", &num1, &num2); //Condition to check smallest number switch(num1 < num2) { case 0: printf("%d is smallest number", num2); break; case 1: printf("%d is smallest number", num1); break; } return 0; }
  • 12.
    Source : // Cprogram to calculate the following series #include <math.h> #include <stdio.h> // Function to calculate the following series double Series(int n) { int i; double sums = 0.0, ser; for (i = 1; i <= n; ++i) { ser = 1 / pow(i, i); sums += ser; } return sums; } // Driver Code int main() { int n = 3; double res = Series(n); printf("%.5f", res); return 0; }
  • 14.
    Source : #include <stdio.h> intmain() { int i,arr[10],sum=0; printf("Enter 10 elements:"); for(i=0;i<10;++i) scanf("%d",&arr[i]); for(i=0;i<10;++i) sum=sum+arr[i]; printf("Sum of numbers is:%d",sum); return 0; }
  • 16.
    Source: #include <stdio.h> #include <math.h> intmain() { int x,n; int result; printf("Enter the value of base: "); scanf("%d",&x); printf("Enter the value of power: "); scanf("%d",&n); result =pow((double)x,n); printf("%d to the power of %d is= %d", x,n, result); getch(); return 0; }
  • 18.
    Source: #include <stdio.h> int main() { intx, y, t; printf("Enter two integersn"); scanf("%d%d", &x, &y); printf("Before SwappingnFirst integer = %dnSecond integer = %dn", x, y); t = x; x = y; y = t; printf("After SwappingnFirst integer = %dnSecond integer = %dn", x, y); return 0; }
  • 20.
    Source: #include<stdio.h> { Int array[100},I,num; Printf(“Enter thesize of an array n”) Scanf(“%d”, &num); Printf(“Enter the elements of the array”) For(i=0; 1<num; i++) {scanf(“%d”,&array[i]); Printf(“n odd numbers in the array are=”); For(i=0; i<num; i++ { If(array[i] %2 !=0){ Printf (“%dt”,arrai[i]);} } }
  • 22.
    Source: /* C programto Print Square Star Pattern */ #include<stdio.h> int main() { int i, j, Side; printf("Please Enter Any Side of a Squaren"); scanf("%d", &Side); for(i = 0; i < Side; i++) { for(j = 0; j < Side; j++) { printf("S"); } printf("n"); } return 0; }
  • 24.
    Source: #include <stdio.h> int main() { intnum1, num2; //Reading two numbers from user printf("Enter two numbers to find smallest number: "); scanf("%d%d", &num1, &num2); //Condition to check smallest number switch(num1 < num2) { case 0: printf("%d is smallest number", num2); break; case 1: printf("%d is smallest number", num1); break; } return 0; }
  • 26.
    Source: // C programto find sum of series // 1 + x/1 + x^2/2 + x^3/3 + ....+ x^n/n #include <math.h> #include <stdio.h> double sum(int x, int n) { double i, total = 1.0; for (i = 1; i <= n; i++) total = total + (pow(x, i) / i); return total; } // Driver code int main() { int x = 2; int n = 5; printf("%.2f", sum(x, n)); return 0; }