C_Language_Coding
1.33K subscribers
4 files
31 links
This channel will serve you C language program from basic to advance in a serial order that help you in understand the basic and crack any IT examination in easy way .

Invite other to Subscribe this channel on telegram
@Programming_and_Coding
Download Telegram
56. Add 'n' numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum=0, i, value;
clrscr();

printf("Enter total numbers you want to add : ");
scanf("%d", &n);

for (i=1; i<=n; i++)
{
printf("Enter number %d : ", i);
scanf("%d", &value);
sum = sum + value;
}

printf("Sum of entered numbers : %d", sum);
getch();
}
@programming_and_coding
57. Add 'n' numbers using array.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum = 0, i, array[100];
clrscr();
printf("Enter total numbers you want to add : ");
scanf("%d", &n);

for (i = 1; i <= n; i++)
{
printf("Enter number %d : ", i);
scanf("%d", &array[i]);
sum = sum + array[i];
}
printf("Sum : %d\n", sum);
getch();
}
@programming_and_coding
58. Program to accept a number and add the digits of that number.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum = 0, remainder;
clrscr();

printf("Enter the number : ");
scanf("%d", &n);

while (n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}

printf("Sum of digits of entered number : %d", sum);
getch();
}
@programming_and_coding
59. Program to accept a number and add the digits of that number using recursion.

#include<stdio.h>
#include<conio.h>

int add_digits(int);

void main()
{
int n, result;
clrscr();
printf("Enter a number : ");
scanf("%d", &n);

result = add_digits(n);

printf("Sum : %d", result);
getch();
}

int add_digits(int n)
{
static int sum = 0;
if (n == 0)
{
return 0;
}
sum = n % 10 + add_digits(n / 10);
return sum;
}
@programming_and_coding
60. Average of numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, i;
float sum=0, x, avg;
clrscr();
printf("Enter total Numbers : ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
printf("\nNumber %d : ", i );
scanf("%f", &x);
sum += x;
}
avg = sum / n;
printf("\nThe Average is : %0.2f", avg);
getch();
}
@programming_and_coding
61. Program to calculate Square of 'n' numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, r, i, sqr=0;
clrscr();
printf("\nEnter the range : ");
scanf("%d", &r);

for (i = 1; i <= r; i++)
{
n = i;
sqr = n * n;
printf("\nSquare of %d is : %d .", n, sqr);
}
getch();
}
@programming_and_coding
62. Program to take an alphabet from user and check whether it is a vowel or not.

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Enter an alphabet : ");
scanf("%c", &ch);

if (ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U')
printf("%c is a vowel.", ch);
else
printf("%c is not a vowel.", ch);
getch();
}
@programming_and_coding
63. Program to take two numbers and check whether they are amicable numbers or not.

#include<stdio.h>
#include<conio.h>

//check function
int check(int a, int b)
{
int s = 0, i;
for (i = 1; i < a; i++)
{
if (a % i == 0)
{
s = s + i;
}
}

if (s == b)
{
s = 0;
for (i = 1; i < b; i++)
{
if (b % i == 0)
{
s = s + i;
}
}

if (s == a)
return 1;
else
return 0;
}
return 0;
}

void main()
{
int a, b;
clrscr();
printf("Enter 1st number : ");
scanf("%d", &a);
printf("Enter 2nd number : ");
scanf("%d", &b);

if (check(a, b))
{
printf("\n%d and %d are Amicable Numbers.", a, b);
}
else
{
printf("\n%d and %d are not Amicable Numbers.", a, b);
}
}
@programming_and_coding
64. Program to accept a number and print the factors of that number.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, i;
clrscr();
printf("Enter a number : ");
scanf("%d", &n);
printf("Factors of %d are : ", n);
for (i = 1; i <= n; ++i)
{
if (n % i == 0)
printf("\n%d ", i);
}
getch();
}
@programming_and_coding
65. Program to accept two integer numbers and print the GCD(Greatest Common Divisor).

#include<stdio.h>
#include<conio.h>
void main()
{
int x, y, m, i;
clrscr();
printf("Enter 1st number : ");
scanf("%d", &x);
printf("Enter 2nd number : ");
scanf("%d", &y);

if (x > y)
m = y;
else
m = x;

for (i = m; i >= 1; i--)
{
if (x % i == 0 && y % i == 0)
{
printf("GCD of two number is : %d", i);
break;
}
}
getch();
}
@programming_and_coding
66. Program to find power of number.

#include<stdio.h>
#include<conio.h>
void main()
{
int base, expo;
int value = 1;
clrscr();
printf("Enter base number : ");
scanf("%d", &base);
printf("Enter exponent number : ");
scanf("%d", &expo);

while (expo != 0)
{
// value = value * base;
value *= base;
--expo;
}
printf("Answer : %d", value);
getch();
}
@programming_and_coding
67. Program to calculate HCF & LCM.

