Loops in C++
(While Loop)
Q1. write a program in C++. your program should print all the numbers from 0-100 on the console screen?
Q2. write a program in C++. your program should print the the table of 2?
Q3. write a program in C++. your program should print the sum of all firs 0-100 numbers on the console?
Q4. what will be the output of the program:
while( 1&& (1||(-100)))
{
cout<<"Good"<<endl;
}
Q5. write a program in C++ to print the sum of all even numbers?
For help:
#include
ReplyDeleteusing namespace std;
int main()
{
int a=0;
while(a<100)
{
cout<<"the number is"<<a;
a=a+1;
}
system("pause");
}
This comment has been removed by the author.
ReplyDeleteQ1
ReplyDelete#include
using namespace std;
int main()
{
int num=0;
while (num<=100)
{
cout<
using namespace std;
int main()
{
int multipleir=1;
while (multipleir<=10)
{
cout<<"2 x "<
using namespace std;
int main()
{
int num=0;
int sum=0;
while (num<=100)
{
sum=sum+num;
num++;
}
cout<<"The Sum of First 0-100 numbers is "<
using namespace std;
int main()
{
int num=0;
int sum=0;
while (num<=20)
{
sum=sum+num;
num=num+2;
}
cout<<"The sum of First 10 Even Numbers is "<<sum<<endl;
return 0;
}
#include
ReplyDeleteusing namespace std;
int main()
{
int a,b;
a=2,b=1;
while(b<=10)
{
cout<<a<<"*"<<b<<"="<<a*b<<endl;
b++;
}
system("pause");
return 0;
}
#include
ReplyDeleteusing namespace std;
int main()
{
int a=0;
while(a<=100)
{
cout<<"a";
a++;
}
system("pause");
return 0;
}
umairilyas853@gmail.com
cms no. 405837
#include
ReplyDeleteusing namespace std;
int main()
{
int a=0,b=0;
while(a<=100)
{
b=a+b;
a++;
}
cout<<b<<endl;
system("pause");
return 0;
}
#include
ReplyDeleteusing namespace std;
int main()
{
int a=10,b=0;
while(a<=20)
{
b=a+b;
a++;
}
cout<<b<<endl;
system ("pause");
return 0;
}
#include
ReplyDeleteusing namespace std;
void main()
{
int a=0;
while(a<=100)
{
cout<<a<<endl;
a++;
}
system("pause");
}
Muhammad Bilal
Section A2
CMS # 406670
#include
ReplyDeleteusing namespace std;
void main()
{
int a=0;
while(a<=100)
{
cout<<a<<endl;
a++;
}
system("pause");
}
Muhammad Bilal
Section A2
CMS # 406670
unlimited time good
ReplyDeleteName :Muhammad Wasif Nazir
section:BSCS section A1
CMS NO.406084.
#include
ReplyDeleteusing namespace std;
void main()
{
int a=2,b=1;
while(b<=10)
{
cout<<a<<"*"<<b<<"="<<a*b<<endl;
b++;
}
system("pause");
}
Muhammad Bilal
Section A2
CMS # 406670
#include
ReplyDeleteusing namespace std;
void main()
{
int a=0,b=0;
while(a<=100)
{
b=a+b;
a++;
}
cout<<"Sum of first 100 num is = "<<b<<endl;
system("pause");
}
Muhammad Bilal
Section A2
CMS # 406670
the output of the program is
ReplyDeleteunlimited times Good
#include
ReplyDeleteusing namespace std;
void main()
{
int a=10,b=0;
while(a<=20)
{
if(a%2==0)
{
b=a+b;
}
a++;
}
cout<<"Sum of 10 to 20 even numbers = "<<b<<endl;
system("pause");
}
Muhammad Bilal
Section A2
CMS # 406670
OUTPUT "GOOD" IS DISPLAYED INFINITY TIMES
ReplyDeleteMUHAMMAD AAMIR SHABBIR
CMS: 406125
SECTION A1
you all guys should mention your name and cms with your code and please comment Question 4 output Question till 11:59 pm
ReplyDeleteThis comment has been removed by the author.
ReplyDelete#include
ReplyDeleteusing namespace std;
void main()
{
int a=0;
while(a<=100)
{
cout<<a<<endl;
a++;
}
system("pause");
}
Muhammad Sheraz
CMS 405646
#include
ReplyDeleteusing namespace std;
int main ()
{
int a=0;
while( 1&& (1||(-100)))
{
cout<<"Good"<<endl;
}
getchar();
return 0;
}
Muhammad Dawood
405909
the output displayed
ReplyDeleteQNO 4;
"GOOD"............
many time print i dont count this
AQEEL EJAZ
405875
This comment has been removed by the author.
ReplyDelete#include
ReplyDeleteusing namespace std;
int main()
{
int a;
cout<<"enter any number"<>a;
while(1&&(1||(-100)))
{
cout<<"Good"<<endl;
}
system ("pause");
return 0;
}
unlimited time Good
Ahtsham Malik(A1)
BSCS
Question no 1=
ReplyDelete#include
using namespace std;
int main()
{
int a=0;
cin>>a;
while(a<=100)
{
cout<<a<<endl;
a=a+1;
}
system ("pause");
return 0;
}
#include
ReplyDeleteusing namespace std;
int main()
{
int a=0;
while (a<100)
{cout<<"The No. is:"<<a<<endl;
a++;
}
system("pause");
return 0;
}
By: M. Fahad Abid
CMS NO:405998
#include
ReplyDeleteusing namespace std;
int main()
{
int a=0;
while (a<100)
{
cout<<"The No. is:"<<a<<endl;
a++;
}
system("pause");
return 0;
}
Name: Mujeeb ur Rahman
CMS NO: 407191
"#include
ReplyDeleteusing namespace std;
int main()
{
int loopindex=0,sumofall=0,summofeven=0;
cout<<"Q#1 ...."<<endl;
while(loopindex<=100)
{
sumofall=loopindex+sumofall;
cout<<","<<loopindex;
if (loopindex%2 == 0)
{
summofeven=loopindex+summofeven;
}
loopindex++;
}
cout<<endl<<endl<<"Q#2 ...."<<endl;
loopindex=1;
while(loopindex<=10)
{
cout<<"2 x "<<loopindex << " = "<< 2*loopindex <<endl;
loopindex++;
}
cout<<endl<<"Operation on Numbers [ 0 - 100 ] "<<endl<<endl;
cout<<"Q#3 The Sum Of All Numbers : "<<sumofall<<endl;
cout<<endl<<"Q#4 Good will print on every line, infinite time."<<endl;
cout<<endl<<"Q#5 The Sum Of Even Numbers: "<<summofeven<<endl;
system ("pause");
return 0;
}"
Name: Muhammad Umer
Name::Ahsan Waheed
ReplyDeleteSection::A
Cms#::406147
Q#1,
#include
using namespace std;
Int main()
{
Int a=0;
While (a<100)
{
Cout<
using namespace std;
Int main()
{
Int a=2;
Int b=1;
While (b<=20)
{
Cout<
using namespace std;
Int main()
{
Int a=0;
While (a<=10)
{
If (a%2==0)
a=a+1; }
Cout<<a<<endl;
System("pause");
Return 0;
}
It will run and output "Good"..
ReplyDeleteQ#4
ReplyDeleteCode will run and output"Good"...
Name:: Ahsan Waheed
Cms#:: 406147
#include
ReplyDeleteusing namespace std;
void main()
{
int a=0;
while(a<=100)
{
cout<<a<<endl;
a++;
}
system("pause");
}
Huzaifa khalid
CMS 406172
section A2
"Good" will continue till infinity appear on console screen.
ReplyDeleteby M SAMEER SOHAIL (406423)
Lab Assignment:4
ReplyDeleteQ1. write a program in C++. your program should print all the numbers from 0-100 on the console screen?
Solution:
#include
using namespace std;
int main()
{
int a=1;
while (a <= 100)
{
cout << a << "\n";
a++;
}
return 0;
}
Q2. write a program in C++. your program should print the the table of 2?
Solution:
#include
using namespace std;
int main()
{
int counter = 1;
int input;
cout << "Enter an integer: ";
cin >> input;
cout << endl;
while (counter < 11)
{
cout << input << "x" << counter << "= " << input * counter << endl;
counter++;
}
system("pause");
return 0;
}
Q3. write a program in C++. your program should print the sum of all firs 0-100 numbers on the console?
Solution:
#include
using namespace std;
int main()
{
int counter = 1;
int input=1;
cout << endl;
while (counter <= 99)
{
cout << input << "+" << counter << "= " << input + counter << endl;
counter++;
}
system("pause");
return 0;
}
Q4. what will be the output of the program:
while( 1&& (1||(-100)))
{
cout<<"Good"<
using namespace std;
int main()
{
int counter = 0;
int input = 2;
cout << endl;
while (counter >=0)
{
cout << input << "+" << counter << "= " << input + counter << endl;
counter++;
}
system("pause");
return 0;
}
JAWAD AHMED-1A-1
406285
Q NO 4:-"GOOD" will continue till infinity.
ReplyDeleteHuzaifa Khalid
CMS 406172
Q#4.output:
ReplyDelete"good" will show unlimited times.
Sarmad Hassan
CMS#406324
Section A2
#include
ReplyDeleteusing namespace std;
int main()
{
int x=0;
while(x < 100)
{
cout<<"Number is: "<<x <<endl;
x=x+1;
}
system("pause");
}
MUHAMMAD UMAIR ANJUM
CMS : 406266
SECTION : A2
QUES NO : 1
DeleteIn Q no.4 infinite loop will execute.
ReplyDelete~406402
QNO#4
ReplyDelete"GOOD"
will continued infinity time.
MUHAMMAD UMAIR ANJUM
CMS NO: 406266
SECTION : A2
#include
ReplyDeleteusing namespace std;
int main()
{
int count = 1;
int a;
cout << "Enter Value: ";
cin >> a;
cout << endl;
while (count < 11)
{
cout << a << "*" << count << "=" << a * count << endl;
count=count+1;
}
system("pause");
return 0;
}
MUHAMMAD UMAIR ANJUM
CMS NO: 406266
SECTION : A2
QUES NO: 2
Deletequest #5
ReplyDelete#include
using namespace std;
int main()
{
int x=40,y=80;
while(x<=80)
{
if(x%2==0)
{
y=x+y;
}
x++;
}
cout<<"Sum of 40 - 80 even numbs = "<< y << endl;
system("pause");
}
MUHAMMAD UMAIR ANJUM
CMS NO: 406266
SECTION : A2
Lab Assignment:4
ReplyDeleteQ1. write a program in C++. your program should print all the numbers from 0-100 on the console screen?
Solution:
#include
using namespace std;
int main()
{
int a=1;
while (a <= 100)
{
cout << a << "\n";
a++;
}
return 0;
}
Q2. write a program in C++. your program should print the the table of 2?
Solution:
#include
using namespace std;
int main()
{
int counter = 1;
int input;
cout << "Enter an integer: ";
cin >> input;
cout << endl;
while (counter < 11)
{
cout << input << "x" << counter << "= " << input * counter << endl;
counter++;
}
system("pause");
return 0;
}
Q3. write a program in C++. your program should print the sum of all firs 0-100 numbers on the console?
Solution:
#include
using namespace std;
int main()
{
int counter = 1;
int input=1;
cout << endl;
while (counter <= 99)
{
cout << input << "+" << counter << "= " << input + counter << endl;
counter++;
}
system("pause");
return 0;
}
Q4. what will be the output of the program:
while( 1&& (1||(-100)))
{
cout<<"Good"<
using namespace std;
int main()
{
int counter = 0;
int input = 2;
cout << endl;
while (counter >=0)
{
cout << input << "+" << counter << "= " << input + counter << endl;
counter++;
}
system("pause");
return 0;
}
Huzaifa Khalid
CMS 406172
ques # 3
ReplyDelete#include
using namespace std;
int main()
{
int x=0,y=100;
while(x<=100)
{
if(x+y)
{
y=x+y;
}
x=x+1;
}
cout<<"Sum of 0 - 100 numbs = "<< y << endl;
system("pause");
}
MUHAMMAD UMAIR ANJUM
CMS NO: 406266
SECTION : A2
Sharafat ali
ReplyDeletecms: 406401
1st semester
#include
using namespace std;
int main()
{
int a=2;
cout<<" now I'm showing the table of 2 "<<endl;
while(a<=20)
{
cout<<"the next value is : "<<a<<endl;
a=a+2;
}
system("pause");
return 0;
}
Question#4:
ReplyDeleteOutput:
"Good"
It will display unlimited times.
Madni Fareed
CMS#406323
Section: A2
Q no:4
ReplyDeletethe output is:
"Good"
This output will show unlimited times.
Abdul Rehman
406311
A2
Question No 4
ReplyDeleteThe Output is
"Good"
It will show infinite times
Saim Bashir
CMS...406979
A2
#include
ReplyDeleteusing namespace std;
void main()
{
int a=2,b=1;
while(b<=10)
{
cout<<a<<"*"<<b<<"="<<a*b<<endl;
b++;
}
system("pause");
}
Name:Sheheryaar
cms: 406231
Post a Comment