0% found this document useful (0 votes)
46 views3 pages

Task - 1: The Value Is %D/N" %D %D" 5

The document contains 8 multiple choice questions and 5 programming questions related to C programming concepts like loops, data types, pattern printing etc. The multiple choice questions test knowledge of errors in code snippets, loop execution counts and data type defaults. The programming questions require writing code to print natural numbers, their sum, cubes of a given range of numbers, and patterns in triangle shape.

Uploaded by

saad
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)
46 views3 pages

Task - 1: The Value Is %D/N" %D %D" 5

The document contains 8 multiple choice questions and 5 programming questions related to C programming concepts like loops, data types, pattern printing etc. The multiple choice questions test knowledge of errors in code snippets, loop execution counts and data type defaults. The programming questions require writing code to print natural numbers, their sum, cubes of a given range of numbers, and patterns in triangle shape.

Uploaded by

saad
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/ 3

Task_1

Identify and correct the errors in each of the following statements:


1- printf (The value is %d\n", &number);
2- scanf(%d %d", &number1, number2 );
3- while (c <= 5) {
product *= c;
++c;
4- While (x <= 100)
total += x;
++x;
5- for (i=0 ; i=>6 ; i++) {
Printf(%d\n , I );
}

6-
How many times the while loop will get executed?
#include<stdio.h>
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %d\n", j, j);
j++;
}
return 0;
}

A. Infinite times

B. 255 times

C. 256 times

D. 254 times
7-
Point out the error, if any in the for loop.
#include<stdio.h>
int main()
{
int i=1;
for(;;)
{
printf("%d\n", i++);
if(i>10)
break;
}
return 0;
}

A. There should be a condition in the for loop

B. The two semicolons should be dropped

C. The for loop should be replaced with while loop.

D. No error

8- By default, the data type of a constant without a decimal point is int, whereas the one with a
decimal point is a double.
A. Yes

B. No
Write the code of the following programs:
1- Write a program in C to display the first 10 natural numbers.
Expected Output:
1 2 3 4 5 6 7 8 9 10

2- Write a C program to find the sum of first 10 natural numbers.


Expected Output:
The first 10 natural number is:
1 2 3 4 5 6 7 8 9 10
The Sum is: 55

3- Write a program in C to display the cube of the number up to given an integer.


Input numbers: 5
Expected Output:
Number is: 1 and cube of the 1 is :1
Number is: 2 and cube of the 2 is :8
Number is: 3 and cube of the 3 is :27
Number is: 4 and cube of the 4 is :64
Number is: 5 and cube of the 5 is :125

4- Write a program in C to display the pattern like right angle triangle with a
number.
The pattern like:
1
12
123
1234

5- Write a program in C to make such a pattern like right angle triangle with a
number which will repeat a number in a row.
The pattern like:
1
22
333
4444

You might also like