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();
}
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();
}
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);
}
}
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();
}
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();
}
#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();
}
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();
}
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);
}
}
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();
}
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();
}
0 comments:
Post a Comment