c program to get the number and check if that is prime if that is prime print it's square
Answers
Answer:
#include<stdio.h>
int main()
{
int n, i = 3, count, c;
printf("Enter the number of prime numbers required\n");
scanf("%d",&n);
if ( n >= 1 )
{
printf("First %d prime numbers are :\n",n);
printf("2\n");
}
for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf("%d\n", i);
count++;
}
i++;
}
int main()
{
int number, Square;
printf(" \n Please Enter any prime no Value : ");
scanf("%d", &number);
Square = number * number;
printf("\n Square of a given number %d is = %d", number, Square);
return 0;
}
Program:
#include <stdio.h>
int main(){
int number, i;
boolean flag = false;
printf("Enter a positive number: ");
scanf("%d", &number);
if (number == 1) {
printf("1 is neither a prime nor a composite number.");
}else{
for(i = 2; i <= number/2; ++i){
if( number % i == 0){
flag = true;
break;
}
}
if ( !flag )
printf("%d is a prime number, and its square is.",( number * number ));
else
printf("%d is not a prime number.", number);
}
}
return 0;
}
Output-1:
Enter a positive number: 29
29 is a prime number.
Output-2:
Enter a positive number: 1
1 is neither a prime nor a composite number.
Output-3:
Enter a positive number: 28
28 is not a prime number.
Explanation:
- This program will take input from user and checks weather it is a prime number or not if it it then it prints its square
- it also check weather the given number is 1 or not if true then print 1 is neither prime nor composite number
----Hope you got what you wanted, if you like my program on c for checking prime and if it is then printing its square mark my answer as brainliest
:)