0% found this document useful (0 votes)
4 views6 pages

WK231

The document contains a C program that includes multiple functions for various tasks: calculating a linear formula, printing even Fibonacci numbers, and generating a specific shape pattern. It features a menu-driven interface allowing users to select which function to execute. The program also includes comments for students to add their code and explanations for certain parts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

WK231

The document contains a C program that includes multiple functions for various tasks: calculating a linear formula, printing even Fibonacci numbers, and generating a specific shape pattern. It features a menu-driven interface allowing users to select which function to execute. The program also includes comments for students to add their code and explanations for certain parts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

//@STUDENT NAME:

//@STUDENT ENROLL NUMBER:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <ctype.h>

//@STUDENT: ADD YOUR CODE FOR FUNCTION Q1 HERE:

double y(double x, double a, double b)

double result;

result = x*a+b;

return result;

//@STUDENT: ADD YOUR CODE FOR FUNCTION Q2 HERE:

void printEvenFibonaci(int N)

int i=1, j=1;


int P=0;

while(P<=N)

P=i+j;

i=j;

j=P;

if(P%2==0 && P<=N) printf("%d ", P);

//@STUDENT: ADD YOUR CODE FOR FUNCTION Q3 HERE:

void printShape(int N)

int i, j, k;

for (i = 0; i < N; i++) {

for (j = 0; j < i; j++) {

printf(" ");

if (i == 0 || i == N - 1) {

for (k = 0; k < 2*N-1; k++) {


if (k % 2 == 0) {

printf("*");

} else {

printf("_");

else {

printf("*");

for (k = 0; k < 2*N - 3; k++) {

if (k % 2 == 0) {

printf("_");

} else {

printf("_");

printf("*");

printf("\n");

//@STUDENT: ADD YOUR CODE FOR FUNCTION Q4 HERE:


void PrintMenu(int* num)

printf("1 - Calculate FORMULA Q1");

printf("\n2 - Print out EVEN FIBONACI NUMBERS Q2");

printf("\n3 - Print out SHAPE Q3");

printf("\n4 - QUIT\n");

scanf("%d", num);

int main() {

system("cls");

//@STUDENT: WRITE CODE FOR Q5 HERE:

int num, N, i;

double x, a, b;

while(num!=4)

PrintMenu(&num);

switch (num)

case 1:

scanf("%lf%lf%lf", &x, &a,&b);


printf("%lf\n", y(x, a, b));

break;

case 2:

scanf("%d", &N);

printEvenFibonaci(N);

printf("\n");

break;

case 3:

scanf("%d", &N);

printShape(N);

printf("\n");

break;

case 4:

printf("Good bye!");

break;

default:

printf("Retype!\n");

break;

}
//--FIXED PART - DO NOT EDIT ANY THINGS HERE

printf("\n");

system("pause");

return(0);

/* @STUDENT EXPLAINS (WALKTHROUGH) Q6 HERE:

int n = 7, m = 6; //gan gia tri n=7 va m=6 co kieu du lieu la int (so nguyen)

int* pn = &n; //gan pn= dia chi cua gia tri n

int* p = &m; //gan p= dia chi cua gia tri m

*pn = *p + 3*m - 5*n; //pn = 6 + 3*6 - 5*7 = -11

*p -= *pn; // p = 6 - (-11) = 17

printf("%d", m+n); //In ra man hinh: 13

*/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy