Please help with writing this assignment in C, please include documenation. Usin
ID: 3533249 • Letter: P
Question
Please help with writing this assignment in C, please include documenation.
Using this program:
#include<stdio.h>
int sum (int, int);
{
int myint1;
int myint2;
int result;
printf ("Enter an integer:");
scanf ("%d",&myint1);
printf ("Enter a second integer: ");
scanf ("%d", &myint2);
result = sum (myint1, myint2);
printf ("The sum is %d. ", result);
return;
}
int sum (int val1, int val2)
{
int thissum;
thisum = val1 + val2;
return thissum;
}
1. Create a variable named index and initialize it to zero (0).
2. Prompt for and input a string value from the keyboard. Store the string variable newstring[80].
3. While (newstring[index] does not equal '')
i. Display the character at newstring[index] followed by a NL.
ii. Increment index
Write your program to use scanf to input the string. Input the following string: This is a test
then change your program to use gets instead of scanf to input the string. This should get the entire string.
Explanation / Answer
#include<stdio.h>
int sum (int, int);
{
int myint1;
int myint2;
int result;
int index=0; // ( i)
char newstring[80];
printf ("Enter an integer:");
scanf ("%d",&myint1);
printf ("Enter a second integer: ");
scanf ("%d", &myint2);
printf ("Enter string : ");
scanf("%s",newstring); //using scanf to get the input string
while(newstring[index]!='')
{
printf("%c ",newstring[index]);
index++;
}
result = sum (myint1, myint2);
printf ("The sum is %d. ", result);
return;
}
int sum (int val1, int val2)
{
int thissum;
thisum = val1 + val2;
return thissum;
}
#include<stdio.h>
int sum (int, int);
{
int myint1;
int myint2;
int result;
int index=0; // ( i)
char newstring[80];
printf ("Enter an integer:");
scanf ("%d",&myint1);
printf ("Enter a second integer: ");
scanf ("%d", &myint2);
printf ("Enter another string : ");
gets(newstring); //using gets to get the input string
while(newstring[index]!='')
{
printf("%c ",newstring[index]);
index++;
}
result = sum (myint1, myint2);
printf ("The sum is %d. ", result);
return;
}
int sum (int val1, int val2)
{
int thissum;
thisum = val1 + val2;
return thissum;
}