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  

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

What is the actual size of INT in the C language, 2 or 4 bytes?
The actual size to int is determined by the compiler as the program runs. But theoretically the size is 2 bytes. You can increase the size by adding keyword long infront of it to make the size 4 bytes. Eg int a; // 2 bytes Long int b; // 4 bytes
Kunal
How can I learn C easily and rapidly?
You can learn C by three ways 1. Practise 10 programs daily for 10 days. 2. Understand the programming concept before going to make an attempt 3. Try to do some simple projects on your own will improve your skills rapidly.
Umamahesh
0 0
5
How do you print an address?
int main(){ int a=5; printf("Address of variable a is: %d",&a); return 0; }
Prakash
2 0
6
what is the significance of lvalue?
An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).
Abhishek
What is = and == in C language?
= is assignment operator while ==is comparision operator
Sayed
0 0
6

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

Ask a Question

Related Lessons

Find out the Output of the following with reason and get C Language Training fess less by 10%
1. void main() { clrscr(); printf(5+"Beautifull"); getch(); } 2. void main() { int a=50; clrscr(); ...

Programming Practice Technique
Any Programming Language required an Algorithm. Algorithm - It is the finite set of instructions in which each and every instruction has the meaning, instructions are not ambiguous and all the instructions...

An Interesting discussion about malloc( ) and calloc( )
What are malloc( ) and calloc( )? Simply putting they are the predefined functions in C language. Malloc( ) and calloc( ) are two such functions which are used for more or less identical purpose and...

Efficient Learning Strategies
Type your notes after class Write your notes onto flashcards - Scrabble -Make posters Review flashcards while walking, at gym, etc. Dog-ear pages in the reading where you can find...

Compiler vs Interpreter
Compiler Interpreter Convert all the code into binary format and execute. Convert one statement at a time and execute, then Convert next statement and execute. After conversion, source...

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