Post your C/C++ Programs Here

Status
Not open for further replies.

Nav11aug

In the zone
Re: Post ur C/C++ Programs Here

I think he means that he cant see the output, nt terminating in the middle of smthin. Program completes execution and closes window
 

Projjwal

free world from money
Re: Post ur C/C++ Programs Here

@aditya.shevade It's very cool ans.Gr8 job ...I was just looking for this ans.
Now do the same thing without using "()" .

use Bitwise Operators
--------------------------------------------------------------
#include<stdio.h>

#include<conio.h>
void main()
{
int a,b;
a=12;
b=25;
a=((b-a)+(b=a));
printf("\na:%d\nb:%d",a,b);
getch();
}

This is de C version of aditya.shevade run it.
-----------------------------------------------------------
 

Quiz_Master

* Teh Flirt King *
Re: Post ur C/C++ Programs Here

^^^^ WHAT????
I dont think anyone here can do that.....

It will require a whole app to be coded not just a single C++ program.
 

Projjwal

free world from money
Re: Post ur C/C++ Programs Here

@Batistabomb i think it's not so easy . U have to develop a C++ program with directX .So u have to know directX programming in other language like VB.NET,C#.net DirectX programming r easier then C++.
 

Batistabomb

Deadman Walking
Re: Post ur C/C++ Programs Here

dude what's the need for directx here i want code in windows environment through any API in c++,is any api's located for c++
 

quan chi

mortal kombat
Re: Post ur C/C++ Programs Here

just fooling around with a simple program.:D
#include<iostream.h>
#include<conio.h>
void main()
{getch();
int n;
cout<<"enter a no between 1-3."<<endl;
cin>>n;
switch(n)
{case 1:
cout<<"you won!!"<<endl;
break;
case2:
cout<<"you lost!!"<<endl;
break;
case3:
cout<<"theres a tie "<<endl;
break;
default<<"please follow the above instructions."
break;
}
}
 

Batistabomb

Deadman Walking
Re: Post ur C/C++ Programs Here

guys i had a nice c++ turorial in a simple english if anyone needs i can send for your mails
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

That swapping thing cost me 6 marks in an exam last year (In C). The teacher refused to believe it works, and when I showed it in the lab, she said its not the right way to do it :| People ..

@Batistabomb - Projjwal is right I guess, .Net would be the easiest way, using Microsoft's APIs. Anyway check these links, I got no idea how to use them though.

*www.microsoft.com/speech/speech2007/speechdevarticle.mspx

Same in wiki's language:
*en.wikipedia.org/wiki/Speech_Application_Programming_Interface
 

Nav11aug

In the zone
Re: Post ur C/C++ Programs Here

QwertyManiac said:
That swapping thing cost me 6 marks in an exam last year (In C). The teacher refused to believe it works, and when I showed it in the lab, she said its not the right way to do it :| People ..

