Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 29-03-2009, 08:50 PM   #1 (permalink)
Computer Maniac !
 
[rApToR]'s Avatar
 
Join Date: Aug 2008
Location: Jurassic Park
Posts: 33
Unhappy Need Help in Programming .... Its Important !


Plz help me by giving me the following program code ...
(Plz use only 'C' Programming Language .... Conditional Statements and Iterative Statements)
Program #1 : Write a program to check if the given no. is an Armstrong no. ?
Program #2 : Write a program to print ::
Code:
   *
  * *
 * * *
* * * * 
 * * *
  * *
   *

Last edited by [rApToR]; 29-03-2009 at 10:55 PM.
[rApToR] is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 31-03-2009, 09:55 PM   #2 (permalink)
Right Off the Assembly Line
 
Join Date: Mar 2009
Posts: 12
Default Re: Need Help in Programming .... Its Important !

Try this piece of code. (I havnt run it)

scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=rows;j>=1;j--)
printf(" ");
for(k=1;k<=i;k++)
{
printf("* ");
}
printf("\n");
}
for(i=rows-1;i>=1;i--)
{
for(j=1;j<=rows;j++)
printf(" ");
for(k=1;k<=i;k++)
{
printf("* ");
}
printf("\n");
}
-----------------------------------------
Posted again:
-----------------------------------------
scanf("%d",&num);
int temp,digits,places = 0,arms=0,a;
temp= num;
do
{
digits = temp%10;
places ++;
temp = (temp-digits)/10;
}while(temp)

temp= num;
for (i=1;i<=places;i++)
{
digits = temp%10;
temp = (temp-digits)/10;
a = 1;
for (j=1;j<=places;j++)
a = a* digits;
arms = arms + a;
}

if (num == arms)
printf("%d is an Armstrong Number");
__________________
http://geekztips.blogspot.com

Last edited by nasweef; 31-03-2009 at 10:10 PM. Reason: Automerged Doublepost
nasweef is offline  
Old 01-04-2009, 08:18 PM   #3 (permalink)
Computer Maniac !
 
[rApToR]'s Avatar
 
Join Date: Aug 2008
Location: Jurassic Park
Posts: 33
Thumbs up Re: Need Help in Programming .... Its Important !

nasweef nice attempt ...
but there are a few errors such as ...
In program :: Armstrong No. no result is displayed ...
And in Star program display is like this (e.g. for rows=4)
Code:
*
**
***
****
***
**
*
[rApToR] is offline  
Old 01-04-2009, 11:12 PM   #4 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Post Re: Need Help in Programming .... Its Important !

@rApToR:
Mate, it is not quite a smart idea to "outsource" an entire program for others to do. It is advisable that you also post the effort and in what lines you are thinking. After all it is YOU who has to learn and not us.
Anyway you would be already thinking, I would not help you but I will but only one of the problem i.e. the star one.

Now to get the ouput, first of all you want this, right?

Code:
 
    *
   * *
  * * *
 * * * *
* * * * *
 * * * *
  * * *
   * *
    *
Cool. Now you have to think how to achive the pattern. Now you already realise you need a loop(of course we can printf these [] but that would not be the point).
Now decide the position of which the loop should move.

So Draw it again and mark positions where the asterisks have to be printed.

Code:
		    *                      4  
		   * * 		  3,5		 
		  * * *		  2,4,6		 
		 * * * *                 1,3,5,7      
		* * * * *                0,2,4,6,8
		 * * * *	               1,3,5,7	 
		  * * *		  2,4,6	 
		   * *		  3,5	 
		    *		  4		 
		012345678
See, now you need loops which go from 4 to 0 and 0 to 4. So the output loop would go like that. I ran the output loop from 4 to -4 and set the negative numbers as positive ones by my abs() function.
Inside it the outer loop run first an inner loop which will print the blank spaces as well as run another parallel inner loop which will print the alternate spaces and asterisks.

Now here in my code. I have compiled it in gcc -pedantic -ansi, so I think it should work in any C compiler.
Read the code carefully. It will work pattern of any size. For getting the pattern you want as exact enter 3 as input.

