77. Program to calculate the sum of 'n' terms in Taylor series.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x, i;
int fact = 1, n;
float sum = 0;
clrscr();
printf("Enter the value of x : ");
scanf("%d", &x);
printf("Enter the number of terms : ");
scanf("%d", &n);
for (i = 1; i < n; i++)
{
fact = fact * i;
sum = sum + (pow(x, i) / fact);
}
sum = sum + 1;
printf("The sum of taylor series is : ");
printf("%f", sum);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x, i;
int fact = 1, n;
float sum = 0;
clrscr();
printf("Enter the value of x : ");
scanf("%d", &x);
printf("Enter the number of terms : ");
scanf("%d", &n);
for (i = 1; i < n; i++)
{
fact = fact * i;
sum = sum + (pow(x, i) / fact);
}
sum = sum + 1;
printf("The sum of taylor series is : ");
printf("%f", sum);
getch();
}
@programming_and_coding
78. Program to swap two numbers without using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int x = 10, y = 5;
clrscr();
printf("Enter x : ");
scanf("%d", &x);
printf("Enter y : ");
scanf("%d", &y);
printf("\nBefore Swapping : \n x = %d \n y = %d", x, y);
// Code to swap x and y
x = x + y;
y = x - y;
x = x - y;
printf("\nAfter Swapping : \n x = %d \n y = %d", x, y);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
int x = 10, y = 5;
clrscr();
printf("Enter x : ");
scanf("%d", &x);
printf("Enter y : ");
scanf("%d", &y);
printf("\nBefore Swapping : \n x = %d \n y = %d", x, y);
// Code to swap x and y
x = x + y;
y = x - y;
x = x - y;
printf("\nAfter Swapping : \n x = %d \n y = %d", x, y);
getch();
}
@programming_and_coding
79. Program to swap two numbers using bitwise XOR.
#include<stdio.h>
#include<conio.h>
void main()
{
long i, k;
clrscr();
printf("Enter two integers : \n");
scanf("%ld %ld", &i, &k);
printf("\n Before swapping i : %ld and k : %ld", i, k);
i = i ^ k;
k = i ^ k;
i = i ^ k;
printf("\nAfter swapping i : %ld and k : %ld", i, k);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
long i, k;
clrscr();
printf("Enter two integers : \n");
scanf("%ld %ld", &i, &k);
printf("\n Before swapping i : %ld and k : %ld", i, k);
i = i ^ k;
k = i ^ k;
i = i ^ k;
printf("\nAfter swapping i : %ld and k : %ld", i, k);
getch();
}
@programming_and_coding
80. Program to swap two numbers using pointer.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
int *ptra, *ptrb, *temp;
clrscr();
printf("Enter a : ");
scanf("%d", &a);
printf("Enter b : ");
scanf("%d", &b);
printf("\nBefore swapping : a : %d, b : %d", a, b);
ptra = &a;
ptrb = &b;
temp = ptra;
*ptra = *ptrb;
*ptrb = *temp;
printf("\nAfter swapping : a : %d, b : %d", a, b);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
int *ptra, *ptrb, *temp;
clrscr();
printf("Enter a : ");
scanf("%d", &a);
printf("Enter b : ");
scanf("%d", &b);
printf("\nBefore swapping : a : %d, b : %d", a, b);
ptra = &a;
ptrb = &b;
temp = ptra;
*ptra = *ptrb;
*ptrb = *temp;
printf("\nAfter swapping : a : %d, b : %d", a, b);
getch();
}
@programming_and_coding
81. Program to add two numbers using pointer.
#include<stdio.h>
#include<conio.h>
void main()
{
int first, second, *p, *q, sum;
clrscr();
printf("Enter two integers : \n");
scanf("%d %d", &first, &second);
p = &first;
q = &second;
sum = *p + *q;
printf("\nSum of entered numbers : %d", sum);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
int first, second, *p, *q, sum;
clrscr();
printf("Enter two integers : \n");
scanf("%d %d", &first, &second);
p = &first;
q = &second;
sum = *p + *q;
printf("\nSum of entered numbers : %d", sum);
getch();
}
@programming_and_coding
82. Program to add first and last digit of a number.
#include<stdio.h>
#include<conio.h>
void main()
{
int input, firstNum, lastNum;
clrscr();
printf("Enter number : ");
scanf("%d", &input);
lastNum = input % 10;
firstNum = input;
while (firstNum >= 10)
firstNum /= 10;
printf("\nAddition of first and last number : %d + %d = %d",
firstNum, lastNum, firstNum + lastNum);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
int input, firstNum, lastNum;
clrscr();
printf("Enter number : ");
scanf("%d", &input);
lastNum = input % 10;
firstNum = input;
while (firstNum >= 10)
firstNum /= 10;
printf("\nAddition of first and last number : %d + %d = %d",
firstNum, lastNum, firstNum + lastNum);
getch();
}
@programming_and_coding
83. Program to find area of triangle using Heron's formula.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double a, b, c, s, area;
clrscr();
printf("\nEnter the sides of triangle : \n");
scanf("%lf%lf%lf", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("\nArea of triangle using Heron's Formula : %.2lf", area);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double a, b, c, s, area;
clrscr();
printf("\nEnter the sides of triangle : \n");
scanf("%lf%lf%lf", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("\nArea of triangle using Heron's Formula : %.2lf", area);
getch();
}
@programming_and_coding
84. Program to convert Binary to Decimal.
#include<stdio.h>
#include<math.h>
#include<conio.h>
int binary_decimal(int n);
void main()
{
int n;
char c;
clrscr();
printf("Enter Binary number : ");
scanf("%d", &n);
printf("%d in binary = %d in decimal", n, binary_decimal(n));
getch();
}
//Function to convert binary to decimal.
int binary_decimal(int n)
{
int decimal = 0, i = 0, rem;
while (n != 0)
{
rem = n % 10;
n /= 10;
decimal += rem * pow(2, i);
++i;
}
return decimal;
}
@programming_and_coding
#include<stdio.h>
#include<math.h>
#include<conio.h>
int binary_decimal(int n);
void main()
{
int n;
char c;
clrscr();
printf("Enter Binary number : ");
scanf("%d", &n);
printf("%d in binary = %d in decimal", n, binary_decimal(n));
getch();
}
//Function to convert binary to decimal.
int binary_decimal(int n)
{
int decimal = 0, i = 0, rem;
while (n != 0)
{
rem = n % 10;
n /= 10;
decimal += rem * pow(2, i);
++i;
}
return decimal;
}
@programming_and_coding
85. Program to convert Decimal numbers to Binary.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, k;
clrscr();
printf("Enter a decimal number : ");
scanf("%d", &n);
printf("\n%d in binary number system is : ", n);
for (c = 31; c >= 0; c--)
{
k = n >> c;
if (k & 1)
{
printf("1");
}
else
{
printf("0");
}
}
printf("\n");
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, k;
clrscr();
printf("Enter a decimal number : ");
scanf("%d", &n);
printf("\n%d in binary number system is : ", n);
for (c = 31; c >= 0; c--)
{
k = n >> c;
if (k & 1)
{
printf("1");
}
else
{
printf("0");
}
}
printf("\n");
getch();
}
@programming_and_coding
β
Wipro Elite NLTH Registration
Last date: 5th Jan 2021
Online Exam: 18thβ23th Jan 2021
Apply Link: bit.ly/nlthexam2
Batch: 2021 Passout
Eligibility: B.E/B.Tech/5yrs Integ-M.Tech
Branch: CS/IT/Circuital
CTC: INR 3.50 lpa & 6.75 lpa
- via Prepflix
Telegram: @programming_and_coding
#Update 3
Last date: 5th Jan 2021
Online Exam: 18thβ23th Jan 2021
Apply Link: bit.ly/nlthexam2
Batch: 2021 Passout
Eligibility: B.E/B.Tech/5yrs Integ-M.Tech
Branch: CS/IT/Circuital
CTC: INR 3.50 lpa & 6.75 lpa
- via Prepflix
Telegram: @programming_and_coding
#Update 3
RBR GATE Course [165GB]
https://rbrgate.freevideos.workers.dev/
β Important: Unmute & Pin this channel in your telegram app to never miss any updates. If facing any download issue [Quota Limit etc] try after sometime
(Share with Credits)
#Update4
Telegram:@programming_and_coding
https://rbrgate.freevideos.workers.dev/
β Important: Unmute & Pin this channel in your telegram app to never miss any updates. If facing any download issue [Quota Limit etc] try after sometime
(Share with Credits)
#Update4
Telegram:@programming_and_coding
86. Program to find f(x) by Lagrange's interpolation method.
#include<stdio.h>
#include<conio.h>
void main()
{
float x[10], y[10], temp = 1, f[10], sum, p;
int i, n, j, k = 0, c;
clrscr();
printf("How many record you will enter : ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("\n\nenter the value of x%d: ", i);
scanf("%f", &x[i]);
printf("\n\nEnter the value of f(x%d): ", i);
scanf("%f", &y[i]);
}
printf("\n\nEnter X for finding f(x): ");
scanf("%f", &p);
for (i = 0; i < n; i++)
{
temp = 1;
k = i;
for (j = 0; j < n; j++)
{
if (k == j)
{
continue;
}
else
{
temp = temp * ((p - x[j]) / (x[k] - x[j]));
}
}
f[i] = y[i] * temp;
}
for (i = 0; i < n; i++)
{
sum = sum + f[i];
}
printf("\n\nf(%.1f) = %f ", p, sum);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
float x[10], y[10], temp = 1, f[10], sum, p;
int i, n, j, k = 0, c;
clrscr();
printf("How many record you will enter : ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("\n\nenter the value of x%d: ", i);
scanf("%f", &x[i]);
printf("\n\nEnter the value of f(x%d): ", i);
scanf("%f", &y[i]);
}
printf("\n\nEnter X for finding f(x): ");
scanf("%f", &p);
for (i = 0; i < n; i++)
{
temp = 1;
k = i;
for (j = 0; j < n; j++)
{
if (k == j)
{
continue;
}
else
{
temp = temp * ((p - x[j]) / (x[k] - x[j]));
}
}
f[i] = y[i] * temp;
}
for (i = 0; i < n; i++)
{
sum = sum + f[i];
}
printf("\n\nf(%.1f) = %f ", p, sum);
getch();
}
@programming_and_coding
87. Program to check the leap year.
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year : ");
scanf("%d", &year);
if (year % 400 == 0)
printf("\n%d is a leap year.", year);
else if (year % 100 == 0)
printf("\n%d is not a leap year.", year);
else if (year % 4 == 0)
printf("\n%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year : ");
scanf("%d", &year);
if (year % 400 == 0)
printf("\n%d is a leap year.", year);
else if (year % 100 == 0)
printf("\n%d is not a leap year.", year);
else if (year % 4 == 0)
printf("\n%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
getch();
}
@programming_and_coding
88. Program to find nCr & nPr.
#include<stdio.h>
#include<conio.h>
long factorial(int);
long find_ncr(int, int);
long find_npr(int, int);
void main()
{
int n, r;
long ncr, npr;
clrscr();
printf("Enter the value of n and r : \n");
scanf("%d %d", &n, &r);
ncr = find_ncr(n, r);
npr = find_npr(n, r);
printf("%dC%d = %ld\n", n, r, ncr);
printf("%dP%d = %ld\n", n, r, npr);
getch();
}
long find_ncr(int n, int r)
{
long result;
result = factorial(n) / (factorial(r) * factorial(n - r));
return result;
}
long find_npr(int n, int r)
{
long result;
result = factorial(n) / factorial(n - r);
return result;
}
long factorial(int n)
{
int c;
long result = 1;
for (c = 1; c <= n; c++)
result = result * c;
return (result);
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
long factorial(int);
long find_ncr(int, int);
long find_npr(int, int);
void main()
{
int n, r;
long ncr, npr;
clrscr();
printf("Enter the value of n and r : \n");
scanf("%d %d", &n, &r);
ncr = find_ncr(n, r);
npr = find_npr(n, r);
printf("%dC%d = %ld\n", n, r, ncr);
printf("%dP%d = %ld\n", n, r, npr);
getch();
}
long find_ncr(int n, int r)
{
long result;
result = factorial(n) / (factorial(r) * factorial(n - r));
return result;
}
long find_npr(int n, int r)
{
long result;
result = factorial(n) / factorial(n - r);
return result;
}
long factorial(int n)
{
int c;
long result = 1;
for (c = 1; c <= n; c++)
result = result * c;
return (result);
}
@programming_and_coding
89. Program for Newton Raphson General.
#include<stdio.h>
#include<math.h>
int user_power, i = 0, cnt = 0, flag = 0;
int coef[10] = {0};
float x1 = 0, x2 = 0, t = 0;
float fx1 = 0, fdx1 = 0;
int main()
{
printf("PROGRAM FOR NEWTON RAPHSON GENERAL");
printf("\nEnter the total no. of power : ");
scanf("%d", &user_power);
for (i = 0; i <= user_power; i++)
{
printf("\nx^%d : ", i);
scanf("%d", &coef[i]);
}
printf("\n");
printf("\n\nThe Polynomial is ");
//printing coeff.
for (i = user_power; i >= 0; i--)
{
printf("%dx^%d", coef[i], i);
}
printf("\n\nIntial x1 -> ");
scanf("%f", &x1);
printf("Iteration\tX1\tFX1\tF'X1");
do
{
cnt++;
fx1 = fdx1 = 0;
for (i = user_power; i >= 1; i--)
{
fx1 += coef[i] * (pow(x1, i));
}
fx1 += coef[0];
for (i = user_power; i >= 0; i--)
{
fdx1 += coef[i] * (i * pow(x1, (i - 1)));
}
t = x2;
x2 = (x1 - (fx1 / fdx1));
x1 = x2;
printf("\n\t%d\t%.3f\t%.3f\t%.3f ", cnt, x2, fx1, fdx1);
}
while ((fabs(t - x1)) >= 0.0001);
printf("\n\nThe root of equation is %f", x2);
return 0;
}
@programming_and_coding
#include<stdio.h>
#include<math.h>
int user_power, i = 0, cnt = 0, flag = 0;
int coef[10] = {0};
float x1 = 0, x2 = 0, t = 0;
float fx1 = 0, fdx1 = 0;
int main()
{
printf("PROGRAM FOR NEWTON RAPHSON GENERAL");
printf("\nEnter the total no. of power : ");
scanf("%d", &user_power);
for (i = 0; i <= user_power; i++)
{
printf("\nx^%d : ", i);
scanf("%d", &coef[i]);
}
printf("\n");
printf("\n\nThe Polynomial is ");
//printing coeff.
for (i = user_power; i >= 0; i--)
{
printf("%dx^%d", coef[i], i);
}
printf("\n\nIntial x1 -> ");
scanf("%f", &x1);
printf("Iteration\tX1\tFX1\tF'X1");
do
{
cnt++;
fx1 = fdx1 = 0;
for (i = user_power; i >= 1; i--)
{
fx1 += coef[i] * (pow(x1, i));
}
fx1 += coef[0];
for (i = user_power; i >= 0; i--)
{
fdx1 += coef[i] * (i * pow(x1, (i - 1)));
}
t = x2;
x2 = (x1 - (fx1 / fdx1));
x1 = x2;
printf("\n\t%d\t%.3f\t%.3f\t%.3f ", cnt, x2, fx1, fdx1);
}
while ((fabs(t - x1)) >= 0.0001);
printf("\n\nThe root of equation is %f", x2);
return 0;
}
@programming_and_coding
90. Program to calculate the sum of even numbers from 1 to n.
#include<stdio.h>
#include<conio.h>
void main()
{
int sum = 0, n;
clrscr();
printf("Enter the number : ");
scanf("%d", &n);
// Using Math formula
// (n/2)((n / 2) + 1)
sum = ((n / 2) * ((n / 2) + 1));
printf("Sum of even numbers from 1 to %d : %d", n, sum);
getch();
}
@programming_and_coding
#include<stdio.h>
#include<conio.h>
void main()
{
int sum = 0, n;
clrscr();
printf("Enter the number : ");
scanf("%d", &n);
// Using Math formula
// (n/2)((n / 2) + 1)
sum = ((n / 2) * ((n / 2) + 1));
printf("Sum of even numbers from 1 to %d : %d", n, sum);
getch();
}
@programming_and_coding
Code With Mosh - The Complete ASP.NET MVC 5 Courses
https://drive.google.com/folderview?id=1izOIk6Xzdnkxi9C-qtUOmB2kgLULfsP5
#lecture_link_1
Telegram:@programming_and_coding
https://drive.google.com/folderview?id=1izOIk6Xzdnkxi9C-qtUOmB2kgLULfsP5
#lecture_link_1
Telegram:@programming_and_coding
5_6208254524902081083.pdf
116.2 KB
Top 30 HR round question and perfect answer
Share with family nd friend to help them.
Telegram:-@programming_and_coding
Share with family nd friend to help them.
Telegram:-@programming_and_coding
91. Simpson 1/3 rule.
#include<stdio.h>
float f(float x)
{
return (1 / (1 + x));
}
void main()
{
int i, n;
float x0, xn, h, y[20], so, se, ans, x[20];
clrscr();
printf("\nEnter values of x0,xn,h: ");
scanf("%f%f%f", &x0, &xn, &h);
n = (xn - x0) / h;
if (n % 2 == 1)
{
n = n + 1;
}
h = (xn - x0) / n;
printf("\nRefined value of n and h are:%d and %f\n", n, h);
printf("\n Y values: \n");
for (i = 0; i <= n; i++)
{
x[i] = x0 + i * h;
y[i] = f(x[i]);
printf("\n %f\n", y[i]);
}
so = 0;
se = 0;
for (i = 1; i < n; i++)
{
if (i % 2 == 1)
{
so = so + y[i];
}
else
{
se = se + y[i];
}
}
ans = h / 3 * (y[0] + y[n] + 4 * so + 2 * se);
printf("\nFinal integration is %f", ans);
getch();
}
@programming_and_coding
#include<stdio.h>
float f(float x)
{
return (1 / (1 + x));
}
void main()
{
int i, n;
float x0, xn, h, y[20], so, se, ans, x[20];
clrscr();
printf("\nEnter values of x0,xn,h: ");
scanf("%f%f%f", &x0, &xn, &h);
n = (xn - x0) / h;
if (n % 2 == 1)
{
n = n + 1;
}
h = (xn - x0) / n;
printf("\nRefined value of n and h are:%d and %f\n", n, h);
printf("\n Y values: \n");
for (i = 0; i <= n; i++)
{
x[i] = x0 + i * h;
y[i] = f(x[i]);
printf("\n %f\n", y[i]);
}
so = 0;
se = 0;
for (i = 1; i < n; i++)
{
if (i % 2 == 1)
{
so = so + y[i];
}
else
{
se = se + y[i];
}
}
ans = h / 3 * (y[0] + y[n] + 4 * so + 2 * se);
printf("\nFinal integration is %f", ans);
getch();
}
@programming_and_coding
92. Program to add two strings without using concat() function.
#include<stdio.h>
#include<string.h>
void concat(char[], char[]);
void main()
{
char s1[50], s2[30];
clrscr();
printf("\nEnter String 1 : ");
gets(s1);
printf("\nEnter String 2 : ");
gets(s2);
concat(s1, s2);
printf("\nConcated string is : %s", s1);
getch();
}
void concat(char s1[], char s2[])
{
int i, j;
i = strlen(s1);
for (j = 0; s2[j] != '\0'; i++, j++)
{
s1[i] = s2[j];
}
s1[i] = '\0';
}
@programming_and_coding
#include<stdio.h>
#include<string.h>
void concat(char[], char[]);
void main()
{
char s1[50], s2[30];
clrscr();
printf("\nEnter String 1 : ");
gets(s1);
printf("\nEnter String 2 : ");
gets(s2);
concat(s1, s2);
printf("\nConcated string is : %s", s1);
getch();
}
void concat(char s1[], char s2[])
{
int i, j;
i = strlen(s1);
for (j = 0; s2[j] != '\0'; i++, j++)
{
s1[i] = s2[j];
}
s1[i] = '\0';
}
@programming_and_coding