# PSUDO Code Examples

0
194

#### Problem:1

##### psudo code:
• Take the length of rectangle from user.
• Take the width of rectangle from user.
• Find the area of rectangle by this formula: area=length*width
• find the perimeter of rectangle using this formula: perimeter=2*(length+width) ##### program of problem 1

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

float width,length,peri,area;

printf(“Enter the length of rectangle:”);

scanf(“%f”,&length);

printf(“Enter the width of rectangle:”);

scanf(“%f”,&width);

area=length*width;

printf(“The area of rectangle is:%f”);

peri=2*(length+width);

printf(“the perimeter of rectangle is:%f”);

getch();

return 0;

}

#### Problem 2

##### psudo code
• Take the salaries of eight employees as a input from the user one by one.
• Calculate the average salary of employees by average=sum of salaries of eight employees/8 ##### program of problem 2

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

int s1,s2,s3,s4,s5,s6,s7,s8;

float avg;

printf(“enter the salaries of eight of employees one by one”);

scanf(“%d%d%d%d%d%d%d%d”,&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8);

avg=(s1+s2+s3+s4+s5+s6+s7+s8)/8;

printf(“%d”,avg);

getch();

return 0;

}

Problem 3

##### psudo code
• Take the temperature of any place in Fahrenheit from the user.
• Convert the temperature into centigrade using C = (F-32)*5/9.
• Show the temperature in centigrade o n the screen ##### Program of Problem 3

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

float c,f;

printf(“Enter the temperature in fahrenheit:”);

scanf(“%d”,&f);

c=(f-32)*5/9;

printf(“%f”,c);

return 0;

}

#### Problem no. 4

##### PSUDO CODE
• Take a any number from the user
• Use modulus operator of user number with 2
• If reminder is 0 then print “the number is even”
• Else print “the number is odd” ##### Program no. 4

#include “stdafx.h”

#include “iostream”

#include “conio.h”

int main()

{

int n;

printf(“Enter any number:”);

scanf(“%d”,&n);

if(n%2==0)

printf(“the number is even”);

else

printf(“the number is odd”);

getch();

return 0;

}

PROBLEM # 5

##### PSUDO CODE
• Take a 4 digit number from the user
• And number is divided by 1000 like (a=n/1000 )
• Take the modulus of n with 1000 (n=n%1000 )
• the answer of modulus is divided by 100 (b=n/100 )
• Again take modulus of the answer of first modulus (n%100 )
• Again the answer is divide by 100
• Again the modulus of second answer of second modulus
• And the answer is divide by 10
• Then arrange the values in from ending to start

Flow Chart  ##### PROGRAM> 5

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

int n,a,b,c;

printf(” Enter a 4 digit number:”);

scanf(“%d”,&n);

a=n/1000;

n=n%1000;

b=n/100;

n=n%100;

c=n/10;

n=n%10;

printf(“%d%d%d%d”,n,c,b,a);

getch();

return 0;

}

#### PROBLEM NO.6

##### PSUDO CODE
• Take two numbers a=21 and b=12
• Consider third variable lets c
• Assign the value of a to c then b to a and c to a
• Then print numbers..the values must be swaps

FLOW CHART ##### PROGRAM> 6

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

int a=21,b=12,c;

printf(“the values of a and b is 21 and 12 before swaping”);

c=a;

a=b;

b=c;

printf(“the values of a and b is %d and %d after swaping”,a,b);

getch();

return 0;

}

#### PROBLEM no.7

##### PSUDO CODE
• Take the hours, minutes and seconds by user one by one
• Then we calculate the total seconds using this formula: sec_in_hours=hour*min/hour*sec/min
• Then print the total seconds into the secreen ##### PROGRAM >> 7

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

int hours,mins,secs,sec_in_hours;

printf(“Enter the hours:”);

scanf(“%d”,&hours);

printf(“Enter the minutes:”);

scanf(“%d”,&mins);

printf(“Enter the seconds:”);

scanf(“%d”,&secs);

sec_in_hours=hours*mins/hours*secs/mins;

printf(“%d”,sec_in_hours);

getch();

return 0;

}

#### PROBLEM no.8

##### PSUDO CODE
• Take the value of radius from the user
• Put in the equation : diameter=2*radius
• Print the diameter  ##### PROGRAM>>8

// pro8.cpp : to find the diameter of the circle.

//

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

int d,r;

printf(“enter the radius of the circle:”);

scanf(“%d”,&r);

d=2*r;

printf(“%d”,d);

getch();

return 0;

}

#### PROBLEM no.9

##### PSUDO CODE
• In this problem we use for loop of 10 cycles
• Take a number from the user for any cycle
• If n%2!=0
• Then sum=sum+1
• This process is continuous for 10 readings
• If any odd number is add by user then sum the number otherwise not
• Then print the sum of odd numbers ##### PROGRAM>>9

// pro 9.cpp : Addition of odd numbers.

//

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

int i,n,sum;

sum=0;

for(i=1;i<=10;i++)

{

printf(“Enter a number:”);

scanf(“%d”,&n);

if(n%2==1)

sum=sum+n;

}

printf(“%d”,sum);

getch();

return 0;

}

#### Problem no.10

##### PSUDO CODE
• Take a number from the user
• Using this equation: cube=num*num*num
• Then print the cube
• The output will be shown on the screen ##### PROGRAM>>10

// pro 10.cpp : Take a cube of number.

//

#include “stdafx.h”

#include “iostream”

#include “conio.h”

using namespace std;

int main()

{

int num=0,cube=0;

printf(“Enter a number:”);

scanf(“%d”,num);

cube=num*num*num;

printf(“%d”,cube);

getch();

return 0;

}