You are on page 1of 4

NAME HOSSAIM MD IMRAN

DEPARTMENT Transportation And Civil Engineering


Class Bachelor Of Science
Batch 2023
Student ID 2333130211
Subject Programming C
HOMEWORK
1‌ . Which of the following is NOT a constant in C language?
A. 012
B. "a"
C. '\n'
D. 'AB'
2. Which of the following is NOT a float constant in C language?
A. 2.38
B. .23
C. 1.2e-2
D. e-2
3. Which of the following are C keywords? choice
main, int, function, char, =
Answer: main, int, char.

4. Assuming that each of the following examples(a--d) is part of a complete program,


what will each one print?
a. printf("Baa Baa Black Sheep.");
printf("Have you any wool?\n");
b. printf("Begone!\nO creature of lard!\n");
c. printf("What?\nNo/nfish?\n");
d. intnum;
num = 2;
printf("%d + %d = %d", num, num, num + num);

Ans:
a. Baa Baa Black Sheep.Have you any wool?
b. Begone!
O creature of lard!

c. What?
No/nfish?

d. 2+2 = 4

5.Correct this silly program. (The / in C means division.)


void main(int) / this program is perfect /
{
cows, legs integer;
printf("How many cow legs did you count?\n);
scanf("%c", legs);
cows = legs / 4;
printf("That implies there are %f cows.\n", cows)
}

#include <stdio.h>
intmain() {
int legs, cows;
printf("How many cow legs did you count?\n");
scanf("%d", & legs);
cows = legs / 4;
printf("That implies there are %d cows.\n", cows);
return 0;
}

Programming operating:

1. Write a C program that prints your first and last name in the console window.
Your first name should appear on one line, and your last name appear on the
next line.

// TASK-3___HOSSAIN MD IMRAN (CE) 2333130211


#include <stdio.h>

int main() {
printf("MD IMRAN\n");
printf("HOSSAIN\n");
return 0;
}

2. Write a program that uses one printf() call to print your first name and last
name on one line, uses a second printf() call to print your first and last names on two
separate lines, and uses a pair of printf() calls to print your first and last names on one
line. The output should look like this (but using your name):

Gustav Mahler First print statement


Gustav Second print statement
Mahler Still the second print statement
Gustav Mahler Third and fourth print statements

Solution

// TASK-3___HOSSAIN MD IMRAN (CE) 2333130211


#include <stdio.h>

int main()
{
printf("Gustav Mahler\n"); // First print statement
printf("Gustav\n"); // Second print statement
printf("Mahler\n"); // Still the second print statement
printf("Gustav "); // Third print statement
printf("Mahler\n"); // Fourth print statement
return 0;
}

You might also like