Write a program to enter any 50 numbers and check whether they are divisible by 5 or
not. If divisible then perform the following tasks:
(a) Display all the numbers ending with the digit 5.
(b) Count those numbers ending with 0 (zero).
Answers
Answer:
#include <iostream>
using namespace std;
int main()
{
int n[50], count=0;
cout<<"Enter 50 numbers\n";
for(int i=0;i<50;i++)
{
cin>>n[i];
}
cout<<"Numbers ending with 5 are\n";
for(int i=0;i<50;i++)
{
if(n[i]%5==0)
{
if(n[i] % 10 == 5)
{
cout<<n[i]<<"\n";
}
else
{
count++;
}
}
}
cout<<"There are "<<count<<" numbers ending with zero";
return 0;
}
Question:-
Write a program to enter any 50 numbers and check whether they are divisible by 5 or
not. If divisible then perform the following tasks:
- Display all the numbers ending with the digit 5.
- Count those numbers ending with 0 (zero).
Program:-
This is written in Java.
import java.util.*;
class Number
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 50 numbers.");
int c=0;
int n[]=new int[50];
for(int i=0;i<50;i++)
{
System.out.print("Enter: ");
n[i]=sc.nextInt();
if(n[i]%10==0)// last digit is zero implies that number is divisible by 5.
c++;
}
System.out.print("Numbers ending with digit 5 are: ");
for(int i=0;i<50;i++)
{
if(n[i]%10==5)
System.out.print(n[i]+" ");
}
System.out.println("Total numbers ending with 0 is: "+c);
}
}