#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, x, y, t, hcf, lcm;
clrscr();
printf("Enter two numbers : ");
scanf("%d%d", &x, &y);

a = x;
b = y;

while (b != 0)
{
t = b;
b = a % b;
a = t;
}

hcf = a;
lcm = (x * y) / hcf;

printf("\nHighest Common Factor of %d and %d : %d", x, y, hcf);
printf("\nLeast Common Multiple of %d and %d : %d", x, y, lcm);
getch();
}
@programming_and_coding
68. Program to find largest among 3 numbers using ternary operator.

#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, big;
clrscr();
printf("Enter 3 numbers : ");
scanf("%d %d %d", &a, &b, &c);

big = (a > b && a > c ? a : b > c ? b : c);
printf("\nThe biggest number is : %d", big);
getch();
}
@programming_and_coding
69. Program to find largest number of 'n' numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, num, i;
int big;
clrscr();
printf("Enter total numbers : ");
scanf("%d", &n);

printf("Number %d : ", 1);
scanf("%d", &big);

for (i = 2; i <= n; i++)
{
printf("Number %d : ", i);
scanf("%d", &num);

if (big < num)
big = num;
}

printf("Largest number is : %d", big);
getch();
}
@programming_and_coding
70. Program to check whether the number is neon number or not.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, sq, i, sum = 0;
clrscr();
printf("Enter the number : ");
scanf("%d", &n);

sq = n * n;

for (i = sq; i > 0; i = i / 10)
sum = sum + i % 10;

if (sum == n)
printf("%d is a neon number.", n);
else
printf("%d is not a neon number.", n);
getch();
}
@programming_and_coding
71. Program to check Niven number (Harshad number).

#include<stdio.h>
#include<conio.h>
void main()
{
int n, d, a, sum = 0;
clrscr();
printf("Enter the number : ");
scanf("%d", &n);

a = n;

while (a > 0)
{
d = a % 10;
sum = sum + d;
a = a / 10;
}

if (n % sum == 0)
printf("\nThe number is Niven Number.");
else
printf("\nThe number is not a Niven Number.");
getch();
}
@programming_and_coding
72. Program to check whether the number is palindrome or not.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, rev = 0, temp;
clrscr();
printf("Enter a number : ");
scanf("%d", &n);

temp = n;

while (temp != 0)
{
rev = rev * 10;
rev = rev + temp % 10;
temp = temp / 10;
}

if (n == rev)
printf("\n%d is palindrome number.", n);
else
printf("\n%d is not palindrome number.", n);
getch();
}
@programming_and_coding
73. Program to check perfect number.

#include<stdio.h>
#include<conio.h>

void main()
{
int n, i = 1, sum = 0;
clrscr();
printf("Enter a number : ");
scanf("%d", &n);

/*The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6.*/

while (i < n)
{
if (n % i == 0)
{
sum = sum + i;
}
i++;
}

if (sum == n)
{
printf("\n%d is a perfect number.", i);
}
else
{
printf("\n%d is not a perfect number.", i);
}
getch();
}
@programming_and_coding
74. Program to find the square root of a number.

#include<math.h>
#include<stdio.h>
#include<conio.h>
void main()
{
double num, result;
clrscr();
printf("Enter number : ");
scanf("%lf", &num);
result = sqrt(num);
printf("Square root of %lf is %lf.", num, result);
getch();
}
@programming_and_coding
75. Program to print sum of 'n' prime numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int n, i = 3, count, c, sum = 2;
clrscr();
printf("Enter total number of prime numbers for addition : ");
scanf("%d", &n);

if (n >= 1)
{
printf("\nFirst %d prime numbers are :", n);
printf("\n2 ");
}
for (count = 2; count <= n;)
{
for (c = 2; c <= i - 1; c++)
{
if (i % c == 0)
break;
}
if (c == i)
{
sum = sum + i;
printf("%d ", i);
count++;
}
i++;
}
printf("\nSum : %d", sum);
getch();
}
@programming_and_coding
76. Program to print sum of factorial series 1/1! + 2/2! +...1/N!

#include<stdio.h>
#include<conio.h>

double sumseries(double);

void main()
{
double number, sum;
clrscr();

printf("Enter the number : ");
scanf("%lf", &number);
sum = sumseries(number);

printf("\nSum of the above series = %lf ", sum);

getch();
}

double sumseries(double m)
{
double sum2 = 0, f = 1, i;
for (i = 1; i <= m; i++)
{
f = f * i;
sum2 = sum2 + (i / f);

if (i == m)
{
printf("%.2lf / %.2lf = %lf", i, f, sum2);
}
else
{
printf("%.2lf / %.2lf + \n", i, f);
}
}
return(sum2);
}
@programming_and_coding