Download as pdf
Download as pdf
You are on page 1of 35
+91 9811854308 Page No.1 Features ‘Small Batches Lab Oriented Training Logical & Selective notes Solve Previous Question paper Deep and Devine knowledge of coding Friendly Environment 491 9811854308 Ces sat 854308 Pageno.2 SOLVED ASSIGNMENTS 1gnou pa eer ‘ASSIGNMENT GURU Q1.Explain the different Storage Classes in C programming language. ‘Storage Clas: © Automatic © Static + Register = Extem 1) Automatic: -it is used to declare a local variable. That treatments when function exited, Variables declared inside a function without storage class specification is by default, an automatic variable ‘Are deciared using a keyword auto. Eg: - auto int a; Pia ceomeag Tienes Prev Psa nlt-F9 Compile fF Pake OUTPUT IS eres 2) Static: - tis used to declare a variable that treatment when program exited. Static variable are iniliaized only once, when the program is completed Itis declared using the keyboard Siatic Like State nt X; Static floaty; a Yu @ Ei /IGNOUASSIGNMENTGURU "25+ +91 9811854308 Page No. 3 SOLVED ASSIGNMENTS rassignmentg a mre AIE-P? Prev Pea A1t-P9 Comile To Make FAO. Mew 3) Register: - itis used to declare a variable that is accessed by register decently, So it provides first execution of program. eg. Register int count; File Fait Search Run ile Debug Project Options: Da cong Titelp Alt-Fe Rext Msg Alt-F? Prev gsg Alt-F9 Compile F9 Make Fi Menu ‘w{} © Fi /IGNOUASSIGNMENTGURU *'"+08 Socale Py | @ ABs Siors +91 9811854308 Page No. 4 x SOLVED ASSIGNMENTS rassignmentg ‘ASSIGNMENT GURU i Output: - Coe ad preety id er aes ~->Register keyboard is used to define local variable. Local variable are stored in register instead of RAM, ~->This is generally used for faster access. ->Common use is “counter” -->it is declared using the keyboard Register Like i | : | Notes:- a and b variable access from memory. But C variable access from CPU decently. 3) Extern:- it used to declare a variable that is already define outside of function. Variable of this storage class are “Global variable”. Generally external variable are declared again in this function using keyword Extern. Example: extern intn; // Explicit Declaration. File Edit Search fun Demy Tilele Alt-Pi Next tsa Alt-F? Prev Men Alt-FS Comile F5 Make FiQ ten Q2. Whatis the difference between “while-do” and “do-while” loop? a Yu © Ei /IGNOUASSIGNMENTGURU = “21254202 +91 9811854308 Page No. 5 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee i While loop Dorwhile loop. y Syntax: - Syntax: - i While (condition) Do iH { if | Statements; //body of loop Statements; //body of loop "| } }while (condition); | In “while” loop the controlling condition In “do-while” loop the controlling condition appears at the start of the loop. appears at the end of the loop. While loop check the condition on top part | Do-While loop check the condition on of loop. If evaluates true then executed the | bottom part of loop It acquits statement first statement otherwise terminated the loop. there after condition is checked it available true than repeat the loop otherwise stop the execution, Examples:- While loop Do-while loop ‘Hinclude #include finclude #ineludecconio.h> Void main() Void main() { 4 In 210; int a=t0 While(a<=3) do ¢ 4 ae ase; printf(‘%d",a); printi("%d",a); } }While(a<=3); getchd; } ae “Terminated the logp Because condition ie fales, | By dafault do- while loop one ime execution. Q3. Design a flowchart and then write a program in C to convert a given complete String to upper case. ‘Strupr: - Strupr function convert a string to upper case. SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +919811854308 Page No.6 x SOLVED ASSIGNMENTS ‘ASSIGNMENT GURU File Fait Search fun Compile Debug Project Options window Help. = —1-1t15 gets Ween Man ter. ca ths oy ul = Alt-FB Next Msg fAlt-F? Prev Msg Alt-F9 Compile F9 Make F10 Menu Fi telp Output: - Input a string to convert to upperc: Cece sear sos input string in uppercase: DIGITAL MANTRA_ ut @ ASSIGNMENT" 491 9811854308 +919811854308 Page No.7 SOLVED ASSIGNMENTS q Output: - FPtnerp Fe Save" F3 Open Alt-P9 Comite 9 take T10 fem Window Help sere Input a string to convert to uppercase digitalmantra wipe ASSIGNMENT! 491 9811854308 es +91 9611854308 Page No.8 2 ‘SOLVED ASSIGNMENTS igno ‘wn, AnGUnESIG piiaritguru.com ‘ASSIGNMENT GURU Flow chart ere + STRING [50],*C INPUT STRING + *C=STRING [0] co | | —-——_ PRINT STRING ST ET RT TT ST EE ARIST NIST ITI Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No.9 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Boot GURU Q4, What do you means by" “array of pointers”? Write a program in C to calculate the sum of the corresponding elements of two array of integers of same size. Array of Pointer is an indexed set of variables in which the variables are pointers (a reference to a location in memory). Pointers and arrays are very closely linked in C. Array elements arranged in consecutive memory location. ‘#include #include Void main() { Int a[10}, Int bi10}, Int sum[10} Int in Cirser(); Printt("Enter the size of array A and Bin’); Scanf("%d",&n); Printf("enter the elements of array A\n"); for(ieO;icnji++) { Scanf("%d" &al]); Printf“Enter the elements of array B\n"); for(i=O;icnji++) { Scanf("%d" 8afi}); } Printf(‘enter the elements of array Bin"); for(i=O;i 8& OR > 11 NOT?! AND: - itis represented by ampersand (8&) and works between two conditions or logical expression and retumn ‘True’ (if both conditions are ‘True’) otherwise ‘False’. Conditional 1 Conditional 2 AND T T fli CASsion| me Ssh F F F F F OR: -itis represented by pipeline sign (|) it works between two conditions or logical expression and ‘return True’ if either condition is True’ SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No.1! SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee | Conditional 1 Conditional2 ‘OR 4 1, 7 ij i T F T Hl F T T E F F F | NOT: -itis represented by exclamation ().t checks one condition at @ ime ane return result as reverse of condition. Conditional 7 NOT T F F T Precedence of Logical operators: - when an expression contains all the three logical operators AND, OR NOT. NOT gets Precedence Level. AND operator gets precedence level2 and OR gets precedence eve. Which means firstly, you will calculate NOT, secondly AND, Thirdly OR operator. Precedence Type of operator 1 NOT 2 AND 3 OR 3. Assignment Operator: - Assignment operator assigns a value to a variable. Assignment operator Example Explanation a=10 10 store into a Q6. What is the different between ‘&' and ‘&&’ in C? Explain with an example. && operator isa logical and & is bit-wise operator. Therefore, && operator always evalustes to true or false. .2 1 or O respectively while & operator evaluates bit wise so the result can be any value. For Example: - 3>5886>4 > 0 Operan: Operand second 1/0 Resuli(&) def 4s] 0u|Sasfinr|raer|teul ow [c3. SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 12 SOLVED ASSIGNMENTS a loop that calculates the sum of n elements of the following series: 14447410413 Use the loop during Programming in the following two different ways: () Using while loop (i) Using do-while loop | iH | y e Using while loop: - File Edit Search Run Compile Debug Project Options Window Help sores Using do-while loop ASR RY RY AAT EY OO AT YotD © Fi ASSIGNMENT" 491 9811854308 TS saimnats x SOLVED ASSIGNMENTS ‘ASSIGNMENT GURU rassignmentg Tieng Den Ceres oon eens ee ee er oa Q8. Write do you mean by scope of a variable? Differentiate between global and local variables giving an example of each. Scope: the scope of & variable determines over what part(s) of the programa variable is actually available for use (active) Types of scope of variable © Global + Local Global Local ] Itis declared outside of function It is declared inside of function. | Itdestroy when program exit It destroy when function Exit. | i [Tt can be access from anywhere. It cannot be access from another function. a Hl Life-Time [Active in Memory]is until that Life-Time [Active in Memory] is until that | program is executed. function is executed | They are stored in Date segmentarea, whichis | They are stored in Stack. F public area, Hence they are also called as public ) variables. F iH | Contact n: - 8802141759 13 | 35 | nti @ fi 1GNOUASSIGNMENTGURU "5408 +91 9811854308 Page No 14 www.ignouassignmentguru.com SOLVED ASSIGNMENTS Example:- re oea include include conio.h> Struct student ( int Roll_no; Float math, english, hindi,computer, DM; Char name[10] class_narne[10]; Float marks, total,avg; i ; | | yl a Yu © Ei /IGNOUASSIGNMENTGURU = “21254202 +91 9811854308 Page No. 15 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Boot GURU } Main() 1 Struct student s{10]; Intl; Clrser(); Forti: int) { Printi("Enter the roll number:”); Scanf(%60”, &s{].roll_no); Printf(“Enter the student name:”); Seant{"5s" &sfi]. name); Printf(“Enter the classe” Scantfl"%s" &s[i.class_name}; Printf(“Enter the marks math, english, hindi, computer, DM"); Scanf(“%FHth6rIeAYF", Rf. math &s[ilengish &s[iJhindi,&s[i] computer 8s[i].DM); Totalemath+English+hinditcomputer+DM; Avg=total/; If (avg>=80) Printf("A”): Else if (avg: Printf("3"); Else if (ave>=50) Printf("B"); Else if (avg>=40) Printf("C"); Else Printf(“FAIL"); Li] See ee 2) stremp():- itis used to compare two string. If string are matched then return Zero. stremp also passes the address of the character array to the function to allow it to be accessed. File Edit Search Run le Deb je Window Help I we F3 Oven Alt-F9 Compile Fr) Make 10 Menu | fr Output: - ‘w{} © Fi /IGNOUASSIGNMENTGURU *'"+08 +91 9811854308 Page No. 17 > SOLVED ASSIGNMENTS 1gnou pa eer ‘ASSIGNMENT GURU [ Owasamus eres | the na matehed i e getchar(): - getchar is a function in c programming language that reads a single character from i the standard single character from the standard input stream stdin. It is include in the stdio.nneader [é file. i tons__Windou_He i : P iH i) gets(): - Reads characters from the standard input and stores them asa st puts(): - prints characters from the standard output. Just like printf statement. a Yu @ Ei /IGNOUASSIGNMENTGURU "25+ +91 9811854308 Page No.18 ~ SOLVED ASSIGNMENTS ‘ASSIGNMENT GURU Q11.(b) Write a program to multiply 2 matrices of size 3 x 3. #inelude Hinelude z Int main () { Int hike int first{3][3],second[3}(3],mull3][3]j//declaration of a array Clrser(); forli=0:ie3;i++) for(j=0)<3)++) { Printf(“Enter the number into first array”); Scent {%d!",&éirst{iJ[j]); /* set each element toa value */ ) } Msecond array// Printf("\n\n"}; forli=0;i<3;i++) forlj=0:j<3:++) { Printf"Enter the number into second array’); Scanf(“%d",&secondli[)): /* set each elements to a value */ } } Clrsert); ‘oD @ Fi /IGNOUASSIGNMENTGURU “254202 +91 9811854308 Page No. 19 ‘SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee Printf(°First array :\n”}: forli=O;i<3;i++) { for(j=0:}<33++) { Printf(“%d\e",first{i)L)): } Printf("\n"}; } Printf(*second arrays\n"}; for{i=0;i<3;i+#) { forlj=0<3;++) { Printf("%q\t" secondfi]l]); } Printf(*\n"}; } Printf(“mul(first*second):\n"); forli=O:ic3it+) { forlj=0<3)++) { MulliJL}: fFor(k=0;k<3}k++) { mulfili}=mulli)j}+first{l[k]*second[kIU}; } Printf("=9d\t" mull] L]); } Printf("\n"}; } getch(); } Q12. Write a recursive program in c to check whether a given string is a palindrome or not. Recursive function: - A function that is called self on body is called recursive function. It has two parts one part is base part that treatment the execution and second part is iterative part. #include SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | #include ff] include nt palindrome (char “inputString, int leftindex, intrightindex); { Contact n: - 8802141759 Page 19|35 wi E11 GNOUASSIGNMENTGURU "9+ +91 9811854308 Page No. 20 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Boot GURU Int main, { Char inputstring[100}: Printf(‘Enter a string for palindrome check\n"); Scanf("%s", inputstring); lf(palindrome(inputstring, 0, strien(inputstring) -1)) { Printf(‘%s is 2 palindrome \n’inputstring); } Else { Printf(“%s is @ not palindrome \n’,inputstring); } getch(); retum 0; /*Function to check whether a string is palindrome or not*/ Int palindrome (char ‘inoutstring, int leftindex, int rightindex) { If(NULL==inputstring || leftindex <0 || rightindex < 0) invalid input"): 7° Recursive termination condition */ H(leftindex >= rightindex) return 1; (inputs tring[leftindex] == inputString[rightindex}) Tetum palindrome(inputstring, leftindex + 1, rightindex — 1); } retum 0; Output:- Enier a string for palindrome check MADAM MADAM is a palindrome 14, Explain the syntax of switch case statement in c language. Also compare the performance of switch case with if else statement. Switch Ifelse ] ST ET RT TT ST EE ARIST NIST ITI Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 21 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee | itis multi decision statement that is used fo | itis multi decision statement that is used to | check equivalent condition only. check less then, greater then and equivalent H conditions. i ‘Syntax:- switch(variable) ‘Syntax:- if(condition) { Statement i ‘Case 1: else if(condition) | Statement Statement |] Break; else if(condition) Case 2: Statement ‘Statement else Break; ‘Statement Default: § ‘Statement Q.15.Explain the concept of dynamic memory allocation with an example. Dynamic Memory Allocation and Dynamic Structures Dynamic allocation is a unique and important feature to cand other high-level languages. It enables us to create data types and structures of any size and length to suit our programs need with in the program. We will look at two common application of this. Dynamic arrays © Dynamic data structure e.g. linked lists Function Use of function malloc () Allocates requested size of bytes and returns a pointer first byte of allocated space calloc() Allocates space for an array elements, initializes to zero and then returns pointer to memory. free() Deallocate the previously allocated space. Realloci) Change the size of previously allocated space. The function malloc is most commonly used to attempt to “allocate” a continuous portion of memory. It defined by: Void *malloc(size_tnumber_of_bytes) SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 22 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee That is to say it return a pointer of type void * that is the start in memory of the reserved. portion of size number_of_bytes. If memory cannot be allocated a NULL pointer is returned variable, Also it is usual to use the sizeof) function to specify the number of bytes, For example: - Int *ip; ip = (Int *)malloc(100*sizeof(int)); A Sizeof() can be used to find the size of any data type, variable or structure, simply supply ‘one of these as an argument to the function. Free() —this allow the memory Freed that ta be available again possibly for further malloc() calls the function free() takes a pointer as an argument and frees the memory to which the pointer refers. Galloc and Realloc ‘The are two addition memory allocation function calloc () and realloc(). Their prototypes are given below: Void *calloc(size_t_num_elements size_t new_size);, Void *relloc(void *ptr, size_t new_size); Example: - write a c program to find sum of n elements entered by user. To perform this program, allocate memory dynamically using malloc() function. #include Hinclude«stdlib.h> Int main() { Int num,,* ptr sum= intf(“Enter number of elemnts: Scanf(“9d”,&num); Ptr=(int*)malloc(num *sizeof{int if(ptr==NULL) { Printf{“Error! Memory not allocated.” Exit(0);) tH(“Enter elements of array:”}; num;+#i) Scanf("%d" tri); Sum+=*(ptr + i); } Printf(“Sum=%d" sum); free(ptr); return 0; } ST SSE ET EY EIR BET SY RT ES EY EGY ASSIA SEIT | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 23 ‘SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee Q16.Explain the use of the following data types with an example for each: {i) enumerated data type (ii) typedef Enuumerated:- Enumerated types contain a list of constants that can be addressed in integer values. We can declare types and variable as follows. Example enum day{mon,tues....,sun}week; enum days week1,week2; /declare variable of enumerator of days NOTE: As with arrys, first enumerated name has index value 0. So mon has value O,tues 1, and so on. Weekt and week? are variables. ‘We can also override the 0-start value: ‘enum months [ian,feb,mar,...dech here it is implied that feb=2etc. Example of enum #includecstdio.h> #include ‘enum days(Monday,Tuesday, Wednesday, thrusday, friday Saturday Sunday}; ‘enum days dd; main() { Cirser(); dd=Tuesday; if(éd void main() ‘ int factorial); int FACT,NUM; clrser(); printf(“ENTER NUMBER : “); scanf(“%6d",&NUM); if(NUM>0) printf(°\nFACTORIAL OF GIVEN NUMBER IS %d “FACT; } else printf(’\nERROR:GIVEN NUMBER IS %d NEGATIVE”, NUM); getch(); 1 Se Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 25 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Em Te = int factorial(int N) { int RESULT; if(N== return(1); else RESULT=N*factoriel(N-1); return(RESULT}; t Flow chart + READ n ae FACT =1 Error Fact = Fact *n C stop) ST ET RT TT ST EE ARIST NIST ITI Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 26 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee Q19.Write a program in “C”, using structures to calculate the gross salary of employee? include int main() { Float basic, gross, da, hra; 1 Read basic salary of employee printf( "Enter basic salary of an employee: scanf("%f", &basic); // Calculate D.A and H.R.A according to specified conditions (basic <= 10000) da =basic * 0.95; bra = basic * 0.3; I Calculate gross salary gross = basic + hra +da; printf("GROSS SALARY OF EMPLOYEE = %.2F', gross); return 0; ? Q20.Write a program to take a no and find itis prime no or not? Prime number: - divisible by 1 and itself Hindudecstdio.h> #include Void main() ( Inta, b=1, ctr=0; Contact n: - 8802141759 e 26|35 ST SSE ET EY EIR BET SY RT ES EY EGY ASSIA SEIT | +91 9811854308 Page No.27 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Boot GURU Clrser(); Printf(“Enter the no:”); Scanf("%sd”, &a); While(b<=a) { If(a%b==0) ( caret; d b=b+1; } If(ctr==2) { Printf(“The no is prime =%d" , a); d Else { Printf(“The no is not prime=%6d", a); Getch(); ? Q21.Write a program to swap two values of variable using pointer? include int main() { int x,y, *a, *b, temp; printf("Enter the value of x and y\n"); scanf("%4d0éd", Bx, &y); printf{"Before Swapping\nx = %d\ny = %d\n", x,y}; printf("After Swapping\nx = %d\ny = %éd\n", x,y); return 0; } Q22. Draw a flow chart and write a program in c to implement binary search in a given list of number. ST SSE ET EY EIR BET SY RT ES EY EGY ASSIA SEIT | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 28 ~ SOLVED ASSIGNMENTS igno ‘wn, AnGUnESIG piiaritguru.com ‘ASSIGNMENT GURU bege=last Mid=(begrlast)/2 elaine last=mid-1 | Larget found of mid Big=mid+1 Item not found ST ET RT TT ST EE ARIST NIST ITI Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 29 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Boot GURU Hincludecstdio.h> Hiinclude define max 10 Int bsearch(int arr[J, int n) { Int beg,last,mid; beg=0,last=max-1; while(beg<=last) { mid=(beg#last)/2; return mid; else if(n>arr{mid]) beg=mid+1; else last=mid-1; - Return -1; - Void main() { Int arrlma Int n,find; clrser(); printf(“enter the number for searching”); scanf("'%d”, in); find=bsearch(arr.n); ifffind==-1) 2,3,4,5,6,7,8,9, 10}; printf(“not found” else printf(“found at the position=%d",find); getch(); } Q23.Explain call by value and call by reference? SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 30 www.ignouassignmentguru.com SOLVED ASSIGNMENTS arguments is passed to formal arguments of ‘the function and any change made to the formal argument in the called function have no effect on the values of actual arguments inthe call by value. Hincludecstdio.h> fincludesconio.h> Void swap (int, int ); Void main() { Int, int b; Printf(“Enter any two no:"); Scanf("%d %d", &a, &b); swaple, b); Geteh(); ) Void swap(int c, int d) { Int temp; Tempzc; ced; d=temp; printf|"The value=%d",c); printfi“the value=%d",d); getch)); } location (address) of actual arguments is passed to formal arguments of the called function. This means by accessing the addresses of actual arguments we can alter them with in from the called call by reference findudesstdio.h> ffinclude Void swap (int*, int * Void main() { Inta, Int; Printf(“Enter any two no: Scanf{*9id %d", 8a, &b); swapla, b); Getcht); } Void swaptint *e, int *a) { Int temp; printf(“The value=%q",c); printf(“‘the value=9%d" d); getch(); t (24: - What is pointer? Write advantage it? Also give example? And explain pointer to Arrays and pointer to Array? Pointer: - pointer is @ variable which contains the address in memory of another variable.so it is called pointer. Exemple :- #includesstdio.h> Void main() i Float, b; Float “fp, *fp2; 2; printi(‘value of ais %f, address of a \n", a, &al; Mp=8a; SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 31 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee Printf(“value in memory location fp is %6f\n", *fp); *fp=9.2; Printf(“new value of a is %f\n”, “fp, a); *fo="fo+1.5; Printf(“Final value of a is %f=%f\n",*fb,a); fb2=fb; printf( "Transferred value into b=%f and fb2 =%f\n", *fb2); Advantage ‘* Returns more than one value from a function. ‘+ Easy string and array manipulation ‘* Dynamic memory allocation. ‘* Create complex data structure such as linked list. Pointer and arrays are very closely linked in c. Array elements arranged in consecutive memory location. Pointer to array Array of pointer Main() Main() { { Int numt]={10, 20,30,40, 50, 60, 70}; Int *num[3]; Inti, "i; Int a,b, ¢; Cirser(); Cirser(); J=&num(0]; Num(0]=&a; For(i=0;ic5;i++) Num(1]=&b; { Num[2]=&c; Printf(““addresss of elements =%u”,j); Printf(“elements =%d”, num|[0]); Printi(“\telements of array =%u\n”, *); Printi(“elements =%d”, num(1}); Jet Printi(“elements=%d”, num{2)); } Getch\(); Getch(); } } 25: -Expalin different types of jumps statement? «The continue statement: - the continue statement the current iteration of a loop and instead jumps to the next iteration For Example For(i=0;i<10;i++) { Wi==5) SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 32 ‘SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee Continue } ‘* The break statement: - A break statement may appears inside a loop (while, do while, for) or switch statement. It cause a jump out of these constructs and hence terminates them. For example Break; } * The goto statement: - the go to statement provides the lowest-level of jumped it has the general from. For example: - Lab: Printf(“Enter the number”); Scanf(“%d”" Ba); If(a>=10) goto lab; * The return statement: - the return statement enables a function to return a value toits caller. It has the general fro Return expression: Int main(void) { Printf{“hello\n”); Return 0; } 026:- write the program to display the string “COBAL” in the following format. c co co coBo coBoL ‘coBo co c Hinclude Main () { Int is Static char string[)=”COBOL’ ST SSE ET EY EIR BET SY RT ES EY EGY ASSIA SEIT | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 33 ‘SOLVED ASSIGNMENTS www ignouassignmentguru.com pe. | Printf(*\n"); i | For(i=0;i<5;i++) | 4 “t id Fl Jit; E l Printf(°%5.*s\n", j, string); ll Hy i 4 For(i=4;j>=0;j++) F i ff Printf(“%d5.*s\n",j ,string); - } i ie Q27:- What is structure? Explain with Explain pointer of structure with example, l example? finclude i Structure provides a way of storing different | Struct student t type of value in variables under the same | { name. it s used struct keywords Int roll E Example of Structure Char name(10); f ‘#include Int m; ;| Struct student b | { Main() R| Int roll; { i Char name[10]; Struct student *s; | Int m; Cirser(); fF k Printf(“Enter roll”); yl Main() Scanf(“%d", &s->roll); | { Printf(“Enter marks’ i Struct student 5; Scanf("%d",&s->m); H Int; Printf(“enter name”); | Cirser(); Scanf("%s", s>name); 4 Printf(“Enter roll”); Printf("Roll=%d”, s->roll); Scanf{"%d",&s.roll); Printf("\tName=%s", s>name); Printf(“Enter marks”); Printf(“\tMarks=%d"\n", s->m); 5 Scanf("%d", &s.m); Getcht); i Printf("Enter name”); } | Scanf{“%s”, &s.name); | Printf(“Roll =%d’, s.roll); i Printf(“Marks =%d" s.m); i Printf(Name=%s\n", s.name); q Getch(); F me I i yi Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 34 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee i 4 (@2B:- What is Union? Explain with example | @25:-What is File? Write a program to read and H _ write file? F Untoa: A union is 3s well a6 structure Ai isa collection of bytes soredon a secondary storage i variable but all member of union shared device. The collection of bytes may be character, words, q same memory. The union keywords is used | lines, paragraphs and pages from a documert. | to create unions, for Example: Meteor Ey finclude sw forwting Union student +3 for appending totho fle ( Weigle acludecstio > Int roll; Main() Char name[10}; ‘ ¢ ruc on; a Char ch; Main() Print(-Dota input"); { F-fopont‘tigakantra", Ww", Union student s, t: erence} Int i; Fouto(ch, #1); Cirser(); 1 Printf(“Enter roll”); nae Scanf("%s”,&t.name); Reading file Printf(“Roll=%d",s.roll); ‘Alncludecsido.h> Printf(“Name=%s\n" t.name); a Getcht); 1 eae Chareh; Creer Printt("\y output Fram the ile dligitsimantra \n"); Fo=fopen| digitalmantra’, "1"; While((ch=‘eetctp) EOF) 4 Print", chi; } {dosetto) sgeteh ) Name Fanetion Fopen|) opens afile Felose)) loses afile Patel) virites a character toa file Four) samo asgetc{) Fseek() seekto a speuiflled bytes in a fle Forint) Isto fle what printf) sto the Fcanfi) is tofle what scanf) isto the console, SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00 +91 9811854308 Page No. 35 SOLVED ASSIGNMENTS www.ignouassignmentguru.com Bee i 'Q30:- What is Function Prototyping? Explain | Q31:- Write Bubble sort program H with example. finclude Hl Ifa function has been defined before it is used. IF | Void bubble(int arr[], int size) El NOT then you must declare the function. The if ] tara ay Sia uieojea htc | pj ter i returns and the type of parameters used bythe | ror(i=ojicsizesi++) H function. { Example of prototype function Hinclude ForlsOicsizeitts) Int sum(int a, int b) { { if(arrfi}>arri+1]) Main() { { Temp=artlil: Int a,b; arrliJ=arrli+41); Print|"Enter two number:”); arr{j+1}-temp; Scant("%d%d",&a, &b); ey Printi("The product of your two numbers is | Void displint arrll int size) d\n", sums, yb); ( Sete eee s Cirser(); is ouleinta it) Printf(“\n\n Bubble sorting si \n\n”); Return at; Forli=Ojicsizeri++) } Printf(“%d\t", arr[i]); x Void main) { Int af]=(4,3.9.6.8,98,5); Bubble(a, 7) Displa, 7); Getch(); } SS SSE ET ASST EER ET ET SEA SN EY ET SEAT TET | Yu © Ei /IGNOUASSIGNMENTGURU =*""=5#00

You might also like