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

Friday, May 29, 2020

C programming Question and Answer Day -5

16. Program to print first n even numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int i=2, n;
//to print odd numbers set variable i=1
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(i<=n)
{
printf("%d\t",i);
i=i+2;
}
getch();
}

17. Program to accept a number and print that number in reverse order.
Ex:- 1024
Output:- 4201

#include<stdio.h>
#include<conio.h>
void main()
{
int reminder, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(n>0)
{
reminder=n%10;
printf("%d", reminder);
n=n/10;
}
getch();
}

18. Program to accept a number and print sum of it’s digits.

#include<stdio.h>
#include<conio.h>
void main()
{
int reminder, sum=0, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(n>0)
{
reminder=n%10;
sum=sum+reminder;
n=n/10;
}
printf("Sum of digits : %d",sum);
getch();
}

19. Program to take a number from user and check whether it is Armstrong number or not.

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

while(n>0)
{
rem = n%10;
sum = sum+(rem*rem*rem);
n = n/10;
}

if(temp==sum)
printf("Entered number is an Armstrong Number");
else
printf("Entered number is not an Armstrong Number");
getch();
}

20. Program to take number from user and print table of that number.

#include<stdio.h>
#include<conio.h>
void main()
{
int i, n;
clrscr();
printf("Enter number : ");
scanf("%d", &n);
for(i=1; i<=10; i++)
printf("%d × %d = %d\n", n, i, n*i);
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]