C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2012, 08:04 AM
carlodg2294 carlodg2294 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 1 carlodg2294 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 13 sec
Reputation Power: 0
Program

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>

typedef char string [128];
main(){
string memory [16] = {0};
string search;
int choice;
int i;
int size = 0;
while(1){
system("CLS");
int found = 0;
printf("Command prompt\n");
printf("1.) Enter string in database\n");
printf("2.) Remove a string from database\n");
printf("3.) View strings in database\n");
printf("4.) Search a string\n");
printf("5.) Exit.\n");
printf("Choose a number that you want to do.\n");
scanf("%d", &choice);

switch(choice){

case 1:
printf("Entry #%d: ",size + 1);
while(getchar()!='\n');
gets(memory[size]);
size++;
break;
case 2:
printf("Enter entry number: ");
scanf("%d",&choice);
choice--;
for (i=choice; i<size ; i++)
strcpy(memory[i],memory[i+1]);
size--;
break;

case 3:
for (i = 0; i < size; i++)
printf("Entry #%d: %s\n",i+1,memory[i]);
break;
case 4:
printf("Search: ");
while(getchar()!='\n');
gets(search);
// linear search
i = 0;
for (; i< size; i++)
if (strcmp(search,memory[i])==0){
found = 1;
break;
}

if (found)
printf("Data is found in number#%d: %s", i+1,search);
else
printf("Data not found.");

break;

case 5:
exit(1);
break;
}
printf("\n");
system("pause");
}
}

polynomial

#include <stdio.h>
#include <stdlib.h>
#include <math.h>



main()
{
system("cls");
int a[10];
int order, constant, i, power;
float sum,x;
system ("cls");
printf("Enter the order of the polynomial\n");
scanf("%d", &order);

printf("Enter constant for x\n");
scanf("%d", &constant);


printf("Enter %d coefficients\n", order+1);
for (i=0; i<= order; i++)
{
scanf("%d", &a[i]);
}
sum = a[0];
for (i=1; i<= order; i++)
{
sum = sum*constant + a[i];
}

power = order;

printf("Given polynomial is:\n");
for (i=0;i<=order;i++)
{
if (power < 0)
{
break;
}
if (a[i] > 0)
printf("+");
else if (a[i] < 0)
printf("-");
else
printf(" ");
printf("%dx^%d", abs(a[i]), power--);
}
printf("\nSum of the polynomial = %6.2f\n\n", sum);

system("pause");

}
mult

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
int m1[10][10],i,j,k,m2[10][10],mult[10][10],r1,c1,r2,c2;
printf("Enter number of rows and columns of first matrix (less than 10)\n");
scanf("%d%d",&r1,&c1);
printf("Enter number of rows and columns of second matrix (less than 10)\n");
scanf("%d%d",&r2,&c2);
if(r2==c1)
{
printf("Enter rows and columns of First matrix \n");
printf("Row wise\n");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
printf("First Matrix is :\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[i][j]);
printf("\n");
}
printf("Enter rows and columns of Second matrix \n");
printf("Row wise\n");
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
printf("Second Matrix is:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}
printf("Multiplication of the Matrices:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
mult[i][j]+=m1[i][k]*m2[k][j];
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
else
{
printf("Matrix multiplication cannot be done");
}
system("pause");

}

Reply With Quote
  #2  
Old October 29th, 2012, 08:36 AM
G4143 G4143 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 G4143 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 1
Not sure why you posted this but could you surround your code with code tags and possibly try formatting it?

Reply With Quote
  #3  
Old October 29th, 2012, 09:10 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
Agree. I often use int i; myself.

Click here links to a website targeted for working code:
http://code.activestate.com/recipes/langs/c/


I tried your polynomial program.

Zeroth: the program doesn't port well to my operating system.

First off, it doesn't tell me whether to order the coefficients from constant toward higher power terms or the other way around.

Secondly, I used 0 for some of the coefficients. The polynomial displays incorrectly.
Code:
$ ./polynomial
sh: 1: cls: not found
Enter the order of the polynomial
3
Enter constant for x
0
Enter 4 coefficients
1 0 0 1
Given polynomial is:
+1x^3 0x^2 0x^1+1x^0
Sum of the polynomial =   1.00

(I think there was also a system("pause"); statement which I deleted before compilation. Likewise, it wouldn't have worked on my operating system.)




(also, I'm sure that your program would break if I entered a 40th order polynomial.)
__________________
[code]Code tags[/code] are essential for python code!

Last edited by b49P23TIvg : October 29th, 2012 at 09:23 AM. Reason: fix [/url]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Program

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap