Assignment On Lab Experiment 07
Assignment On Lab Experiment 07
LAB REPORT NO 07
Course Title: Structured Programming Lab
Course Code: 104 Section: 211-DB
Student Details
Name ID
Objectives/Aim
The main objective was to solve math problems.
P.T.O
(Section 6)
Answer to question no. 1
Code:
#include <stdio.h>
char* odd_even(int i);
int main()
{
int num;
printf("Enter an integer number : ");
scanf("%d", &num);
printf("Result : %s",odd_even(num));
return 0;
}
char* odd_even(int num)
{
if (num%2 == 0){
return "YOUR NUMBER IS EVEN NUMBER";
}else{
return "YOUR NUMBER IS ODD NUMBER";
}
}
Output:
Answer to question no. 2
Code:
#include <stdio.h>
int isPerfect(int num);
void printPerfect(int starting, int end);
int main()
{
int starting, end;
printf("Enter lower the limit to print perfect numbers: ");
scanf("%d", &starting);
printf("Enter the upper limit to print perfect numbers: ");
scanf("%d", &end);
return 0;
}
int isPerfect(int num)
{
int i, sum;
sum = 0;
for(i=1; i<num; i++)
{
if(num % i == 0)
{
sum += i;
}
}
if(sum == num)
return 1;
else
return 0;
}
void printPerfect(int starting, int end)
{
while(starting <= end)
{
if(isPerfect(starting))
{
printf("%d ", starting);
}
starting++;
}
}
Output:
(Section 7)
Answer to question no. 1
Code:
#include <stdio.h>
#include <conio.h>
getch();
return 0;
}
Code:
#include<stdio.h>
#include<stdlib.h>
void display(float n1, float n2, char ch, float result);
void add(float n1, float n2);
void subtract(float n1, float n2);
void multiply(float n1, float n2);
void divide(float n1, float n2);
void rem(float n1, float n2);
void power(float n1, float n2);
int main()
{
float n1, n2;
int ch;
do{
printf("Enter two numbers: ");
scanf("%f %f", &n1, &n2);
printf("\n*****************");
printf("\n1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4.Division");
printf("\n5.Remainder");
printf("\n6.Power (x^y)");
printf("\n7.Exit");
printf("\nEnter your choice: ");
scanf("%d", &ch);
switch (ch) {
case 1:
add(n1,n2);
break;
case 2:
subtract(n1,n2);
break;
case 3:
multiply(n1,n2);
break;
case 4:
divide(n1,n2);
break;
case 5:
rem(n1,n2);
break;
case 6:
power(n1,n2);
break;
case 7:
printf("Thank You.");
exit(0);
default:
printf("Invalid input.");
printf("Please enter correct input.");
}
printf("\n**********************************\n");
}while(1);
return 0;
}
void display(float n1, float n2, char ch, float result)
{
printf("%.2f %c %.2f = %.2f\n", n1, ch, n2, result);
}
Output:
int main()
{
int start, end;
return 0;
}
void printStrongNumbers(int start, int end)
{
long long s;
int num;
while(start != end)
{
s = 0;
num = start;
while(num != 0)
{
s += fact(num % 10);
num /= 10;
}
if(start == s)
{
printf("%d ", start);
}
start++;
}
}
Summary
It was a good thing that we learned new functions that can help us to solve real-life
problems.