Monday, December 16, 2019

C solved practical slips of F.Y.B.Sc. Computer Science

C solved practical slips of F.Y.B.Sc. Computer Science:

Program 1:
Title:To demonstrate the use of data types and simple operators

#include
#include
void main()
{
float fahr,cel=0,kel=0;
clrscr();
printf(“\n Enter temperature in Fahrenheit:”);
scanf(“%f”,&fahr);
cel=((5.0/9)*(fahr-32));
kel=cel+273.15;
printf(“\n Temperature in 1 elsius is %0.2f”,cel);
printf(“\n Temperature in kelvin is %0.2f”,kel);
getch();
}

Output:
Enter the temperature in Fahrenheit:50
Temperature in Celsius is 10.00
Temperature in Kelvin is 283.15



Program no: 2
Title:To demonstrate the use of if, if-else statements

#include
#include
void main()
{
int year;
clrscr();
printf(“\n Enter the year:”);
scanf(“%d”,&year);
if(year%4==0 && year%10!=0 || year%400==0)
printf(“\n %d is leap year”,year);
else
printf(“\n %d is not leap year”,year);
getch();
}

Output:
Enter the year:1994
1994 is not leap year
Enter the year:2004
2004 is leap year




Program no: 3
Title:To demonstrate the use of switch case

#include
#include
void main()
{
int n;
float rad;
clrscr();
printf(“\n Enter the radius:”);
scanf(“%f”,&rad);
printf(“\n Enter your choice:”);
printf(“\n 1.Area of circle”);
printf(“\n 2.Circumference of circle \n 3.Volume of circle:\t”);
scanf(“%d”,&n);
switch(n)
{
case 1:printf(“\n Area of circle=%0.2f”,3.14*rad*rad);
break;
case 2:printf(“\n Circumference of circle=%02f”,2*3.14*rad);
break;
case 3:printf(“\n Volume of of circle=%0.2f”,1.334*3.14*rad*rad*rad);
break;
default:printf(“Invalid choice”);
}
getch();
}

Output:
Enter radius:2
Enter your choice:
1. Area of circle
2. Circumference of circle
3. Volume of circle
Entre your choice:1
1. Area of circle: 12.56


Program no: 4
Title:To demonstrate the use ofloops


#include
#include
void main()
{
int n,a=1,b=1,c;
clrscr();
printf(“\n Enter the last number:”);
scanf(“%d”,&n);
printf(“\n Fibnoacci series is:\t%d\t%d”,a,b);
do
{
c=a+b;
printf(“\t%d”,c);
a=b; b=c;
}while(c<=n);
getch();
}

Output:
Enter the last number:50
Fibnoacci series is:1 1 2 3 5 8 13 21 34 55



Program no: 5
Title:To demonstrate the use of looping structures

#include
#include
void main()
{
int a,b,c,sum=0,x;
clrscr();
printf(“\n The Armstrong number between the range 1 & 500 are:\n”);
for(x=1;x<=500;x++)
{
a=x; sum=0;
do
{
b=a%10;
sum+=(b*b*b);
a=a/10;
}while(a!=0);
if(sum==x)
printf(“\t%d”,x);
}
getch();
}

Output:
The Armstrong number between the range 1 & 500 are:
1 153 370 371 407

Study testing conditions: if, elif, else in python

Testing conditions: if, elif, else :

In Python, we have the if, elif and the else statements for decision making to execute a certain line of codes if a condition is satisfied,and a different set of code in case it is not.

This is the simplest example of a conditional statement. The syntax is:

if(condition):
      indented Statement Block

The block of lines indented the same amount after the colon (:) will be executed whenever the condition is TRUE.


For example, lets say you are recording the score for a certain course.
The total score is 100, with 50 points for the theoretical work and 50 for practical.
You want to display an error message or warning if the score exceeds 100.

score_theory = 40
score_practical = 45
if(score_theory + score_practical > 100):
    print("Invalid score. Please check the input.")
The colon (:) is important because it separates the condition from the statements to be executed after the evaluation of the condition.