nthn surprisin.. people(especially teachers) dnt appreciate the smart ways of doin things.. got many marks cut when in school fr using KeyB shrtcuts everywhere in Office :((
 

The_Devil_Himself

die blizzard die! D3?
Re: Post ur C/C++ Programs Here

I couldn't agree more.In many a cases students are way smarter than teachers.Today my Data structure was asking "hey how do we change resolution in linux(red hat)?" and I was laughing like hell.

Hey guys(and gals of course) don't you think this thread should be made a sticky?The starter please start a poll man--sticky or not sticky.
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Here's something useful with respect to this thread.

This program creates a vB list out of a file given in a particular format.

The format should be:

Title 1
URL 1
Title 2
URL 2

And the output file's content will be the vB code for the following:


List Title​
  • :arrow: Title 1
  • :arrow: Title 2
Would be helpful for those maintaining List threads. And it'd be good if Intel_Gigacore maintains it for this thread too.

Am uploading an example file along, which contains the list for this thread.

And here's the code. Briefly Documented.

Edit: Code removed as the tags inside were getting converted.
Code's attached as digit.txt.

Code:
Download digit.txt below to view code. 
You can rename it to digit.cpp. 
Sorry for the inconvenience
Note: You might find an extra LIST tag at the end of the file but that's cause of the editors. The editors place an extra line at EOF, so can't help it.
I can add a lot of BACKSPACE characters but that's just stupid. So till I find another workaround, this is the code.

title.txt is the input test file.
digitout.txt is the test output file.
digit.txt is the code file. Rename it to digit.cpp to get syntax highlighting.

digitout.txt when pasted here, will look like:

Programs
  • :arrow: Biggest of 3 Numbers.
  • :arrow: Area, Surface Area (SA), Volume, Total SA, etc. of Various 2D and 3D Figures.
  • :arrow: Simple Random Number Lottery.
  • :arrow: Reverse a Number.
  • :arrow: Simple Stack Implementation using Linked Lists.
  • :arrow: Simple Bulls and Cows game.
  • :arrow: Binary, Decimal, Octal Interconversion.
  • :arrow: Simple Incremental Pyramid.
  • :arrow: Sorting of Numbers using Bubble Sort.
  • :arrow: Swapping of two numbers without a Temporary variable in 1 line.
  • :arrow: Simple Switch-Case Example.
Attachments below:
 
Last edited:

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

And here's a sample run. Forgot to add it to the earlier post.

Code:
harsh@qwerty-workstation:~$ ./digit.out 

Digit Forum URL Bulleted List Generator
-------------------------------------

Version 1.0

The Input file must be in the format of Title first and URL next.

Example:
Title1
*URL 1
Title 2
*URL 2

And so on..

Enter the input file's location and name to convert: title
Enter the output file's location and name to store into: digitout
Enter the list name: Programs
harsh@qwerty-workstation:~$

This'd hopefully work in Windows as well. As I haven't added any OS-only code. :)
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

Nav11aug said:
^^ better algo than the one given..

11 @aditya.shevade

Uhh... better than one given where? Please explain what do you mean.

Projjwal said:
@aditya.shevade It's very cool ans.Gr8 job ...I was just looking for this ans.
Now do the same thing without using "()" .

use Bitwise Operators
--------------------------------------------------------------
#include<stdio.h>

#include<conio.h>
void main()
{
int a,b;
a=12;
b=25;
a=((b-a)+(b=a));
printf("\na:%d\nb:%d",a,b);
getch();
}

This is de C version of aditya.shevade run it.
-----------------------------------------------------------

Alright... Will do that... Right now, gotta run for keyboard class (music).


Projjwal said:
This is de C version of aditya.shevade run it.

Oh.... I have a C version of myself now... Didn't know that one :-D

By the way. Had my C orals today. Mid Semester exams. Scored 23/25. Topped the batch of 20 :-D. Orals of remaining 3 batches are still to be held. :-D

Aditya
 
Last edited:

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Orals? :p What are we supposed to do in Orals? :?

Btw, swapping in Python is deadly easy :))

a,b=b,a

That's it, swapped. :))

Here's a running example:
Code:
harsh@qwerty-workstation:~$ python
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35) 
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=25
>>> b=10
>>> [B]a,b=b,a[/B]
>>> a
10
>>> b
25
>>> exit()
harsh@qwerty-workstation:~$
 
Last edited:

Nav11aug

In the zone
Re: Post ur C/C++ Programs Here

aditya.shevade said:
Uhh... better than one given where? Please explain what do you mean.
better than
Projjwal said:
b=a+b;
a=b-a;
b=b-a;
---------------de above program has 3 functional lines now write it in one functional line.
the implementation did not use the line b=a+b.thz why i said "better"
 

Quiz_Master

* Teh Flirt King *
Re: Post ur C/C++ Programs Here

Hey QWERTY.. That program in Post #92 is awesome man...
ThankQ Very Much for that....
 

Nav11aug

In the zone
Re: Post ur C/C++ Programs Here

The_Devil_Himself said:
Hey guys(and gals of course) don't you think this thread should be made a sticky?The starter please start a poll man--sticky or not sticky.

Sticky now ..sweet :)
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

It isn't sticky yet :?

I don't want this as sticky, cause no one would look at it then, as is the case with most stickies. I'd rather vote for a new Programming section :)
 

Quiz_Master

* Teh Flirt King *
Re: Post ur C/C++ Programs Here

This was today's homework.

Write a C program to find an element from an Array using Binary Search Method.

Code:
#include <stdio.h>
#define M 10

void bsearch(int list[],int n,int element)
{
   int l,u,m, flag = 0;
   l = 0;
   u = n-1;
   while(l <= u)
   {
      m = (l+u)/2;
      if( list[m] == element)
      {
	       printf("The element whose value is %d is present at position %d in list\n",element,m);
                 flag =1;
                 break;
      }
      else
            if(list[m] < element)
                   l = m+1;
            else
                   u = m-1;
   }
   if( flag == 0)
   printf("The element whose value is %d is not present in the list\n",element);
}

void readlist(int list[],int n)
{
   int i;
   printf("Enter the elements\n");
   for(i=0;i<n;i++)
       scanf("%d",&list[i]);
}

void printlist(int list[],int n)
{
    int i;
   printf("The elements of the list are: \n");
   for(i=0;i<n;i++)
       printf("%d\t",list[i]);
}

void main()
{
   int list[M], n, element;
   printf("Enter the number of elements in the list max = 10\n");
   scanf("%d",&n);
   readlist(list,n);
   printf("\nThe list before sorting is:\n");
   printlist(list,n);
   printf("\nEnter the element to be searched\n");
   scanf("%d",&element);
   bsearch(list,n,element);
}

Couldn't test it as I am on Linux right now and Have no Compiler installed here.
 
Status
Not open for further replies.
Top Bottom