Find the best tutors and institutes for C Language

Find Best C Language Classes

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?

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

Tutor

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

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

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

Tutor

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

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

Related Questions

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

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

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

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...
Find C Language Classes near you

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 »

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 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 6.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