what seems to be wrong with this C program. Please debug it for me. Copy-paste the new source code then provide a screenshot that yours is working   here is the code: #include int main() {     //prompting user for non negative integer     printf("Enter a non-negative integer number: ");     //reading number     int n;//to store number     scanf("%d",&n);//reading integer          //now finding integer is prime or not     //note: a number is prime it is divisible by 1 and the number itself     int flag=1;//initially assuming n is prime, 1:prime, 0:not prime     //now checking if any other number other than 1 and n, divides n, then it is not prime     for(int i=2;i

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

what seems to be wrong with this C program. Please debug it for me. Copy-paste the new source code then provide a screenshot that yours is working

 

here is the code:

#include <stdio.h>
int main()
{
    //prompting user for non negative integer
    printf("Enter a non-negative integer number: ");
    //reading number
    int n;//to store number
    scanf("%d",&n);//reading integer
    
    //now finding integer is prime or not
    //note: a number is prime it is divisible by 1 and the number itself
    int flag=1;//initially assuming n is prime, 1:prime, 0:not prime
    //now checking if any other number other than 1 and n, divides n, then it is not prime
    for(int i=2;i<n;i++)//i is from i=2 to n-1
        if(n%i==0)//if such i found, (i divides n)
            {//then n is to prime, since we found i that divides n, where i is not 1 and n
                flag=0;//setting flag to 0, indicates it is not prime
                break;//breaking loop
            }
    //displaying output
    if(flag==1)//flag 1 means n is prime
    {
        printf("%d is a prime number\n",n);
    }
    else{//flag=0 means n is not prime
        printf("%d is a non-prime number\n",n);
    }
    return 0;
}

output:

C:\Users\Pluto\Documents\mp6\CCG-MP7.c - Dev-C++ 5.11
File
Edit
Search View Project Execute Tools AStyle Window Help
目唱
品口国盟
TDM-GCC 4.9.2 64-bit Release
(globals)
Project Classes Debug
CCG-MP6.c CCG-MP7.c
1
#include <stdio.h>
2
int main()
3E {
//prompting user for non negative integer
printf("Enter a non-negative integer number: ");
//reading number
int n;//to store number
scanf("%d",&n);//reading integer
4
6
7
9
//now finding integer is prime or not
//note: a number is prime it is divisible by 1 and the number itself
int flag=1;//initially assuming n is prime, 1:prime, 0:not prime
//now checking if any other number other than 1 and n, divides n, then it is not prime
for (int i=2;i<n;i++)//i is from i=2 to n-1
if(n%i==0)//if such i found, (i divides n)
10
11
12
13
14
15
16 E
{//then n is to prime, since we found i that divides n, where i is not 1 and n
flag=0;//setting flag to 0, indicates it is not prime
break;//breaking loop
17
18
19
//displaying output
if(flag==1)//flag 1 means n is prime
{
printf("%d is a prime number\n",n);
}
else{//flag=0 means n is not prime
printf("%d is a non-prime number\n",n);
}
return e;
20
21
22 E
23
24
25 =
26
27
28
29
}
30
31
output:
88 Compiler (5)
Resources dih Compile Log Debug a Find Results Close
Line
Col
File
Message
C:\Users\Pluto\Documents\mp6\CCG-MP7.c
C:\Users\Pluto\Documents\mp6\CCG-MP7.c
C:\Users\Pluto\Documents\mp6\CCG-MP7.c
In function 'main':
[Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
[Note] use option -std=c99, -std=gnu99, -std=c11 or -std3gnu11 to compile your code
14
14
5
C:\Users\Pluto\Documents\mp6\CCG-MP7.c
C:\Users\Pluto\Documents\mp6\CCG-MP7.c
At top level:
31
[Error] expected '=', ',',|
", 'asm' or '_attribute_' before ':' token
Line:
20
Col: 24
Sel: 0
Lines: 31
Length: 1078
Insert
Done parsing in 0.016 seconds
8:41 pm
IN
O Type here to search
DEV
! 21°C
O 4»)) A ENG
PC
30/01/2022
Transcribed Image Text:C:\Users\Pluto\Documents\mp6\CCG-MP7.c - Dev-C++ 5.11 File Edit Search View Project Execute Tools AStyle Window Help 目唱 品口国盟 TDM-GCC 4.9.2 64-bit Release (globals) Project Classes Debug CCG-MP6.c CCG-MP7.c 1 #include <stdio.h> 2 int main() 3E { //prompting user for non negative integer printf("Enter a non-negative integer number: "); //reading number int n;//to store number scanf("%d",&n);//reading integer 4 6 7 9 //now finding integer is prime or not //note: a number is prime it is divisible by 1 and the number itself int flag=1;//initially assuming n is prime, 1:prime, 0:not prime //now checking if any other number other than 1 and n, divides n, then it is not prime for (int i=2;i<n;i++)//i is from i=2 to n-1 if(n%i==0)//if such i found, (i divides n) 10 11 12 13 14 15 16 E {//then n is to prime, since we found i that divides n, where i is not 1 and n flag=0;//setting flag to 0, indicates it is not prime break;//breaking loop 17 18 19 //displaying output if(flag==1)//flag 1 means n is prime { printf("%d is a prime number\n",n); } else{//flag=0 means n is not prime printf("%d is a non-prime number\n",n); } return e; 20 21 22 E 23 24 25 = 26 27 28 29 } 30 31 output: 88 Compiler (5) Resources dih Compile Log Debug a Find Results Close Line Col File Message C:\Users\Pluto\Documents\mp6\CCG-MP7.c C:\Users\Pluto\Documents\mp6\CCG-MP7.c C:\Users\Pluto\Documents\mp6\CCG-MP7.c In function 'main': [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode [Note] use option -std=c99, -std=gnu99, -std=c11 or -std3gnu11 to compile your code 14 14 5 C:\Users\Pluto\Documents\mp6\CCG-MP7.c C:\Users\Pluto\Documents\mp6\CCG-MP7.c At top level: 31 [Error] expected '=', ',',| ", 'asm' or '_attribute_' before ':' token Line: 20 Col: 24 Sel: 0 Lines: 31 Length: 1078 Insert Done parsing in 0.016 seconds 8:41 pm IN O Type here to search DEV ! 21°C O 4»)) A ENG PC 30/01/2022
MACHINE PROBLEM No. 7
Write a program to test if a non-negative integer number is prime or not.
Sample Output 1:
Enter a non-negative integer number: 11
11 is a prime number
Sample Output 2:
Enter a non-negative integer number: 15
15 is a non-prime number
Transcribed Image Text:MACHINE PROBLEM No. 7 Write a program to test if a non-negative integer number is prime or not. Sample Output 1: Enter a non-negative integer number: 11 11 is a prime number Sample Output 2: Enter a non-negative integer number: 15 15 is a non-prime number
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY