0% found this document useful (0 votes)
29 views11 pages

#Include Void

The document contains 10 C programming examples written by Mohd Zarif Nashriq Bin Mohd Nor. The programs demonstrate the use of various loop structures in C including while, for, do-while loops. The programs print output based on conditions and incrementing/decrementing loop counters. Overall the programs provide examples of basic loop implementation and syntax in C programming.

Uploaded by

Anonymous 11nYo1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views11 pages

#Include Void

The document contains 10 C programming examples written by Mohd Zarif Nashriq Bin Mohd Nor. The programs demonstrate the use of various loop structures in C including while, for, do-while loops. The programs print output based on conditions and incrementing/decrementing loop counters. Overall the programs provide examples of basic loop implementation and syntax in C programming.

Uploaded by

Anonymous 11nYo1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

/**************************************************

Name: MOHD ZARIF NASHRIQ BIN MOHD NOR


ID: CE095863
Program: Program 1
Purpose: SWITCH Statement
**************************************************/
#include <stdio.h>
void main()
{
char grade = 'D';
printf("Your grade is %c\n", grade);
switch (grade)
{
case 'A':
printf("Excellent!\n");
break;
case 'B':
printf("Congratulations!\n");
case 'C':
printf("Well done\n");
break;
case 'D':
printf("You passed\n");
break;
case 'E':
printf("You can do better next time\n");
case 'F':
printf("You have failed,try harder!\n");
break;
default:
printf("False grade\nInsert your grade again\n");
}

return 0;
}

Output

Your grade is D
You passed
Press any key to continue . . .

Your grade is W
False grade
Insert your grade again
Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863
Program: Program 2
Purpose: SWITCH Statement
**************************************************/
#include <stdio.h>
void main()
{

int code;
printf("Enter the subject's code: ");
scanf("%d", &code);
switch (code)
{
case 1:
printf("\tTITAS\n");
break;
case 2:
case 3:

printf("\tGeotech\n");
break;
printf("\tProgramming\n");
break;

default:
printf("\nInvalid code\n");
}
}

Output

Enter the subject's code: 3


Programming
Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863
Program: Program 3
Purpose: WHILE Statement
**************************************************/
#include <stdio.h>
void main()
{
int value = 8;
while (value < 14)
{
printf("\tWhat's up guys!!!\n\n");
value++;
}
}

Output

What's up guys!!!

What's up guys!!!

What's up guys!!!

What's up guys!!!

What's up guys!!!

What's up guys!!!

Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863
Program: Program 4
Purpose: WHILE Statement
**************************************************/
#include <stdio.h>
void main()
{
int num = 1;
while (num < 3)
{
printf("\tRemember, life is not a bed of roses~~\n\n");
num++;
}
}

Output

Remember, life is not a bed of roses~~

Remember, life is not a bed of roses~~

Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863
Program: Program 5
Purpose: WHILE Statement
**************************************************/
#include <stdio.h>
void main()
{
int x = 7;
while (x < 12)
{
printf("\tThe value of x : %d\n", x);
x++;
}
}

Output

The value of x : 7
The value of x : 8
The value of x : 9
The value of x : 10
The value of x : 11
Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863

Program: Program 6
Purpose: FOR Statement
**************************************************/
#include <stdio.h>
void main()
{
int x;
for (x = 0; x < 125; x = x + 25)
{

printf("The value of x is %d\n\n", x);

}
}

return 0;

Output

The value of x is 0

The value of x is 25

The value of x is 50

The value of x is 75

The value of x is 100

Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863

Program: Program 7
Purpose: FOR Statement
**************************************************/
#include <stdio.h>
void main()
{
int x;
for (x = 4; x < 21; x=x+4)
{
/* When x equals 21 the loop breaks. */
printf("%d\n", x);
}
}

Output

4
8
12
16
20
Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863
Program: Program 8
Purpose: FOR Statement

**************************************************/
#include <stdio.h>
void main()
{
int x;

for (x = 2; x < 15; x=x+3)


{
/* When x equals 15 the loop breaks. */
printf("PROCESSING YOUR APPLICATION\n");
}
printf("\tError,try again\n\n");

Output

PROCESSING YOUR APPLICATION


PROCESSING YOUR APPLICATION
PROCESSING YOUR APPLICATION
PROCESSING YOUR APPLICATION
PROCESSING YOUR APPLICATION
Error,try again

Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863
Program: Program 9
Purpose: DO...WHILE Statement
**************************************************/

#include <stdio.h>
void main()
{

int a = 45;
do {

printf("The value of a: %d\n", a);


a = a + 5;
} while (a <= 65);
}

Output

The value of a: 45
The value of a: 50
The value of a: 55
The value of a: 60
The value of a: 65
Press any key to continue . . .

/**************************************************
Name: MOHD ZARIF NASHRIQ BIN MOHD NOR
ID: CE095863
Program: Program 10
Purpose: DO...WHILE Statement
**************************************************/
#include <stdio.h>

void main()
{

int x;
x = 5;
do
{

/* "Hello, world!" is printed at least one time


even though the condition is false */
printf("\nHello world!\n\t I \"love\" PROGRAMMING\n\n");

while (x != 5);
}

Output

Hello world!
I "love" PROGRAMMING

Press any key to continue . . .

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