ਪ੍ਰਸ਼ਨ 1: ਬਹੁਪੱਦੀ ਪਸੰਦ ਦੇ ਪ੍ਰਸ਼ਨ
1.1
(c) ;
1.2
(c) 1
1.3
(b) {}
1.4
(e) all of these
1.5
(b) main
1.6
(d) all of these
1.7
(c) math .h
1.8
(a) d
1.9
(b) \0
1.10
(a) a digit
ਪ੍ਰਸ਼ਨ 2: ਨਿਮਨਲਿਖਿਤ ਦਾ ਸਟੇਟਮੈਂਟ ਲਿਖੋ:-
2.1 ਨਿਮਨਲਿਖਿਤ ਸਟੇਟਮੈਂਟ ਲਾਗੂ ਕਰਨ ਦਾ ਕੀ ਪ੍ਰਭਾਵ
ਹੁੰਦਾ ਹੈ?
printf(“\nOne\nTwo\nThree\n”);
Ans. One
Two
Three
2.2 printf ਸਟੇਟਮੈਂਟ ਲਿਖੋ, ਜਿਹੜਾ
ਤੁਹਾਡੀ ਸਕਰੀਨ ਤੇ ਨਿਮਨਲਿਖਤ ਨੂੰ ਪ੍ਰਦਰਸ਼ਿਤ ਕੋਰ?
This is a test 1 2 3
123.33
These are the Characters a b c
Ans. printf(“This is a test 1 2
3\n123.33\nThese are the Characters a b c”);
2.3 ਸਟੇਟਮੈਂਟ ਲਿਖੋ, ਜਿਹੜੇ ਨਿਮਨਲਿਖਤ ਵੈਰੀਏਬਲਜ਼
ਨੂੰ ਸੂਚਿਤ ਕੀਤੇ ਗਏ ਢੰਗ ਨਾਲ ਡਿਕਲੇਅਰ ਕਰੋ?
up, down as integers
first, last as single
precision floating point
c as a
character
Ans. int up, down;
float first, last;
char c;
2.4 ਕੀ ਹੇਠ ਲਿਖਿਆ ਪ੍ਰੋਗਰਾਮ ਕੰਮ ਕਰੇਗਾ? ਜੇ ਨਹੀ
ਤਾਂ ਗਲਤੀਆਂ ਦੱਸੋ ਅਤੇ ਠੀਕ ਕਰੋ।
#include<stdio.h>
main() { printf(“How
many person!);}
Ans. #include<stdio.h>
void
main(){printf(“How many person!”);}
2.5 ਸੀ ਕੋਡ ਦੇ ਨਿਮਨਲਿਖਤ ਭਾਗ
ਨਾਲ ਕੀ ਗਲਤ ਹੈ?
printf(“c”,”o”,”m”,”p”,”u”,”t”,”e”,”r”,”\n”);
Ans. printf ਫੰਕਸ਼ਨ ਦਾ ਪਹਿਲਾ ਪੈਰਾਮੀਟਰ ਇਕ
ਫਾਰਮੇਟਡ ਸਟਰਿੰਗ ਹੁੰਦੀ ਹੈ ਜਿਸ ਨੂੰ ਸਕਰੀਨ ਤੇ ਪ੍ਰਿੰਟ ਕੀਤਾ ਜਾਂਦਾ ਹੈ ਅਤੇ ਬਾਕੀ ਪੈਰਾਮੀਟਰਾਂ ਨੂੰ ਉਸ ਸਟਰਿੰਗ ਨੂੰ ਫਾਰਮੈਟ ਕਰਨ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ। ਉਪਰੋਕਤ ਸਟੇਟਮੈਂਟ ਵਿੱਚ printf ਫੰਕਸ਼ਨ ਸਿਰਫ ਪਹਿਲੀ ਸਟਰਿੰਗ ਨੂੰ ਹੀ ਸਕਰੀਨ ਤੇ ਪ੍ਰਿੰਟ ਕਰੇਗਾ,
ਜਿਸ ਦੇ ਨਤੀਜੇ ਵੱਜੋ ਸਿਰਫ ਹੇਠ ਲਿਖੀ ਆਊਟਪੁਟ ਹੀ ਆਵੇਗੀ:
Output:
c
2.6 ਪ੍ਰੋਗਰਾਮ ਵਿੱਚ ਗਲਤੀਆਂ ਦਸੋ।
name() \*This
is one great program; stand buy…./*
{
printf(‘I think I am getting hungry. \n’);
Ans. 1. ਹੈਡਰ ਫਾਈਲ stdio.h ਦਾਖਲ ਨਹੀ ਕੀਤੀ ਗਈ।
2. ਫੰਕਸ਼ਨ name ਜਗ੍ਹਾ ਤੇ main ਲਿਖਿਆ ਜਾਣਾ ਹੈ।
3. ਕਮੈਂਟ ਨੂੰ ਸਹੀ ਤਰ੍ਹਾਂ ਖਤਮ ਨਹੀ ਕੀਤਾ ਗਿਆ। /* ਦੀ ਜਗ੍ਹਾ *\ ਇਸਤੇਮਾਲ ਚਾਹੀਦਾ
ਹੈ।
4. ਸਟਰਿੰਗ ‘I think I am getting hungry. \n’ ਨੂੰ “” ਵਿੱਚ
ਲਿਖਿਆ ਜਾਣਾ ਚਾਹੀਦਾ ਸੀ।
5. ਫੰਕਸ਼ਨ ਦੀ ਬਾਡੀ ਦੀ
ਸਮਾਪਤੀ } ਨਾਲ ਨਹੀ ਹੋਈ ਹੈ। ਅੰਤ ਵਿੱਚ }
ਲਗਾਓ।
2.7 printf ਫੰਕਸ਼ਨ ਦੀ ਵਰਤੋ ਕਰਦੇ ਹੋਇਆਂ ਸੀ ਪ੍ਰੋਗਰਾਮ ਲਿਖੋ ਜੋ
ਨਾਮ ਨੂੰ ਇਕ ਲਾਈਨ ਤੇ, ਐਡਰੈਸ ਦੂਜੀ ਲਾਈਨ ਅਤੇ ਸ਼ਹਿਰ, ਰਾਜ ਦਾ ਨਾਮ ਤੀਜੀ ਲਾਈਨ ਉੱਤੇ ਲਿਖੋ।
#include<stdio.h>
void
main()
{
printf(“My
Name\nMy Address\nMy City, State”);
}
2,8 printf ਵਰਤੋਂ ਕਰਕੇ –
ਤਿੰਨ ਅੰਕਾਂ ਦੀ ਔਸਤ ਅਤੇ ਜੋੜ ਪ੍ਰਿੰਟ ਕਰੋ?
#include<stdio.h>
#include<conio.h>
void
main()
{
float
s, a;
s=4+5+6;
a=s/3.0;
printf(“Sum=%.2f\nAverage=%.2f”,s,a);
getch();
}
2.9 ਮੀਟਰਾਂ ਨੂੰ
ਕਿਲੋਮੀਟਰਾਂ ਵਿਚ ਬਦਲਣ ਲਈ ਪ੍ਰੋਗਰਾਮ ਵਿਚੋ ਗਲਤੀਆਂ ਨੂੰ ਸਹੀ ਕਰੋ?
main()
{
float mtrs, km;
printf(“Enter the value in meters”);
scanf(“%f”,&mtr);
km=mtrs/1000.00
printf(“\n
The value of metre(s) %7.2f is converted into %7.2f kilometre(s)’,mtr,km);}
Ans. #include<stdio.h> //add header file
void
main() //add void
{
float mtrs, km;
printf(“Enter the value in
meters”);
scanf(“%f”,&mtrs);
//correct variable name to mtrs
km=mtrs/1000.00; //add semicolon at end of statement
printf(“\n
The value metre(s) %7.2 is converted into %7.2f kilometer (s)”,mtrs,km);
//use
” instead of ‘ and correct mtr to mtrs
}
2.10 c=(5.0/9.0)*(f*32.0); ਵਰਤੋ ਕਰਕੇ ਤਾਪਮਾਨ
ਨੂੰ ਫਾਰਨਾਹੀਟ ਤੋ ਸੈਲਸਿਅਸ ਵਿਚ ਬਦਲੋ?
#include<stdio.h>
#include<conio.h>
void
main()
{
float
c,f;
printf(“Enter
temperature in Fahrenheit: “);
scanf(“%f”,&f);
c=(5.0/9.0)*(f-32.0);
printf(“Temperature
in Celcius is %.2f”,c);
getch();
}
Comments
Post a Comment