Question Solution of CIT-111
Question Solution of CIT-111
Answer:
Program: Program is the process of creating a set of
instructions that tell a computer how to perform a
task.
Programming can be done using a variety of
computer programming languages, such as
JavaScript, Python, and C++.
#include<stdio.h>
int main()
{
int n, t, sum=0, r;
printf(“Enter a number\n”);
scanf(“%d”,&n);
t = n;
while (t != 0)
{
r = t%10;
sum = sum+r;
t = t/10;
}
Printf(“Sum of digits on %d = %d\n” , n, sum);
return 0;
}
c). (i) Find the errors and correct the error.
1. #include<stdio.h>
2. {
3. int main(void)
4. while(.)
5. {
6. printf(“hello”);
7. }
8. return 0;
9. }
Answer:
1. #include<stdio.h>
2. int main(void)
3. {
4. printf(“hello”);
5. }
6. return 0;
(ii). How many times CSE PSTU will print:
1. #include<stdio.h>
2. int main()
3. {
4. int x;
5. for(x=-1; x<=10; x++)
6. {
7. if(x<5)
8. continue;
9. else
10. break;
11. printf(“CSE PSTU”);
12. }
13. return 0; }
Answer:
0 times CSE PSTU will print.
Answer:
A C program to count the total number of vowel or
consonant in a word-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define str_size 100 //Declare the maximum size
of the string
void main()
{
char str[str_size];
int i, len, vowel, cons;
printf("\n\nCount total number of vowel
or consonant :\n");
printf("---------------------------------------
-------\n");
printf("Input the string : ");
fgets(str, sizeof str, stdin);
vowel = 0;
cons = 0;
len = strlen(str);
Statement:
Answer:
A program for reversing an odd number where
user will enter the input from the keyboard-
#include<stdio.h>
int main()
{
int n, reverse=0, remainder;
printf(“Enter an odd number: ”);
scanf(“%d” ,&n);
while(n != 0)
{
remainder = n%10;
reverse = reverse*10 + remainder;
n /= 10;
}
printf(“Reversed number = %d” , reverse);
return 0;
}
1. #include<stdio.h>
2. void main()
3. {
4. int x = 10;
5. int y = 15;
6. printf(“%d”,(x,y)) }
Answer:
1. #include<stdio.h>
2. void main()
3. {
4. int x = 10;
5. int y = 15;
6. printf(“%d,%d”,x,y) }
#include<stdio.h>
int main()
{
int a = 10, b = 25;
a = b-- - a--;
b = --b - --a;
printf(“%d %d\n”,a,b);
}
Answer:
a = 25 – 10 = 15
b = 23 – 14 = 9
1. #include<stdio.h>
2. int main()
3. {
4. int m = -10, n=20;
5. n = (m<0)? 0:1;
6. printf(“%d %d”, m, n);
7. }
Answer:
The output of the following code-
-10 0
while(z>=0) {
sum += z;
Answer:
while (z >= 0)
{
sum += z;
z--;
}
Explanation: Since the while structure is controlled by the
variable z being greater than or equal to 0, z must be
decremented in order for the loop continuation
condition to become false at some point. For this reason,
we added z-- inside the body of the while loop. Note that
the code is now blocked together with curly braces,
because there is more than one statement in the body of
the while loop.
1. #include<stdio.h>
2. int main() {
3. int check = 2;
4. switch(check) {
5. case 1:
6. printf(“Compter”);
7. case 2:
8. printf(“Science”);
9. case 3:
10. printf(“Engineering”);
11. default:
12. printf(“PSTU”);
13. }
14. return 0;
15. }
Answer:
The output of the following code-
ScienceEngineeringPSTU
switch( score / 10 )
{
case 10:
case 9:
printf("Grade: A+");
break;
case 8:
printf("Grade: A");
break;
case 7:
printf("Grade: B");
break;
case 6:
printf("Grade: C");
break;
case 5:
printf("Grade: D");
break;
default:
printf("Grade: F");
break;
return 0;
}
main()
int y;
printf(“%d\n”, y);
main()
{
int y;
| printf(“%d\n”, y); |
| } |
| {
| p = x*y; /* x = 10 , y = 5*/
if (i % j == 0)
{
flag = 1;
break;
printf("%d\t", i);
return 0;
}
o block scope,
o function scope and
o prototype scope.
o automatic lifetime and
o dynamic lifetime.
Fclose(ptr);
#include<stdio.h>
main()
{
FILE *f1, *f2, *f3;
int number, i;
printf(“Contents Of NUMB file\n\n”);
f1 = fopen(“NUBM” , “w”; /*Create NUMB file */
for(i=1; i<=30; i++)
{
scanf(“%d” , &number);
if(number == -1) break;
putw(number, f1);
}
fclose(f1);
f1 = fopen(“NUMB” , “r”);
f2 = fopen(“NUMB” , “w”);
f3 = fopen(“NUBM”, “w”);
Output:
Contents of NUMB file
111 222 333 444 555 666 777 888 999 000 121 232 343
454 565 -1
Contents of ODD file
111 333 555 777 999 121 343 565
Contents of EVEN file
222 444 666 888 0 232 454
--------------------------