Data Structure lab 2

                                                    LAB 02

                                             Data Structure Lab


             Task :1 Part 1

   #include<iostream>
using namespace std;
void main(){
       int count = 0;
       int n ,flag=0;

       cout << "Enter any integer: ";
       cin >> n;
       for (int i =2; i<=n-1; i++){
              if (n%i == 0){
                     flag = 1;
              }
              count++;
       }
       if (flag == 0){
              cout << "Number is prime"<<endl;
       }
       else{
              cout << "Number is not prime" << endl;
       }
       cout << "Loop runs " << count << " times" << endl;
       system("pause");
}

Task 2:



 post the screen shot of given inputs

Task 1:Part 2

#include<iostream>
#include<math.h>
using namespace std;
void main(){
       int count = 0;
       int n ,flag=0;

       cout << "Enter any integer: ";
       cin >> n;
       for (int i =2; i<=sqrt(n-1); i++){
              if (n%i == 0){
                     flag = 1;
              }
              count++;
       }
       if (flag == 0){
              cout << "Number is prime"<<endl;
       }
       else{
              cout << "Number is not prime" << endl;
       }
       cout << "Loop runs " << count << " times" << endl;
       system("pause");
}

Task:2

post the screen shot of given inputs




Comments

Popular posts from this blog

Computer Programming Lab 5

Computer Programming lab 11

Computer Programming Lab 4