Professional Documents
Culture Documents
Class VIII
PROGRAM-2
/*Program to print all the numbers from 1 to n.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf(“\n Enter a number);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
printf(“%d”,i);
1
}
getch();
}
********************************************************************
PROGRAM-3
/*Program to print * 40 times in one line*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=40;i++)
{
printf("*");
}
getch();
}
******************************************************************************************
PROGRAM-4
/*Program to print squares of all numbers from 1 to 10.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sq;
clrscr();
for(i=1;i<=10;i++)
{
sq=i*i;
printf(“\n Squares of %d=%d”,i,sq);
}
getch();
}
*****************************************************************************************
2
PROGRAM-5
/*Program to input a number and print last two digits of number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,d;
printf(“\nEnter a Number”);
scanf(“%d”,&n);
while(n>10)
{
d=n%10;
printf(“\n%d”,d);
n=n/10;
}
getch();
}
****************************************************************************************
PROGRAM-6
/*Program to Find Sum of Digits of a Number using While Loop */
#include <stdio.h>
#include<conio.h>
void main()
{
int n, d, sum=0;
clrscr();
printf("\n Enter a number");
scanf("%d", &n);
while(n > 0)
{
d= n% 10;
sum = sum+ d;
n = n/ 10;
}
printf("\n Sum of the digits of Number = %d", sum);
getch();
}
****************************************************************************************
PROGRAM-7
3
/*Program to input a number and print all the digits in separate lines*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,d;
printf(“\nEnter a number”);
scanf(“%d”,&n);
while(n!=0)
{
d=n%10;
printf(“\n %d”,d);
n=n/10;
}
getch();
}
****************************************************************************************
PROGRAM-8
/*Program to input a number and check whether no is Armstrong or not.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,res,m,sum=0;
clrscr();
printf(“Enter a number”);
scanf(“%d”,&n);
res=n;
while(n>0)
{
m=n%10;
sum=sum+m*m*m;
n=n/10;
}
if(sum==res)
printf(“%d number is an Armstrong number”,res);
else
printf(“%d number is not an Armstrong number”,res);
getch();
4
}
****************************************************************************************
PROGRAM-9
/*Program to input 10 numbers and print the sum and average of numbers. */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
float avg=0;
printf("\n Enter 10 Numbers:\n");
for(i=1;i<10;i++)
{
scanf(“%d”,&n);
sum = sum +n;
}
avg=sum/10;
printf("\nSum of the Numbers = %d", sum);
printf("\nAverage of the Numbers = %f",avg);
getch();
}
************************************************************************
PROGRAM-10
/*Program to input 10 numbers and print out largest among them. */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,l=0;
printf(“\nEnter 10 numbers”);
for(i=1;i<=10;i++)
{
scanf(“%d”,&n);
if(n>l)
{
l=n;
}
}
5
printf(“The largest no is=%d”,l);
getch();
}
****************************************************************************************
PROGRAM-11
PROGRAM-13
PROGRAM-15