Post your C/C++ Programs Here

Status
Not open for further replies.

mavihs

Techie By Heart
Re: Post ur C/C++ Programs Here

can u guys give me a site where i can reffere about c++ & get some solution. & i got this a prob with a question i hav. if u guys can solve it or give a hint or anything.
here it is:-

WAP to display th following format on the screen.(using loop)
Code:
[CENTER][CENTER]1
1   1   1
1   1   1   1   1
1   1   1   1   1   1   1[/CENTER]
  [/CENTER]

plzzzzzzz give the ans or atleast some hint or somthing. I got an exam on monday. i hav 2 prepare for it. i can't understand these question how 2 do. plzzzzz help! i've been trying 2 figure it out for a week. it may come for my exam. plzzzz help!!!!!!
 
OP
Gigacore

Gigacore

Dreamweaver
Re: Post ur C/C++ Programs Here

Try this:
Code:
#include <stdio.h>
main()
{
	int	row, col, t, i;
	int	tab=40;
	for(row = 1; row <= 7; row++)
	{
		for (t = 1; t <= tab; t++) printf(" ");
		/* number if blank spaces from left edge of the screen */
		for(col = 1;col <= row; col++)
			printf("%d ",row);
		printf("\n");
		tab--;
	}
return 0;
}

For C++ tutors...: *www.cprogramming.com/tutorial.html
 

Projjwal

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

do u know wht's the output of following prog
:)) :))

#include<stdio.h>
#include<conio.h>
void main()
{
int c;
c=printf("abc");
printf("\n%d",c);
getch();
}
Don't run it. Just guess it's output . & why?
 

QwertyManiac

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

Intel_Gigacore said:
Try this:
Code:
#include <stdio.h>
main()
{
    int    row, col, t, i;
    int    tab=40;
    for(row = 1; row <= 7; row++)
    {
        for (t = 1; t <= tab; t++) printf(" ");
        /* number if blank spaces from left edge of the screen */
        for(col = 1;col <= row; col++)
            printf("%d ",row);
        printf("\n");
        tab--;
    }
return 0;
}
He needed just 1s and in odd quantities only. :p Good write up though :)
 

ilugd

Beware of the innocent
Re: Post ur C/C++ Programs Here

what does printf return by the way? a return value or some pointer? It would take a minute to google that but I guess that would be cheating. :)
 

QwertyManiac

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

ilugd said:
what does printf return by the way? a return value or some pointer? It would take a minute to google that but I guess that would be cheating.

I think it returns an int. I've seen int in its prototype for sure. But I got no clue what the output of Projjwal's program's gotta be.
 

Projjwal

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

hint:





try it bro....u r partially correct ..It's the value which printf return..But wht is that value.? I give up the ans is
abc
3
 

Quiz_Master

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

Honestly Speaking this is going to be my fevorite thread ever on Digit forum...
BookMarked...
[Its very usefull for a BCA 3rd Sem student of a small town and thats me..:D ]

OK, let me post my Today's Homework here..hehe...

Write a C Program to sort numbers of an Array using Bubble Sort Method.

Code:
#include <stdio.h>
#define MAX 10
void swap(int *x,int *y)
{
   int temp;
   temp = *x;
   *x = *y;
   *y = temp;
}
void bsort(int list[], int n)
{
   int i,j;
   for(i=0;i<(n-1);i++)
      for(j=0;j<(n-(i+1));j++)
             if(list[j] > list[j+1])
                    swap(&list[j],&list[j+1]);
}
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[MAX], n;
   printf("Enter the number of elements in the list max = 10\n");
   scanf("%d",&n);
   readlist(list,n);
   printf("The list before sorting is:\n");
   printlist(list,n);
   bsort(list,n);
   printf("The list after sorting is:\n");
   printlist(list,n);
}

Intel_Gigacore said:
^ theres nothing in Hint

There IS..
Just Highlight the post.
 
Last edited:

Projjwal

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

yea just highlight my previous post or just press "ctrl+ A ".Actually printf is a function with return type integer .Just open stdio.h file from include directory frm there u will got that. And it returns the length of string which it print.so as a result
c=printf("abc")
means printf return value 3 Which saved in C integer variable thats all.
 

Projjwal

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

So,everybody of the forum know swapping using 3rd variable & without 3rd variable .now write a swapping program in c without 3rd variable & de vital point is use one line function only .
means
b=a+b;
a=b-a;
b=b-a;
---------------de above program has 3 functional lines now write it in one functional line.
 

aditya.shevade

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

Easy. Check this out.

Code:
#include<iostream>

using namespace std;

main()
{
	int a, b;
	
	cout << "Enter A and B" << endl;
	cout << "a = ";
	cin >> a;
	cout << endl << "b = ";	
	cin >> b;
	
	a = ((b - a) + (b = a));
	
	cout << endl << "a = " << a << endl;
	cout << "b = " << b;
	
	return 0;
	
}

EDIT : Output :-

Code:
EXECUTING:
/home/aditya/test 
----------------------------------------------
Enter A and B
a = 12

b = 23

a = 23
b = 12
----------------------------------------------
Program exited successfully with errcode (0)
Press the Enter key to close this terminal ...
 
OP
Gigacore

Gigacore

Dreamweaver
Re: Post ur C/C++ Programs Here

I'm using borland Turbo C++, whenever i execute a program, it runs and closes suddenly... it happens in Dev C++ also.. please help
 

Desi-Tek.com

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

reusable java class to send email through pop3

Code:
 /*
 * Mail.java
 *
 * Created on January 1, 2003, 1:58 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ocricket.bean;

import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * 
 * @author Dheeraj
 */
public class Mail {

	public  void sendMail(String toemail, String subject, String body)
			throws MessagingException {
		String host = "mail.ofindia.in";
		String user = "ocricket@ofindia.in";
		String pass = "86qx3@i48fg6";
		// Create properties, get Session
		Properties props = System.getProperties();
		props.put("mail.host", host);
		props.put("mail.transport.protocol.", "smtp");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.", "true");
		props.put("mail.smtp.port", "25");
		props.put("mail.smtp.socketFactory.fallback", "false");
		Session mailSession = Session.getDefaultInstance(props, null);
		Message msg = new MimeMessage(mailSession);
		msg.setFrom(new InternetAddress(user));
		InternetAddress[] address = { new InternetAddress(toemail) };
		msg.setRecipients(Message.RecipientType.TO, address);
		msg.setSubject(subject);
		msg.setSentDate(new Date());
		msg.setText(body);
		Transport transport = mailSession.getTransport("smtp");
		transport.connect(host, user, pass);
		transport.sendMessage(msg, msg.getAllRecipients());
		transport.close();

	}

}
 

QwertyManiac

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

Intel_Gigacore said:
I'm using borland Turbo C++, whenever i execute a program, it runs and closes suddenly... it happens in Dev C++ also.. please help

Dev C++ too? Doesn't the output remain in the console box? Anyway for TC++ you need to call getch(); just before the end of the main function ( Before } ) but I guess you'd definitely know that :confused:

You mean to say that you get the output but not the final result or does it end abruptly in middle (Segmentation fault?)
 
Status
Not open for further replies.
Top Bottom