You are on page 1of 8

Lucknow Public College

Class VIII

Sub:- Computer Science

Ch- 5 Decision Making and Looping


PROGRAM-1
/*Program to print your name 10 times*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("\n My name is Madhvi Mani");
}
getch();
}
*****************************************************************************************

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 to input 10 numbers and print out smallest among them.


*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,s;
printf(“\nEnter 10 numbers”);
for(i=1;i<=10;i++)
{
scanf(“%d”,&n);
if(n<s)
{
s=n;
}
}
printf(“\nThe smallest no is=%d”,s);
getch();
}
****************************************************************************************
PROGRAM-12

/*Program to input 10 numbers and print out sum of the negative


numbers. */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
printf(“\nEnter 10 numbers”);
for(i=1;i<=10;i++)
{
scanf(“%d”,&n);
6
if(n<0)
{
sum=sum+n;
}
}
printf(“\nThe sum of the negative numbers is=%d”,sum);
getch();
}
****************************************************************************************

PROGRAM-13

/*Program to input 10 numbers and print out sum of the positive


numbers. */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
printf(“\nEnter 10 numbers”);
for(i=1;i<=10;i++)
{
scanf(“%d”,&n);
if(n>0)
{
sum=sum+n;
}
}
printf(“\nThe sum of the positive numbers is=%d”,sum);
getch();
}
****************************************************************************************
PROGRAM-14

/*Program to input 10 numbers and print out sum of the even


numbers. */
#include<stdio.h>
#include<conio.h>
void main()
{
7
int n,i,sum=0;
for(i=1;i<=10;i++)
{
printf(“\nEnter a number”);
scanf(“%d”,&n);
if(n%2==0)
{
sum=sum+n;
}
}
printf(“\nThe sum of the even numbers is=%d”,sum);
getch();
}
****************************************************************************************

PROGRAM-15

/*Program to input 10 numbers and print out sum of the even


numbers. */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
printf(“\nEnter 10 numbers”);
for(i=1;i<=10;i++)
{
scanf(“%d”,&n);
if(n%2!==0)
{
sum=sum+n;
}
}
printf(“\nThe sum of the odd numbers is=%d”,sum);
getch();
}
****************************************************************************************

You might also like