Find the best tutors and institutes for C Language

Find Best C Language Classes

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

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  

IT Courses/Programming Languages/C Language

Follow 8

7 Answers

Please enter your answer


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


Check with the attachment

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; }


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; }

Computer Programming Trainer

#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; }


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

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

View 5 more Answers

Related Questions

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

Ask a Question

Related Lessons

Some Tricky Questions in C
Can you write two functions in which one executes before main function and other executes after the main function? #pragma startup #pragma exit Where, priority is optional integer value.For user priority...

Sahana D. | 16 Feb

0 0

Program to swap the value of two variables without using third variable(simplest way)...
int main() { int a=10,b=20; printf("values of a before swap ="%d,a); printf("values of b before swap ="%d,b); a=a+b; b=a-b; a=a-b; printf("******************"); printf("values of a after swap...

Rohan | 17/11/2018

2 0

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

Recommended Articles

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Applications engineering is a hot trend in the current IT market. An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company s manufacturing, marketing, sales, and customer...

Read full article >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

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 >

Looking for C Language Classes?

Find best C Language Classes in your locality on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you

Find Best C Language Classes?

Find Now » is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on, to fulfill their learning requirements across 1,000+ categories. Using, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on 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