

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Instructions
Objective The objectives of this lab are to
For each of the following code try to understand the working of scanf function, try to predict the output first.
#include <conio.h> #include <stdio.h> void main(void) { clrscr(); int A; int B; printf(โEnter a number : โ); scanf(โ%dโ,&A); printf(โValue of A = %d \nโ, A); printf(โEnter another number : โ); scanf(โ%dโ,&B); printf(โValue of B = %d \nโ, A); printf(โThe sum of %d and %d=โ,A,B,A+B); getch(); }
TASKโ (^01) scanf()
Predicted Output c:> c:> c:> c:> c:> c:> c:> c:> c:> c:> c:> c:> c:> c:> c:> c:>
Program-01 : Print numbers from 1 to 10
#include <conio.h> #include <stdio.h> void main(void) { clrscr(); for(int a=0;a<11;a++){ printf(โA = %d โ,a); } getche(); }
Program-02: Print table of 2
#include <conio.h> #include <stdio.h> void main(void) { clrscr(); for(int a=0;a<=10;a++){ printf(โ2 x %d = %d \nโ,a,2*a); } getche(); }
Program-03: Printing even series , by using a for loop
#include <conio.h> #include <stdio.h> void main(void) { clrscr(); int sum=0; printf(โEven series\nโ); for(int a=0;a<=10;a++){ printf( โ%d โ,sum); sum=sum+2; } getch(); }
Program-03A : We can print the same series by another way as given below
#include <conio.h> #include <stdio.h> void main(void) {
clrscr(); printf(โEven series\nโ); for(int a=0;a<=10;a=a+2){ printf(โ%d โ,a); } getch(); }
Program-04: Controlling the for loops from user input
The following program when executed gets two numbers from the users and prints the number between these two numbers. The first number entered should be smaller than the second number.
#include <stdio.h> #include <conio.h> void main(void){
int A,B; printf(โEnter value of A : โ); scanf(โ%dโ,A);
printf(โ\nEnter value of B : โ ); scanf(โ%dโ,B); printf(โ\nNumbers between %d and %d are \nโ,A,B); for(int a=A;a<B; a++) printf(โ%d โ,a); getch(); } Program-05: printing the sum of first 10 numbers #include <conio.h> #include <stdio.h> void main(void) { clrscr(); int sum=0; printf(โEven series\nโ); for(int a=0;a<=10;a++){ sum=sum+a; } printf(โThe sum of first 10 integers = %dโ,sum); getch(); }
TASKโ (^02) Learn the syntax of for loop