In: Computer Science
Objectives
Program 1:
Program 2:
## in C Language only ##
PROGRAM 1:
CODE:
#include <stdio.h>
int main() {
int n=-1;
printf("Enter a number: ");
while(n<0)
{ scanf("%d",&n);
if(n<0)
{
printf("Retry: ");
}
else
{
break;
}
}
for(int i=0;i<=n;i++)
{
if(i%5==0)
{
printf("%d ",i);
}
}
return 0;
}
SCREENSHOT OF CODE and OUTPUT:
PROGRAM 2:
CODE:
#include <stdio.h>
#include<math.h>
int main() {
int n=-1;
printf("Enter a number N: ");
while(n<0)
{ scanf("%d",&n);
if(n<0)
{
printf("Retry: ");
}
else
{
break;
}
}
float c=-1;
printf("Enter a number C: ");
while(c<0)
{ scanf("%f",&c);
if(c<0)
{
printf("Retry: ");
}
else
{
break;
}
}
for(int i=0;i<=n;i++)
{
if(fmod(i,c)==0)// fmod is a predefined function to find mod with float {
printf("%d ",i);
}
}
return 0;
}
SCREENSHOT OF CODE:
OUTPUT:
I hope I solved your query. In case of doubt feel free to ask in comment section.