You are on page 1of 6

LAB#11

DATE:27/5/13 LABTASK #1

Q1) Write a program to create sequence of first 20 natural numbers with their respective addition in next column by using while loop ? SOURCE CODE: # include<stdio.h> # include<conio.h> void main(void) { clrscr(); int r=1; int h=0; while (m<=20) { u=r+h; printf("\n%d\t %d",r,h); m++; } getch(); }

LAB#11
Page 1

DATE:27/5/13

OUTPUT:

Count 1 Count 2 Count 3 Count 4 Count 5 Count 6 Count 7 Count 8 count 9 count 10 count 11 count 12 count 13 count 14 count 15 count 16 count 17 count 18 count 19 count 20

total=1 total=3 total=6 total=10 total=15 total=21 total=28 total=36 total=45 total=55 total=66 total=78 total=91 total=105 total=120 total=136 total=153 total=171 total=190 total=210

LAB#11
Page 2

DATE:27/5/13

LABTASK #2 Q2) Write a program to calculate cube of a number and repeat the program until user requirement by using while loop ? SOURCE CODE: #include<conio.h> #include<stdio.h> void main () { clrscr(); int m; char k='y'; while (k=='y') { printf("\n\n Enter any number"); scanf("%d",&m); printf("NO:%d\t Cube of number:%d",m,m*m*m); printf("\nrun again (y)?"); k=getche(); } getch(); }

LAB#11
Page 3

DATE:27/5/13

OUTPUT:

Enter any number5 Num:5 Cube of Number:125 run again(y)?y Enter any number5 Num:5 Cube of Number:125 run again(y)?

LAB#11
Page 4

DATE:27/5/13

LABTASK #3 Q3) Write a program to calculate word count in given sentences by using while loop ? SOURCE CODE: #include<stdio.h> #include<conio.h> void main (void) { int wordcnt=0; int charcnt=0; char ch; printf("type a phrase is :\n"); while((ch=getche())!='\r') { charcnt++; if(ch==' ') wordcnt++; } printf("\nword count is : %d",wordcnt+1); getch(); }

LAB#11
Page 5

DATE:27/5/13

OUTPUT:
type a phrase is : All Is Well Word count is : 3

Page 6

You might also like