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 22-03-2008, 05:52 PM   #1 (permalink)
Alpha Geek
 
ajaybc's Avatar
 
Join Date: Feb 2007
Location: Cochin
Posts: 744
Default Please do these simple C programs for me...


I have to submit my record book this Monday and I have these programs pending.Please do these programs for me as I couldn't get it right when I did it myself.


1.Copy a text file to another in such a way that upper case characters are converted to lowercase vice versa giving the file name of the first file as arguments.

2.Store student details in a file such as name,roll no.,marks and age in a file and find the average age of the students and print the name of the student with the maximum mark.

3.To sort a list of names using a pointer array.

4.To print the sine series.


5.To accept the student details of n students and print the details of the youngest student using structures and functions.


Please use simple programming.
Please post these before Monday

PLEASE....
__________________
Available for freelance web design and web development jobs.
You can view my portfolio here.
Ajay Balachandran

Please contact via PM

Last edited by ajaybc; 23-03-2008 at 09:45 AM.
ajaybc is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 22-03-2008, 06:33 PM   #2 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default Re: Please do these simple C programs for me...

Please post your program code and the members will help you sort it out... Please dont ask others to do your homework... That is not the right way to learn...

Arun
sakumar79 is offline  
Old 23-03-2008, 10:14 AM   #3 (permalink)
Alpha Geek
 
ajaybc's Avatar
 
Join Date: Feb 2007
Location: Cochin
Posts: 744
Default Re: Please do these simple C programs for me...

Quote:
Originally Posted by sakumar79 View Post
Please post your program code and the members will help you sort it out... Please dont ask others to do your homework... That is not the right way to learn...

Arun
Thanks bro for ur suggestion
I am doing the programs now.
Now while doing the 5th program- "To accept the student details of n students and print the details of the youngest student using structures and functions." iam not able to get the correct output.

Please debug it for me.
The code is as shown below:


#include<stdio.h>
typedef struct st
{
int roll,age,marks;
char name[20];
}st;

main()
{
st stud[20];
int i,n;
clrscr();
printf("Enter the no. of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the details of student no.%d:\n",i+1);
printf("Name:");
scanf("%s",stud[i].name);
printf("Roll no:");
scanf("%d",stud[i].roll);
printf("Marks:");
scanf("%d",stud[i].marks);
printf("Age:");
scanf("%d",stud[i].age);
}
f1(stud,n);
}

f1(st s[],int n)
{
int young,i;
young=0;
for(i=0;i<n;i++)
{
if(s[young].age>s[i].age)
young=i;
}
printf("Youngest student is student no:%d\n",young+1);
printf("Name:%s\nRoll no:%d\nAge:%d\nMarks:%d",s[young].name,s[young].roll,s[young].age,s[young].marks);
getch();
}

__________________
Available for freelance web design and web development jobs.
You can view my portfolio here.
Ajay Balachandran

Please contact via PM
ajaybc is offline  
Old 23-03-2008, 10:37 AM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Please do these simple C programs for me...

You've just missed the & operators in your scanf() function calls.

Here's the fixed code (Still non-standard, lest you whine and rest too):
Code:
#include<stdio.h>

typedef struct st
{
int roll,age,marks;
char name[20];
}st;

main()
{
    st stud[20];
    int i,n;
    printf("Enter the no. of students:");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("Enter the details of student no.%d: ",i+1);
        printf("\nName: ");
        scanf("%s",stud[i].name);
        printf("Roll no:");
        scanf("%d",&stud[i].roll);
        printf("Marks:");
        scanf("%d",&stud[i].marks);
        printf("Age:");
        scanf("%d",&stud[i].age);
    }
    f1(stud,n);
    return 0;
}

f1(st s[],int n)
{
    int young,i;
    young=0;
    for(i=0;i<n;i++)
    {
        if(s[young].age>s[i].age)
        young=i;
    }
    printf("\nYoungest student is student no:%d\n",young+1);
    printf("Name:%s\nRoll no:%d\nAge:%d\nMarks:%d\n",s[young].name,s[young].roll,s[young].age,s[young].marks);
    getchar();
}
String input doesn't require an Ampersand in a scanf() statement, but rest all do, arrays or not.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 23-03-2008, 10:55 AM   #5 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Please do these simple C programs for me...

