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

Why is C programming language called C?
The C programming language is named "C" because it is a successor to the B programming language. The B language was developed at Bell Labs by Ken Thompson and Dennis Ritchie. When they created C, they...
Ashwini
0 0
6
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
Which is the best C language IDE/compiler for Windows?
Let us now check out some of the famous and best-working IDEs available. Visual Studio Code. Visual Studio Code is one of the most popular IDEs and is open-source software developed by Microsoft....
Deepashri
0 0
5
Is it valid to address one element beyond the end of an array?
No, array is a fixed size memory allocation for variables. It is illegal to access elements beyond the allocated space.
Shivani
how the right shift operator works on a numerical value?? eg:- 8>>3=?
first convert numerical value to binary value then arrange into bits and shift 3 bit on right then convert binary value to decimal value.
Abhishek

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

Ask a Question

Related Lessons

Storage classes in c
Storage classes determine the scope and life time of a variable. Scope is defined as the region over which the defined variable is accessible. Lifetime is the time during which the value of a variable...

C Program-Infinite Loop[For] Demo
//Header Files #include<stdio.h>#include<conio.h> //Main function void main(){ //Function for clearing screen clrscr(); //Infinite for loop for(;;) { printf("Hello!"); } //Function for...

Features Of C Language
Features of C language It is a robust language with rich set of built-in functions and operators that can be used to write any complex program. The C compiler combines the capabilities of an assembly...

Functions In C Programming
A C-language program is nothing but collection of Function, these are the building blocks of a ‘C’ program. Generally, a function mans a task. “Function is a...

C Programming basics
C PROGRAMMING BASICS 10 Hours Introduction to ‘ C’ programming –fundamentals – structure of a ‘C’...
O

Om K.

0 0
0

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