forked from ShreyaDhir/HacktoberFest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
8 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,12 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() { | ||
char a[5]; // contains garbage values | ||
cout<<"A: "<<a<<sizeof(a)/sizeof(char)<<endl; | ||
|
||
char b[] ={'a', 'b', 'c', 'd', 'e'}; // can end with null or garbage value | ||
cout<<"B: "<<b<<sizeof(b)/sizeof(char)<<endl; | ||
|
||
char c[] ={'a', 'b', 'c', 'd', 'e', '\0'}; // best practice to add null at end | ||
cout<<"C: "<<c<<sizeof(c)/sizeof(char)<<endl; | ||
|
||
char d[] = "hello world"; //size+1 | ||
cout<<"D: "<<d<<sizeof(d)/sizeof(char)<<endl; | ||
|
||
// storing char | ||
char e[100]; | ||
cin>>e; // it can also read boolean string , without spaces, tab etc. | ||
cout<<"E: "<<e<<sizeof(e)/sizeof(char)<<endl; | ||
|
||
// strong using cin.getline() | ||
char f[100]; | ||
// cin.getline(arr, sizeofarray, delimiter) default delimeter is '\n' | ||
cin.getline(f,100); | ||
cout<<"F: "<<f<<sizeof(f)/sizeof(char)<<endl;; | ||
|
||
// read pragraph | ||
char par[1000]; | ||
cin.get(par, 1000, '.'); // when it finds . then stops, at max 1000 char can be read | ||
cout<<"Par: "<<par<<sizeof(par)/sizeof(char)<<endl;; | ||
|
||
return 0; | ||
int num,factorial=1; | ||
cout<<" Enter Number To Find Its Factorial: "; | ||
cin>>num; | ||
for (int a=1;a<=num;a++) { | ||
factorial=factorial*a; | ||
} | ||
cout<<"Factorial of Given Number is ="<<factorial<<endl; | ||
return 0; | ||
} | ||
|
||
|
||
/* | ||
Input: | ||
i am from e | ||
you are from f | ||
what about | ||
the paragraph | ||
you are reading. | ||
Output: | ||
A: 5 | ||
B: abcde5 | ||
C: abcde6 | ||
D: hello world12 | ||
E: i100 | ||
F: am from e100 | ||
Par: you are from f | ||
what about | ||
the paragraph | ||
you are reading1000 | ||
*/ |