Explain non-standard part?
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 23-03-2008, 11:32 AM   #6 (permalink)
Wahahaha~!
 
Faun's Avatar
 
Join Date: Dec 2006
Location: Pune/there
Posts: 7,675
Default Re: Please do these simple C programs for me...

Quote:
Originally Posted by mehulved View Post
Explain non-standard part?
int main

return 0;
__________________
Blog | Flickr | Battlelog
Spoiler:
Asus Z68 V-Pro|i5 2500k|TRUE Black|Ripjaws X|U2311H|N560GTX|D7000|XONAR STX|RE272|RE0|CC51|XE200PRO Walnut| TD II V2| Ultraphile|N5800

Mono
Faun is online now  
Old 23-03-2008, 11:41 AM   #7 (permalink)
Alpha Geek
 
ajaybc's Avatar
 
Join Date: Feb 2007
Location: Cochin
Posts: 744
Default Re: Please do these simple C programs for me...

Quote:
Originally Posted by QwertyManiac View Post
You've just missed the & operators in your scanf() function calls.

Here's the fixed code (Still non-standard, lest you whine and rest too):
Code:
#include<stdio.h>

typedef struct st
{
int roll,age,marks;
char name[20];
}st;

main()
{
    st stud[20];
    int i,n;
    printf("Enter the no. of students:");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("Enter the details of student no.%d: ",i+1);
        printf("\nName: ");
        scanf("%s",stud[i].name);
        printf("Roll no:");
        scanf("%d",&stud[i].roll);
        printf("Marks:");
        scanf("%d",&stud[i].marks);
        printf("Age:");
        scanf("%d",&stud[i].age);
    }
    f1(stud,n);
    return 0;
}

f1(st s[],int n)
{
    int young,i;
    young=0;
    for(i=0;i<n;i++)
    {
        if(s[young].age>s[i].age)
        young=i;
    }
    printf("\nYoungest student is student no:%d\n",young+1);
    printf("Name:%s\nRoll no:%d\nAge:%d\nMarks:%d\n",s[young].name,s[young].roll,s[young].age,s[young].marks);
    getchar();
}
String input doesn't require an Ampersand in a scanf() statement, but rest all do, arrays or not.


Thanks for the program.It works fine.

I now did the 1st program now.
"Copy a text file to another in such a way that upper case characters are converted to lowercase vice versa giving the file name of the first file as arguments."

#include<stdio.h>
main(int argc,char *argv[])
{

FILE *fone,*ftwo;
char a;
clrscr();
fone=fopen(argv[1],"w");
printf("Enter the contents of %s:\n",argv[1]);

while((a=getchar())!=EOF)
{
fputc(a,fone);
}

fclose(fone);


fone=fopen(argv[1],"r");
ftwo=fopen(argv[2],"w");
while((a=fgetc(fone))!=EOF)
{
if(isupper(a))
fputc(tolower(a),ftwo);

else if(islower(a))
fputc(toupper(a),ftwo);

}

fclose(fone);
fclose(ftwo);
ftwo=fopen(argv[2],"r");
while((a=fgetc(ftwo)!=EOF))
{
printf("%c",a);
}
fclose(ftwo);
getch();
}




everything in this program works fine.it creates two files and copies the contents and converts uppercase and lower case.
The problem comes only when it is displaying the contents of the second file.It shows some rubbish.Please debug this
__________________
Available for freelance web design and web development jobs.
You can view my portfolio here.
Ajay Balachandran

Please contact via PM
ajaybc is offline  
Old 23-03-2008, 11:59 AM   #8 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Please do these simple C programs for me...

Quote:
Originally Posted by T159 View Post
int main

return 0;
That wasn't what he asked.

@mehulved - I gave it in non-standard to focus on his problem first here and then show him the standard way (Which only ensures portability). I've noticed that once standards get in the discussions here the posts shift towards bad-mouthing the non-standard coders and not helping him analyze/solve issues with his code. How much have you got AGAINST portability? Give one some hospitality before showing him the door.

@OP - That program doesn't show any character here at all. Also, asking the user to input an EOF is a bad idea. Try with the line feed input, '\n' | Return Key.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 23-03-2008, 12:22 PM   #9 (permalink)
Alpha Geek
 
ajaybc's Avatar
 
Join Date: Feb 2007
Location: Cochin
Posts: 744
Default Re: Please do these simple C programs for me...

Instead of fighting please help me

I just did the program for finding the sine series upto n terms:

#include<stdio.h>
#include<math.h>
main()
{
int i,j,k,x,n,sign=-1,f=1,p=1,m;
clrscr();
printf("Enter the angle: ");
scanf("%d",&x);
printf("Enter number of terms: ");
scanf("%d",&n);
x=x*(3.14/180);
m=x;
for(i=1,j=3;i<=n;i++,j=j+2)
{
f=1;
for(k=1;k<=j;k++)
{
f=f*k;
}
p=pow(x,j);
m=m+((p/f)*sign);
sign=sign*(-1);
}
printf("%d",m);
getch();
}


I get the correct answer(which is 1) for the angle 90degree only.for all others I get 0.So I changed the int values to float.Then the answer for all angles changes to 0 which is wrong.


Please help me.
Iam in desperate need for help.I have to submit these tomorrow.
__________________
Available for freelance web design and web development jobs.
You can view my portfolio here.
Ajay Balachandran

Please contact via PM

Last edited by ajaybc; 23-03-2008 at 12:22 PM. Reason: Automerged Doublepost
ajaybc is offline  
Old 23-03-2008, 07:08 PM   #10 (permalink)
Alpha Geek
 
ajaybc's Avatar
 
Join Date: Feb 2007
Location: Cochin
Posts: 744
Default Re: Please do these simple C programs for me...

Please guys please.Iam begging u.
I want the programs debugged before 7AM tomorrow before i go to college.
Please debug these........
__________________
Available for freelance web design and web development jobs.
You can view my portfolio here.
Ajay Balachandran

Please contact via PM
ajaybc is offline  
Old 23-03-2008, 09:00 PM   #11 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Please do these simple C programs for me...

Quote:
Originally Posted by ajaybc View Post
#include<stdio.h>
main(int argc,char *argv[])
{

FILE *fone,*ftwo;
char a;
clrscr();
fone=fopen(argv[1],"w");
printf("Enter the contents of %s:\n",argv[1]);

while((a=getchar())!=EOF)
{
fputc(a,fone);
}

fclose(fone);


fone=fopen(argv[1],"r");
ftwo=fopen(argv[2],"w");
while((a=fgetc(fone))!=EOF)
{
if(isupper(a))
fputc(tolower(a),ftwo);

else if(islower(a))
fputc(toupper(a),ftwo);

}

fclose(fone);
fclose(ftwo);
ftwo=fopen(argv[2],"r");
while((a=fgetc(ftwo)!=EOF))
{
printf("%c",a);
}
fclose(ftwo);
getch();
}




everything in this program works fine.it creates two files and copies the contents and converts uppercase and lower case.
The problem comes only when it is displaying the contents of the second file.It shows some rubbish.Please debug this
Both the files come fine for me. Only problem is, if I input a flaot or an int I don't see it reflected into the second file. Time to create version 2.

Quote:
Originally Posted by ajaybc View Post
Instead of fighting please help me

I just did the program for finding the sine series upto n terms:

#include<stdio.h>
#include<math.h>
main()
{
int i,j,k,x,n,sign=-1,f=1,p=1,m;
clrscr();
printf("Enter the angle: ");
scanf("%d",&x);
printf("Enter number of terms: ");
scanf("%d",&n);
x=x*(3.14/180);
m=x;
for(i=1,j=3;i<=n;i++,j=j+2)
{
f=1;
for(k=1;k<=j;k++)
{
f=f*k;
}
p=pow(x,j);
m=m+((p/f)*sign);
sign=sign*(-1);
}
printf("%d",m);
getch();
}


