Docsity

Solved Practice Problems of C Programming | CSC 3320, Study notes of Computer Science

Toggle sidebar
bg1
Practice problems of C programming
1. What is the output of the following program?
int a,b,c;
a=10; b=50; c=30;
if(a>b)a=b,b=c;c=a;
printf(โ€œa=%d b=%d c=%d \nโ€,a,b,c);
A) a=10 b=50 c=10 B) a=10 b=50 c=30
C) a=10 b=30 c=10 D) a=50 b=30 c=50
2. what is the output of the following program?
#include <stdio.h>
main()
{
int i,j;
for(i=3;i>=1;i--)
{ for(j=1;j<=2;j++) printf("%d",i+j);
printf("\n ") ;
}
}
A) 2 3 4 B) 4 3 2 C) 2 3 D) 4 5
3 4 5 5 4 3 3 4 3 4
4 5 2 3
3. What is the output of the following program?
#include <stdio.h>
main()
{
int x=1,y=2,z=3;
if(x>y)
if(y<z) printf("%d",++z);
else printf("%d",++y);
printf("%d\n", x++ );
}
A)331 B)41 C)2 D)1
4. What is the output of the following program?
#include <stdio.h>
main()
{ int i=5;
do
{ if(i%3==1)
if(i%5==2)
{ printf(โ€œ*%dโ€,i); break; }
i++;
pf3
pf4
pf5

Partial preview of the text

Download Solved Practice Problems of C Programming | CSC 3320 and more Study notes Computer Science in PDF only on Docsity!

Practice problems of C programming

  1. What is the output of the following program? int a,b,c; a=10; b=50; c=30; if(a>b)a=b,b=c;c=a; printf(โ€œa=%d b=%d c=%d \nโ€,a,b,c); A) a=10 b=50 c=10 B) a=10 b=50 c= C) a=10 b=30 c=10 D) a=50 b=30 c=
  2. what is the output of the following program? #include <stdio.h> main() { int i,j; for(i=3;i>=1;i--) { for(j=1;j<=2;j++) printf("%d",i+j); printf("\n ") ; } } A) 2 3 4 B) 4 3 2 C) 2 3 D) 4 5 3 4 5 5 4 3 3 4 3 4 4 5 2 3
  3. What is the output of the following program? #include <stdio.h> main() { int x=1,y=2,z=3; if(x>y) if(y<z) printf("%d",++z); else printf("%d",++y); printf("%d\n", x++ ); } A)331 B)41 C)2 D)
  4. What is the output of the following program? #include <stdio.h> main() { int i=5; do { if(i%3==1) if(i%5==2) { printf(โ€œ*%dโ€,i); break; } i++;

} while(i!=0); printf(โ€œ\nโ€); } A) 7 B)35 C)5 D)2

  1. What is the output of the following program? #include <stdio.h> int fun(int a,int b) { if(b==0) return a; else return(fun(--a,--b)); } main() { printf("%d\n", fun(4,2));} A) 1 B)2 C)3 D)
  2. What is the output of the following program? #include <stdio.h> #include <stdlib.h> int fun(int n) { int p; p=(int)malloc(sizeof(int)); *p=n; return *p; } main() { int a; a = fun(10); printf("%d\n",a+fun(10)); } A)0 B)10 C)20 D) Error
  3. What is the output of the following program? #include <stdio.h> void fun( int a, int b) { int t; t=a; a=b; b=t; } main() { int c[10]={1,2,3,4,5,6,7,8,9,0}, i; for(i=0;i<10;i+=2) fun(c[i], c[i+1]); for(i=0;i<10;i++) printf("%d," ,c[i]); printf("\n"); } A)1,2,3,4,5,6,7,8,9,0 B)2,1,4,3,6,5,8,7,0, C)0,9,8,7,6,5,4,3,2,1 D)0,1,2,3,4,5,6,7,8,

for(i=1;i<n;i++) if(s[i][k]>m)m= s[i][k]; return m; } main() { int a[4][4]={{1,2,3,4},{11,12,13,14},{21,22,23,24},{31,32,33,34}}; printf("%d\n",fun(a,4,0)); } A)4 B)34 C)31 D)

  1. What is the output of the following program? #include <stdio.h> main() { struct STU { char name[9]; char sex; double score[2];}; struct STU a={"Zhao",'m',85.0,90.0},b={"Qian",'f',95.0,92.0}; b=a; printf("%s,%c,%2.0f,%2.0f\n", b.name, b.sex, b.score[0], b.score[1]); } A) Qian,f,95,92 B) Qian,m,85,90 C) Zhao,f,95,92 D) Zhao,m,85,
  2. Assume we created a linked list as follows. data next p q The statement to delete and free node q should be A)(p).next=(q).next; free(p); B)p=q->next; free(q); C) p=q; free(q); D)p->next=q->next; free(q);
  3. What is the output of the following program? #include <stdio.h> main() { char a=4; printf(โ€œ%d\nโ€,a=a<<1); } A) 40 B) 16 C) 8 D) 4
  4. What is the content of abc.dat after the execution of the following program? #include <stdio.h> main() { FILE *pf; char *s1="State", *s2="Georgia"; pf=fopen("abc.dat","wb+"); Head a b c

fwrite(s2,7,1,pf); rewind(pf); /go back to the head of the file/ fwrite(s1,5,1,pf); fclose(pf); } A) State B) Stateia C) StateGeorgia D) GeorgiaState

  1. The output of the following program is 1 #include<stdio.h> main() { int i,j,sum; for(i=3;i>=1;i--) { sum=0; for(j=1;j<=i;j++) sum+=i*j; } printf("%d\n",sum); }
  2. The output of the following program is ______9911_______ #include<stdio.h> main() { int j,a[]={1,3,5,7,9,11,13,15},p=a+5; for(j=3;j;j--) { switch(j) { case 1: case 2:printf(โ€œ%dโ€,p++); break; case 3:printf(โ€œ%dโ€,*(--p)); } } }
  3. The output of the following program is _______3_______________ #include<stdio.h> #define N 5 int fun(int *s,int a ,int n) { int j; *s=a; j=n; while(a!=s[j]) j--; return j; } main()

return m; }