Code:
#include<stdio.h>

int abs(int n)
{
	if(n>=0)
		return n;
	else
		return -n;
}

int main()
{
	int n;
	int i,j,k;
	
	printf("Enter a number: ");
	scanf("%d", &n);
	
	
	for(i=n; i>=-n; i--)
	{
		for(j=0; j<abs(i); j++)
			printf(" ");
		for(k=0; k<2*(n-abs(i))+1; k++)
			{
			if(k%2==0)
				printf("*");
			else
				printf(" ");
			}
		
		printf("\n");
		
	}
	
	return 0;
	
}
Now I hope you understand the code.

Regarding the second problem, I WONT solve it for you. Try to attempt it first and if you can't then post again.
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline  
Old 01-04-2009, 11:40 PM   #5 (permalink)
Super Hero - Super Powers
 
n2casey's Avatar
 
Join Date: Sep 2006
Location: Dynamic
Posts: 766
Default Re: Need Help in Programming .... Its Important !

Yes, Liverpool_fan has given a good suggestion. You shud concentrate a little first before asking for help, so that u can learn. If u feel difficulty at any point then ask.
__________________
Minds are like Parachutes :arrow: They work best when open
n2casey is offline  
Old 02-04-2009, 04:47 PM   #6 (permalink)
Computer Maniac !
 
[rApToR]'s Avatar
 
Join Date: Aug 2008
Location: Jurassic Park
Posts: 33
Talking Re: Need Help in Programming .... Its Important !

Oops I forgot to give the program i made !
Sorry guys ...
Code:
/*Program to check if no. is Armstrong no. or not*/
#include<stdio.h>
#include<conio.h>
void main()
{
int rem, num, arm, sum=0;
clrscr();
arm=num;
printf("Enter the number to be checked: ");
scanf("%d",&num);
while(num>0)
{
rem=num%10;
sum=sum+(rem*rem*rem);
num=num/10;
}
if(sum==arm)
{
printf("Number is Armstrong Number");
}
else
{
printf("This number is not an Armstrong Number");
}
getch();
}
... This is the program i made two weeks ago but i din't get the right results ...
Plz check for corrections that can make this program give right results.
[rApToR] is offline  
Old 02-04-2009, 05:16 PM   #7 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default Re: Need Help in Programming .... Its Important !

^ ^ ^
Excellent.

You have only made a tiny mistake mate.

In the line
Code:
arm=num;
should come after:
Code:
printf("Enter the number to be checked: ");
scanf("%d",&num);
Not before.
Your program otherwise runs fine for all 3 digit numbers.
Keep in mind this program would work ONLY for 3 digit numbers.

BTW an advice:
Kindly indent your code, it will go a long way in improving presentation.
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline  
Old 02-04-2009, 06:50 PM   #8 (permalink)
In The Zone
 
Pragadheesh's Avatar
 
Join Date: Jul 2006
Location: Coimbatore
Posts: 403
Default Re: Need Help in Programming .... Its Important !

@raptor
you should try your best in doing homework problems plus get the logic or the way to implement and you do the implementation part rather than getting code from someone. these are the basic c programs. once you start solving them by yourself your interest towards the language would increase and improve your coding skills..
Pragadheesh is offline  
Old 08-05-2009, 08:54 PM   #9 (permalink)
Most wanted
 
rohan_mhtr's Avatar
 
Join Date: Oct 2007
Location: Mumbai (vashi)
Posts: 466
Default Re: Need Help in Programming .... Its Important !

main()
{
int amm 0 temp 0 n x;
printf( enter thealue of n );
scanf( d &n);
x n;
for(;n>0
{
temp n 10;
amm amm+(temp*temp*temp);
n n/10;
}
if(x n)
{
printf( ARMSTRONG NUMBER );
}
else
printf( NOT AMSTRONG NUMBER );

}
rohan_mhtr is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Sujeet
- by gforz
- by soumya

Advertisement




All times are GMT +5.5. The time now is 03:10 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2