1:-Write A Program in Python To Check The Number Is Prime or Not.?
1:-Write A Program in Python To Check The Number Is Prime or Not.?
prime or not.?
# Program to check if a number is prime or not
num = 29
2:- Example to check whether an integer is a prime number or not using for loop
and if...else statement.?
#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
if (n == 1) {
printf("1 is neither prime nor composite.");
}
else {
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}
return 0;
}
Output
Enter a positive integer: 29
29 is a prime number.
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
return 0;
}
Output
Enter an integer: -7
-7 is odd.
#include <stdio.h>
void main()
int j, sum = 0;
sum = sum + j;
printf("%d ",j);
Copy
Sample Output:
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
Write a program in python to print the largest number among three numbers?
# Python program to find the largest number among the three input numbers
Output
The largest number is 14.0
6:- Write an if statement that asks for the user's name via input() function. If the
name is "Bond" make it print "Welcome on board 007." Otherwise make it print
"Good morning NAME". (Replace Name with user's name) .
def count_l(a):
c=0
for i in a.split():
if i[0].lower() == a:
c = c+1
else:
pass
return c
print(count_l(str))
# include<iostream>
using namespace std ;
int serviceyear ,salary ;
cout<<" Dear employee please enter ur Salary ";
cin>>salary ;
cout<<"Dear employee please enter ur serviceyear ";
cin>>serviceyear;
if(serviceyear>5)
{
cout<<"(Total salary)+(bonus) "<<salary*serviceyear+(salary*5/100);
}else
{
9:- Take input of age of 3 people by user and determine oldest and youngest
among them.
#include <stdio.h>
main ()
{
int a,b,c;
printf("\nType the ages of a,b,c:");
//correct format of scanf
scanf("%d %d %d",&a,&b,&c);
if ((a>b) && (a>c))
{
printf("\nThe biggest age is A");
}
else
{
printf("\nThe lesser age is A");
}
//(b>a) && (b>c)
if ((b>a) && (b>c))
{
printf("\nThe biggest age is B");
}
Else
{
printf("\nThe lesser age is B");
}
if ((c>a) && (c>a))
{
printf("\nThe biggest age is C");
}
else
{
printf("\nThe lesser age is C");
}
return 0;
}
10:- You are given with a list of integer elements. Make a new list which will
store square of elements of previous list.
print(nums)
print(square_nums)
print(cube_nums)
Copy
Sample Output:
Original list of integers:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
class Circle():
self.radius = r
def area(self):
return self.radius**2*3.14
def perimeter(self):
return 2*self.radius*3.14
NewCircle = Circle(8)
print(NewCircle.area())
print(NewCircle.perimeter())
Copy
Sample Output:
200.96
50.24
12:- Create a Student class and initialize it with name and roll number. Make
methods to : 1. Display - It should display all informations of the student. 2.
setAge - It should assign age to student 3. setMarks - It should assign marks to
the student.
class Student():
def __init__(self,name,roll):
self.name = name
self.roll= roll
def display(self):
print self.name
print self.roll
def setAge(self,age):
self.age=age
def setMarks(self,marks):
self.marks = marks