Department of Computer Science
and Engineering
BRAC University
CSE 110: Programming Language I
Write the following program in the Visual C++ editor. Compile and run the program and observe the output.
#include <stdio.h>
int main()
{
int luckyNumber = 5;
float radius = 2;
char myName[15] = "John";
char initial = 'J';
printf("Hello
World\n"); /* The format string contains only
ordinary
characters.
*/
printf("My lucky number is %d\n", luckyNumber); /*
The "%d" specifies
that
an integer value will be output. */
printf("My name is
%s\n",myName); /* The %s specifies that a character
string
will be output. */
printf("My first initial is
%c\n",initial); /* The %c specifies that a
character
will be output. */
printf("The radius of the circle %f\n",
radius);
/*
%f specifies that a float will be output. */
printf("Hello %s or should I say
%c\n",myName,initial);
/*
Multiple arguments of different types may be output. */
return(0);
}
Write the following program in the Visual C++ editor. Compile and run the program and observe the output
/* A program to add two integer numbers */
#include <stdio.h>
int main()
{
char yourName[15]; /* declaration */
int integ1, integ2, sum;
printf("Enter your name:
");
scanf("%s",yourName); /* yourName is a
character array */
printf("Hello %s\n",yourName);
printf(“Enter 1st integer\n”); /* prompt */
scanf(“%d”,&integ1); /* read an integer */
printf(“Enter 2nd integer\n”); /* prompt */
scanf(“%d”,&integ2); /* read an integer */
sum=integ1+integ2; /* assignment of sum */
printf(“Sum is %d\n”,sum); /* print sum */
return 0;
}
Sample input:
Enter 1st integer
45
Enter 2nd integer
72
Sample output:
Sum is 117
Problem 1: Write a program that will calculate the average of four integer numbers.
Sample Input:
Enter 1st Integer: 4
Enter 2nd Integer: 6
Enter 3rd Integer: 3
Enter 4th Integer: 7
Sample Output:
Average of 4, 6, 3 and 7 is 5