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

Thursday, June 4, 2020

C programming Question ans Answer Day-14

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

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

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

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

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