If Statement Write A Problem That Will Know If An Individual Is Addicted To Facebook or Not
If Statement Write A Problem That Will Know If An Individual Is Addicted To Facebook or Not
#inlclude<stdio.h>
int h;
main()
{
clrscr();
printf("\n Enter number of hours you spent in FaceBook: ");
scanf("%d",&h);
if (h<=4)
printf("\n Great! You're not yet addicted.");
else if (h>4)
printf("\n **CERTIFIED FaceBookaholic!!!**");
getch();
}
Produce a program that will help the students to know if they can still pursue their
course.
#include<stdio.h>
float ave;
main()
{
clrscr();
printf("\n Enter your average grade: ");
scanf("%f",&ave);
if(ave>3.0)
printf("\n Sorry, you have to shift another course");
else if (ave<=3.0)
printf("\n Great! You can still pursue you recent course.");
getch();
}
IF-ELSE STATEMENT
Write a program that will ask the user input an integer then output the equivalent day
of the week. 1 is Sunday, 2 is Monday, and so on. If the inputted number is not within 1 – 7
output “Day is not available!”
#include<stdio.h>
main()
{
Int day;
printf(“Enter an integer:”);
scanf(“%d”, &day);
if (day == 1)
printf(“Sunday”);
else if (day ==2)
printf(“Monday”);Else if (day ==3)
printf(”Tuesday”); Else if (day ==4)
printf(“Wednesday”);
else if (day ==5)
printf(“Thursday”);
else if (day ==6)
printf(“Friday”); Else if (day ==7)
printf(“Saturday”);
else
printf(“Day is not available!”);
getch();
}
WHILE LOOP
#include <stdio.h>
int main () {
unsigned i;
i = 0;
while (i < 10) {
if (i % 2 == 1) {
printf("%u is an odd number\n", i);
}
++i;
}
return 0;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
int arr[3][3][3]=
{
{
{11, 12, 13},
{14, 15, 16},
{17, 18, 19}
},
{
{21, 22, 23},
{24, 25, 26},
{27, 28, 29}
},
{
{31, 32, 33},
{34, 35, 36},
{37, 38, 39}
},
};
clrscr();
printf(":::3D Array Elements:::\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
printf("%d\t",arr[i][j][k]);
}
printf("\n");
}
printf("\n");
}
getch();
}
FUNCTIONS
Write a program that will print out ‘Welcome to Function in C” using function with no
arguments and no return value.
#include<stdio.h>
#include<conio.h>
void printline()
{
int i;
printf("\n");
for(i=0;i<30;i++)
{
printf("-");
}
printf("\n");
}
void main()
{
clrscr();
printf("Welcome to function in C");
printline();
printf("Function easy to learn.");
printline();
getch();
}
#include<stdio.h>
#include<conio.h>
void add(int x, int y)
{
int result;
result = x+y;
printf("Sum of %d and %d is %d.\n\n",x,y,result);
}
void main()
{
clrscr();
add(30,15);
add(63,49);
add(952,321);
getch();
}