I get the correct answer(which is 1) for the angle 90degree only.for all others I get 0.So I changed the int values to float.Then the answer for all angles changes to 0 which is wrong.


Please help me.
Iam in desperate need for help.I have to submit these tomorrow.
Did you change all %d to %f?

And please try to use better variable names. It will makes things easier for all of us.
__________________
http://www.bash.org/?258908

Last edited by mehulved; 23-03-2008 at 09:00 PM. Reason: Automerged Doublepost
mehulved is offline  
Old 23-03-2008, 09:18 PM   #12 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default Re: Please do these simple C programs for me...

Ensure i,j,k, n and sign are integers and the rest are floats... When you do calculation across types, ensure that you do conversion (f=f*(float )k)... Since I am not having a compiler at hand, I am unable to check the code in detail...

Arun
sakumar79 is offline  
Old 24-03-2008, 06:47 AM   #13 (permalink)
Alpha Geek
 
ajaybc's Avatar
 
Join Date: Feb 2007
Location: Cochin
Posts: 744
Default Re: Please do these simple C programs for me...

Quote:
Originally Posted by mehulved View Post
Both the files come fine for me. Only problem is, if I input a flaot or an int I don't see it reflected into the second file. Time to create version 2.


Did you change all %d to %f?

And please try to use better variable names. It will makes things easier for all of us.
Thanx bhai that sine program worked.but that file program shows some rubbish when i try to read using this program.
__________________
Available for freelance web design and web development jobs.
You can view my portfolio here.
Ajay Balachandran

Please contact via PM
ajaybc is offline  
Old 24-03-2008, 07:10 AM   #14 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default Re: Please do these simple C programs for me...

Change

Code:
if(isupper(a))
fputc(tolower(a),ftwo);

else if(islower(a))
fputc(toupper(a),ftwo);
to

Code:
if(isupper(a))
fputc(tolower(a),ftwo);

else if(islower(a))
fputc(toupper(a),ftwo);

else fputc(a,ftwo);
so that any non-alphabet characters are printed as they are...

Arun
sakumar79 is offline  
Old 24-03-2008, 08:46 AM   #15 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Please do these simple C programs for me...

Quote:
#include<stdio.h>
main(int argc,char *argv[])
{

FILE *fone,*ftwo;
char a;
fone=fopen(argv[1],"w");
printf("Enter the contents of %s:\n",argv[1]);

while((a=getchar())!=EOF)
{
fputc(a,fone);
}

fclose(fone);


fone=fopen(argv[1],"r");
ftwo=fopen(argv[2],"w");
while((a=fgetc(fone))!=EOF)
{
if(isupper(a))
fputc(tolower(a),ftwo);

else if(islower(a))
fputc(toupper(a),ftwo);

else fputc(a,ftwo);
}

fclose(fone);
fclose(ftwo);
ftwo=fopen(argv[2],"r");
while((a=fgetc(ftwo)!=EOF))
{
printf("%c\n",a);
}
fclose(ftwo);
}
Works perfectly for me after making the change given by arun. I am using gcc under gentoo/freebsd.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 28-03-2008, 12:55 PM   #16 (permalink)
Alpha Geek
 
ajaybc's Avatar
 
Join Date: Feb 2007
Location: Cochin
Posts: 744
Default Re: Please do these simple C programs for me...

Thannx friends.MISSION ACCOMPLISHED!!!RECORD SUBMITTED!!!
__________________
Available for freelance web design and web development jobs.
You can view my portfolio here.
Ajay Balachandran

Please contact via PM
ajaybc 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Uninstall programs, not listed in add/remove programs Aanand QnA (read only) 9 06-06-2008 07:00 PM
simple popup champ_rock QnA (read only) 4 12-03-2007 07:11 PM
good c fundu book and simple programs adithya_spec QnA (read only) 3 20-11-2005 05:31 PM
Make a folder in "start>programs" menu & move programs to it Aanand QnA (read only) 5 26-10-2005 12:25 AM
Simple C...?? Mikwiththestick QnA (read only) 3 29-04-2005 04:41 PM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:55 AM.


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

Search Engine Optimization by vBSEO 3.3.2