programming like c, c++, java,python learn in free

Thursday, June 4, 2020

C programming Question and Answer Day-13

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();
}
Share:

0 comments:

Post a Comment

Unordered List

recentposts1
Powered by Blogger.

Text Widget

Featured Post

C programming Question and Answer Day-15

71. Program to check Niven number (Harshad number). #include<stdio.h> #include<conio.h> void main() {     int n, d, a, su...

Search This Blog

recent comments

recentcomments

Labels

[slideshow][technology]

vertical posts

[verticalposts][technology]

business

[business][grids]

ad space

ads 600

vehicles

[cars][stack]
[verticalposts][food]

our facebook page

about us

logo

Jupiter is a magazine responsive Blogger template. It has everything you need to make your blog stand out. This template is fully customizable and very flexible and we believe you will love it as much as we do.

Slide show

[people][slideshow]

health

[health][btop]

recent posts

recentposts1

Subscribe Us

random posts

randomposts2

Blog Archive

Recent Posts

top ads

Unordered List

recent

Pages

Theme Support

[socialcounter] [facebook][#][215K] [twitter][#][115K] [youtube][#][215,635] [rss][#][23M] [linkedin][#][21.5K] [instagram][#][600,300]