The above if statement checks for the 'if' condition and determines the statement
(40 + 45 = 85) > 100 to be FALSE and thus, will not print the warning.
Lets make the statement FALSE and see what happens:

score_theory = 50
score_practical = 55
if(score_theory + score_practical >= 100):
    print("Invalid score. Please check the input.")

Output:
Invalid score. Please check the input.




if-else Statement
 The syntax for the if-else statement is:

if(condition):
      Indented statement block for when condition is TRUE
else:
      Indented statement block for when condition is FALSE

example:
score_theory = 40
score_practical = 45
if(score_theory + score_practical > 100):
    print("Please check the input. Score exceeds total possible score.")
else:
    print("Score validated. Your total is: ", score_theory + score_practical)




Output:

Score validated. Your total is:  85



Multiple tests: if-elif-else Statement:

The syntax followed by the if-else-if statement is:

if(Condition1):
      Indented statement block for Condition1
elif(Condition2):
       Indented statement block for Condition2
else:
       Alternate statement block if all condition check above fails


Example:
coursework = "English"
score_theory = 53
score_practical = 35

if(coursework == "Science" or coursework == "science"):
    if(score_theory > 50):
        print("Please check the input score for 'Science: Theory'.")
    elif(score_practical > 50):
            print("Please check the input score for 'Science: Practical'.") 
    else:
        print("Score validated for Science. Your total is: ",score_theory + score_practical)           
elif(coursework == "English" or coursework == "english"):
    if(score_theory > 60):
        print("Please check the input score for 'English: Theory'.")
    elif(score_practical > 40):
            print("Please check the input score for 'English: Practical'.") 
    else:
        print("Score validated for English. Your total is: ",score_theory + score_practical)
else: print("Coursework not recognized. Please enter score for either Science or English.")

Output:
Score validated for English. Your total is:  88

Variables and objects in python

Learn variables and objects in python:

In Python, values are stored in objects.
If we do
d = 10.0
a new object d is created. As we have given it a floating point value (10.0) the object is of type floating point.
If we had defined d = 10, d would have been an integer object.
In other programming languages, values are stored in variables.
This is not exactly the same as an object, as an object has "methods", that means functions that belong to the object.

There are many object types in Python.

The most important to begin with are:

Object type: Integer
Type class name: int
Description: Signed integer, 32 bit
Example: a = 5

Object type: Float
Type class name: float
Description: Double precision floating point number, 64 bit
Example:b = 3.14

Object type: Complex
Type class name: complex
Description: Complex number
Example: c = 3 + 5j
  c= complex(3,5)


Object type: Character
Type class name: chr
Description:  Single byte character
Example: d = chr(65)
d = 'A'
d = "A"

Object type: String
Type class name: str
Description: List of characters, text string
Example: e = 'LTAM'
e = "LTAM"

A python program to ask the user for his name and greets him

Write a python program to ask the user for his name and greets him:

Answer:
s = raw_input("What is your name?")
print "HELLO ", s

Output:
What is your name?Tom
HELLO Tom

A python program to draw hexagon using Turtle Programming

Write a python program to draw hexagon using Turtle Programming :

Answer:

import turtle 
polygon = turtle.Turtle()
 
num_sides = 6
side_length = 70
angle = 360.0 / num_sides 
 
for i in range(num_sides):
    polygon.forward(side_length)
    polygon.right(angle)
     
turtle.done()

A python program to draw star using Turtle Programming

Write a python program to draw star using Turtle Programming :


Answer:

import turtle 
 
star = turtle.Turtle()
 
for i in range(50):
    star.forward(50)
    star.right(144)
     
turtle.done()

A python program to draw square using Turtle Programming

Write a python program to draw square using Turtle Programming

Answer:

import turtle 
skk = turtle.Turtle()
 
for i in range(4):
    skk.forward(50)
    skk.right(90)
     
turtle.done() 

List of bank names in India

 Here is a comprehensive list of banks in India, categorized by type: