PDA

View Full Version : Very Basic C & C++ Examples



xKVQ8x
06-04-2010, 10:10 AM
Hello World [C]



#include <stdio.h>

int main(){
printf("Hello World");
getch();
}


Hello World [C++]



#include <iostream>
using namespace std;

int main(){
cout << "Hello World" << endl;
system("pause");
}


Basic Input Output With Numbers and Words [C]



#include <stdio.h>

char name; //Variable for are name
int number; //Varible for are number

int main(){
printf("Enter your name: ");
scanf("%s", &name);
printf("Enter your number: ");
scanf("%d", &number);
system("cls");
printf("Hello %s, your number is %d", &name, number);
getch();
}


Basic Input Output With Numbers and Words [C++]



#include <iostream>
#include <string>
using namespace std;

string name; //Variable for are name
int number; //Variable for are number

int main(){
cout << "Enter your name: ";
getline(cin, name); //We use this instead of a normal cin to get the full name if the user entered any spaces
cout << "Enter your number: ";
cin >> number;
system("cls");
cout << "Hello " << name << " your number is " << number << endl;
system("pause");
}