UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I write a C program to print the total number of a single-digit prime number using a loop?

Asked by Last Modified  

7 Answers

Learn C Language

Follow 8
Answer

Please enter your answer

Tutor

total number of single digit prime number that means your prime number starts from 2 and less than 9 so you can take loop for this range
Comments

Tutor

Check with the attachment
Comments

Online Computer Trainer

#include"stdio.h" int main() { int count,i; for(i=2;i<10;i++) { count = 0; for(j=2;j<=i/2;j++) if(i % j == 0) count++; if(count == 0) printf("\t %d",i); } return 0; }
Comments

Trainer

int main() { int x=0; for (int i=0;i<10;i++) { for(int j=0;j<=1%2;j++) { if(i/j==0) { x+=1; } } if(x<=2) { printf("%d",i); } } getch(); return 0; }
Comments

Computer Programming Trainer & Instructor

#include"stdio.h" #include"conio.h" int main() { for(int i=2;i<=9;i++) { for(int j=2;j<=i;j++) { if(i%j!=0) { printf(“%d ”,i); } } } return 0; }
Comments

Tutor | Python | Data Science | Machine Learning Trainer | Pandas | R | C | C++ | Computer Classes

Single Digit prime number means number from 0 to 10 which are prime. so write for loop which will iterate from 0 to 10 as the value of i your i is nothing but the number pass the value of i to function prime(int) it will check if it is prime and print if it is
Comments

Advance Excel And VBA Training

We can solve it in two ways 1st Way: ''''''''''''''' It's easy, prime number means it should not be divisible by any number itself and 1. The basic logic dictates that we divide and check each number by numbers of half the value of the number we are checking. confused? here's an example. if we...
read more
We can solve it in two ways 1st Way: ''''''''''''''' It's easy, prime number means it should not be divisible by any number itself and 1. The basic logic dictates that we divide and check each number by numbers of half the value of the number we are checking. confused? here's an example. if we are checking number n (say) for prime, then we run the loop from 2 to n/2! since here we are only checking for single digits , our n has values from 1 to 9. Below is the Code: //assuming all variables declared and all header files included for ( int i = 1; i<=9;i++){ flag = 0; //to check for divisibility for ( int j= 2; j<=i/2;j++){ if (i%j==0){ flag++; // value changes if divisible } } if ( flag==0){ // check for change of value printf("%d",i); } } 2nd Way: ''''''''''''''' for(int i=2; i<=9; i++) { int count=0; for(int j=2;j<=sqrt(i);j++) { if(i%j==0) { count++; break; } } if(count==0) cout<read less
Comments

View 5 more Answers

Related Questions

How are portions of a program disabled in demo versions?
By inserting comments in the program Single line comment denoted by // Multi line comment denoted by /* */
Akhilesh
0 0
5
In how many days can we learn the C language?
Around one month and depends upon you how much time you give.
Ravi Shankar
0 0
9
When is a "switch" statement better than multiple "if" statements?
switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type. For instance, rather than the code if (x == 1) printf(“x...
Shalu
Why should I learn Python over C or C++?
There are definite differences. C++ is a strongly typed language and Python is not. There's no need to declare variables. ... (I generally don't like languages to be dependent on any kind of formatting,...
Sajini
What is the output of the below: printf("%d", printf("Hello"));
The output would be as follows: Hello5 Reason: 'printf( )' not only prints a given strings, but it also returns a number which is the count of the number of characters that it has successfully printed...
Pravalika

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Recommended Articles

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more