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